From bd09d8f08123d47f205118a0ba5286b9efdaf0ea Mon Sep 17 00:00:00 2001 From: codeanticode Date: Mon, 20 Aug 2012 20:16:17 +0000 Subject: [PATCH] Constant number of loop iterations in light shaders, to make them compatible with older Adreno GPUs (fixes issue 1145). Also, more careful handling of vectors in shaders to avoid problems with powerVR GPUs. --- .../src/processing/opengl/PolyFullShaderVert.glsl | 13 ++++++++----- .../src/processing/opengl/PolyLightShaderVert.glsl | 13 ++++++++----- core/andres.txt | 10 +++++++++- core/src/processing/opengl/PolyFullShaderVert.glsl | 13 ++++++++----- core/src/processing/opengl/PolyLightShaderVert.glsl | 13 ++++++++----- 5 files changed, 41 insertions(+), 21 deletions(-) diff --git a/android/core/src/processing/opengl/PolyFullShaderVert.glsl b/android/core/src/processing/opengl/PolyFullShaderVert.glsl index 01b3457cb..7ce8cf92f 100644 --- a/android/core/src/processing/opengl/PolyFullShaderVert.glsl +++ b/android/core/src/processing/opengl/PolyFullShaderVert.glsl @@ -59,8 +59,9 @@ float falloffFactor(vec3 lightPos, vec3 vertPos, vec3 coeff) { float spotFactor(vec3 lightPos, vec3 vertPos, vec3 lightNorm, float minCos, float spotExp) { vec3 lpv = normalize(lightPos - vertPos); - float spotCos = dot(-lightNorm, lpv); - return spotCos <= minCos ? zero_float : pow(spotCos, spotExp); + vec3 nln = -one_float * lightNorm; + float spotCos = dot(nln, lpv); + return spotCos <= minCos ? zero_float : pow(spotCos, spotExp); } float lambertFactor(vec3 lightDir, vec3 vecNormal) { @@ -83,7 +84,7 @@ void main() { // Normal vector in eye coordinates vec3 ecNormal = normalize(normalMatrix * inNormal); - if (dot(-ecVertex, ecNormal) < zero_float) { + if (dot(-one_float * ecVertex, ecNormal) < zero_float) { // If normal is away from camera, choose its opposite. // If we add backface culling, this will be backfacing ecNormal *= -one_float; @@ -93,7 +94,9 @@ void main() { vec3 totalAmbient = vec3(0, 0, 0); vec3 totalDiffuse = vec3(0, 0, 0); vec3 totalSpecular = vec3(0, 0, 0); - for (int i = 0; i < lightCount; i++) { + for (int i = 0; i < 8; i++) { + if (lightCount == i) break; + vec3 lightPos = lightPosition[i].xyz; bool isDir = zero_float < lightPosition[i].w; float spotCos = lightSpotParameters[i].x; @@ -105,7 +108,7 @@ void main() { if (isDir) { falloff = one_float; - lightDir = -lightNormal[i]; + lightDir = -one_float * lightNormal[i]; } else { falloff = falloffFactor(lightPos, ecVertex, lightFalloffCoefficients[i]); lightDir = normalize(lightPos - ecVertex); diff --git a/android/core/src/processing/opengl/PolyLightShaderVert.glsl b/android/core/src/processing/opengl/PolyLightShaderVert.glsl index 88f5777ff..b271b020a 100644 --- a/android/core/src/processing/opengl/PolyLightShaderVert.glsl +++ b/android/core/src/processing/opengl/PolyLightShaderVert.glsl @@ -56,8 +56,9 @@ float falloffFactor(vec3 lightPos, vec3 vertPos, vec3 coeff) { float spotFactor(vec3 lightPos, vec3 vertPos, vec3 lightNorm, float minCos, float spotExp) { vec3 lpv = normalize(lightPos - vertPos); - float spotCos = dot(-lightNorm, lpv); - return spotCos <= minCos ? zero_float : pow(spotCos, spotExp); + vec3 nln = -one_float * lightNorm; + float spotCos = dot(nln, lpv); + return spotCos <= minCos ? zero_float : pow(spotCos, spotExp); } float lambertFactor(vec3 lightDir, vec3 vecNormal) { @@ -80,7 +81,7 @@ void main() { // Normal vector in eye coordinates vec3 ecNormal = normalize(normalMatrix * inNormal); - if (dot(-ecVertex, ecNormal) < zero_float) { + if (dot(-one_float * ecVertex, ecNormal) < zero_float) { // If normal is away from camera, choose its opposite. // If we add backface culling, this will be backfacing ecNormal *= -one_float; @@ -90,7 +91,9 @@ void main() { vec3 totalAmbient = vec3(0, 0, 0); vec3 totalDiffuse = vec3(0, 0, 0); vec3 totalSpecular = vec3(0, 0, 0); - for (int i = 0; i < lightCount; i++) { + for (int i = 0; i < 8; i++) { + if (lightCount == i) break; + vec3 lightPos = lightPosition[i].xyz; bool isDir = zero_float < lightPosition[i].w; float spotCos = lightSpotParameters[i].x; @@ -102,7 +105,7 @@ void main() { if (isDir) { falloff = one_float; - lightDir = -lightNormal[i]; + lightDir = -one_float * lightNormal[i]; } else { falloff = falloffFactor(lightPos, ecVertex, lightFalloffCoefficients[i]); lightDir = normalize(lightPos - ecVertex); diff --git a/core/andres.txt b/core/andres.txt index 74270cce0..c6f58edbe 100644 --- a/core/andres.txt +++ b/core/andres.txt @@ -9,12 +9,15 @@ X Cleanup video API: http://code.google.com/p/processing/issues/detail?id=1170 X Have Capture.list() return all supported resolutions, and use the string as the argument for the capture object + +0208 android +X Issues on low-end phones: http://code.google.com/p/processing/issues/detail?id=1145 + 0208 todo pre-beta: _ Add DISABLE_PERSPECTIVE_CORRECTED_STROKE hint, remove DISABLE_PERSPECTIVE_CORRECTED_LINES _ Rename shader constants (FLAT, LIT, TEXTURED, etc), resetShader() w/out args? _ Back-buffer support in shaders: http://code.google.com/p/processing/issues/detail?id=1169 -_ Issues on low-end phones: http://code.google.com/p/processing/issues/detail?id=1145 _ Rotation problem on Android: http://code.google.com/p/processing/issues/detail?id=1146 processing-core todo (post-beta): @@ -33,7 +36,12 @@ _ Lines, points and fill geometry should be handled separately in raw output in _ Use GL_LINES and GL_POINTS when stroke weight is below the hardware limit and stroke cap/bevel is RECT. _ Properly handle very large stroke paths in P3D (create new index cache, etc). +processing-video todo (post-beta) +_ New gstreamer binaries from GStreamer SDK + processing-android todo (post-beta): _ noLoop/redraw not working _ Mipmaps are disabled, need manual generation +_ make OpenGL examples work on emulator +_ support for compressed textures: http://developer.android.com/guide/topics/graphics/opengl.html#textures \ No newline at end of file diff --git a/core/src/processing/opengl/PolyFullShaderVert.glsl b/core/src/processing/opengl/PolyFullShaderVert.glsl index 01b3457cb..7ce8cf92f 100644 --- a/core/src/processing/opengl/PolyFullShaderVert.glsl +++ b/core/src/processing/opengl/PolyFullShaderVert.glsl @@ -59,8 +59,9 @@ float falloffFactor(vec3 lightPos, vec3 vertPos, vec3 coeff) { float spotFactor(vec3 lightPos, vec3 vertPos, vec3 lightNorm, float minCos, float spotExp) { vec3 lpv = normalize(lightPos - vertPos); - float spotCos = dot(-lightNorm, lpv); - return spotCos <= minCos ? zero_float : pow(spotCos, spotExp); + vec3 nln = -one_float * lightNorm; + float spotCos = dot(nln, lpv); + return spotCos <= minCos ? zero_float : pow(spotCos, spotExp); } float lambertFactor(vec3 lightDir, vec3 vecNormal) { @@ -83,7 +84,7 @@ void main() { // Normal vector in eye coordinates vec3 ecNormal = normalize(normalMatrix * inNormal); - if (dot(-ecVertex, ecNormal) < zero_float) { + if (dot(-one_float * ecVertex, ecNormal) < zero_float) { // If normal is away from camera, choose its opposite. // If we add backface culling, this will be backfacing ecNormal *= -one_float; @@ -93,7 +94,9 @@ void main() { vec3 totalAmbient = vec3(0, 0, 0); vec3 totalDiffuse = vec3(0, 0, 0); vec3 totalSpecular = vec3(0, 0, 0); - for (int i = 0; i < lightCount; i++) { + for (int i = 0; i < 8; i++) { + if (lightCount == i) break; + vec3 lightPos = lightPosition[i].xyz; bool isDir = zero_float < lightPosition[i].w; float spotCos = lightSpotParameters[i].x; @@ -105,7 +108,7 @@ void main() { if (isDir) { falloff = one_float; - lightDir = -lightNormal[i]; + lightDir = -one_float * lightNormal[i]; } else { falloff = falloffFactor(lightPos, ecVertex, lightFalloffCoefficients[i]); lightDir = normalize(lightPos - ecVertex); diff --git a/core/src/processing/opengl/PolyLightShaderVert.glsl b/core/src/processing/opengl/PolyLightShaderVert.glsl index 88f5777ff..b271b020a 100644 --- a/core/src/processing/opengl/PolyLightShaderVert.glsl +++ b/core/src/processing/opengl/PolyLightShaderVert.glsl @@ -56,8 +56,9 @@ float falloffFactor(vec3 lightPos, vec3 vertPos, vec3 coeff) { float spotFactor(vec3 lightPos, vec3 vertPos, vec3 lightNorm, float minCos, float spotExp) { vec3 lpv = normalize(lightPos - vertPos); - float spotCos = dot(-lightNorm, lpv); - return spotCos <= minCos ? zero_float : pow(spotCos, spotExp); + vec3 nln = -one_float * lightNorm; + float spotCos = dot(nln, lpv); + return spotCos <= minCos ? zero_float : pow(spotCos, spotExp); } float lambertFactor(vec3 lightDir, vec3 vecNormal) { @@ -80,7 +81,7 @@ void main() { // Normal vector in eye coordinates vec3 ecNormal = normalize(normalMatrix * inNormal); - if (dot(-ecVertex, ecNormal) < zero_float) { + if (dot(-one_float * ecVertex, ecNormal) < zero_float) { // If normal is away from camera, choose its opposite. // If we add backface culling, this will be backfacing ecNormal *= -one_float; @@ -90,7 +91,9 @@ void main() { vec3 totalAmbient = vec3(0, 0, 0); vec3 totalDiffuse = vec3(0, 0, 0); vec3 totalSpecular = vec3(0, 0, 0); - for (int i = 0; i < lightCount; i++) { + for (int i = 0; i < 8; i++) { + if (lightCount == i) break; + vec3 lightPos = lightPosition[i].xyz; bool isDir = zero_float < lightPosition[i].w; float spotCos = lightSpotParameters[i].x; @@ -102,7 +105,7 @@ void main() { if (isDir) { falloff = one_float; - lightDir = -lightNormal[i]; + lightDir = -one_float * lightNormal[i]; } else { falloff = falloffFactor(lightPos, ecVertex, lightFalloffCoefficients[i]); lightDir = normalize(lightPos - ecVertex);