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.

This commit is contained in:
codeanticode
2012-08-20 20:16:17 +00:00
parent d3e0785fc8
commit bd09d8f081
5 changed files with 41 additions and 21 deletions
@@ -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);
@@ -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);
+9 -1
View File
@@ -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
@@ -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);
@@ -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);