diff --git a/android/core/src/processing/opengl/FillShaderVertFull.glsl b/android/core/src/processing/opengl/FillShaderVertFull.glsl index 5734b25bd..c9a79eb50 100644 --- a/android/core/src/processing/opengl/FillShaderVertFull.glsl +++ b/android/core/src/processing/opengl/FillShaderVertFull.glsl @@ -65,14 +65,12 @@ float spotFactor(vec3 lightPos, vec3 vertPos, vec3 lightNorm, float minCos, floa } float lambertFactor(vec3 lightDir, vec3 vecNormal) { - //return max(zero_float, dot(lightDir, vecNormal)); - return abs(dot(lightDir, vecNormal)); + return max(zero_float, dot(lightDir, vecNormal)); } float blinnPhongFactor(vec3 lightDir, vec3 lightPos, vec3 vecNormal, float shine) { vec3 ldp = normalize(lightDir - lightPos); - //return pow(max(zero_float, dot(ldp, vecNormal)), shine); - return pow(abs(dot(ldp, vecNormal)), shine); + return pow(max(zero_float, dot(ldp, vecNormal)), shine); } void main() { @@ -85,6 +83,12 @@ void main() { // Normal vector in eye coordinates vec3 ecNormal = normalize(normalMatrix * inNormal); + if (dot(-ecVertex, ecNormal) < 0) { + // If normal is away from camera, choose its opposite. + // If we add backface culling, this will be backfacing + ecNormal *= -1; + } + // Light calculations vec3 totalAmbient = vec3(0, 0, 0); vec3 totalDiffuse = vec3(0, 0, 0); diff --git a/android/core/src/processing/opengl/FillShaderVertLit.glsl b/android/core/src/processing/opengl/FillShaderVertLit.glsl index 02ee447a4..33d2360e7 100644 --- a/android/core/src/processing/opengl/FillShaderVertLit.glsl +++ b/android/core/src/processing/opengl/FillShaderVertLit.glsl @@ -62,14 +62,12 @@ float spotFactor(vec3 lightPos, vec3 vertPos, vec3 lightNorm, float minCos, floa } float lambertFactor(vec3 lightDir, vec3 vecNormal) { - //return max(zero_float, dot(lightDir, vecNormal)); - return abs(dot(lightDir, vecNormal)); + return max(zero_float, dot(lightDir, vecNormal)); } float blinnPhongFactor(vec3 lightDir, vec3 lightPos, vec3 vecNormal, float shine) { vec3 ldp = normalize(lightDir - lightPos); - //return pow(max(zero_float, dot(ldp, vecNormal)), shine); - return pow(abs(dot(ldp, vecNormal)), shine); + return pow(max(zero_float, dot(ldp, vecNormal)), shine); } void main() { @@ -82,6 +80,12 @@ void main() { // Normal vector in eye coordinates vec3 ecNormal = normalize(normalMatrix * inNormal); + if (dot(-ecVertex, ecNormal) < 0) { + // If normal is away from camera, choose its opposite. + // If we add backface culling, this will be backfacing + ecNormal *= -1; + } + // Light calculations vec3 totalAmbient = vec3(0, 0, 0); vec3 totalDiffuse = vec3(0, 0, 0); diff --git a/java/libraries/opengl/src/processing/opengl/FillShaderVertFull.glsl b/java/libraries/opengl/src/processing/opengl/FillShaderVertFull.glsl index 5734b25bd..c9a79eb50 100644 --- a/java/libraries/opengl/src/processing/opengl/FillShaderVertFull.glsl +++ b/java/libraries/opengl/src/processing/opengl/FillShaderVertFull.glsl @@ -65,14 +65,12 @@ float spotFactor(vec3 lightPos, vec3 vertPos, vec3 lightNorm, float minCos, floa } float lambertFactor(vec3 lightDir, vec3 vecNormal) { - //return max(zero_float, dot(lightDir, vecNormal)); - return abs(dot(lightDir, vecNormal)); + return max(zero_float, dot(lightDir, vecNormal)); } float blinnPhongFactor(vec3 lightDir, vec3 lightPos, vec3 vecNormal, float shine) { vec3 ldp = normalize(lightDir - lightPos); - //return pow(max(zero_float, dot(ldp, vecNormal)), shine); - return pow(abs(dot(ldp, vecNormal)), shine); + return pow(max(zero_float, dot(ldp, vecNormal)), shine); } void main() { @@ -85,6 +83,12 @@ void main() { // Normal vector in eye coordinates vec3 ecNormal = normalize(normalMatrix * inNormal); + if (dot(-ecVertex, ecNormal) < 0) { + // If normal is away from camera, choose its opposite. + // If we add backface culling, this will be backfacing + ecNormal *= -1; + } + // Light calculations vec3 totalAmbient = vec3(0, 0, 0); vec3 totalDiffuse = vec3(0, 0, 0); diff --git a/java/libraries/opengl/src/processing/opengl/FillShaderVertLit.glsl b/java/libraries/opengl/src/processing/opengl/FillShaderVertLit.glsl index 02ee447a4..33d2360e7 100644 --- a/java/libraries/opengl/src/processing/opengl/FillShaderVertLit.glsl +++ b/java/libraries/opengl/src/processing/opengl/FillShaderVertLit.glsl @@ -62,14 +62,12 @@ float spotFactor(vec3 lightPos, vec3 vertPos, vec3 lightNorm, float minCos, floa } float lambertFactor(vec3 lightDir, vec3 vecNormal) { - //return max(zero_float, dot(lightDir, vecNormal)); - return abs(dot(lightDir, vecNormal)); + return max(zero_float, dot(lightDir, vecNormal)); } float blinnPhongFactor(vec3 lightDir, vec3 lightPos, vec3 vecNormal, float shine) { vec3 ldp = normalize(lightDir - lightPos); - //return pow(max(zero_float, dot(ldp, vecNormal)), shine); - return pow(abs(dot(ldp, vecNormal)), shine); + return pow(max(zero_float, dot(ldp, vecNormal)), shine); } void main() { @@ -82,6 +80,12 @@ void main() { // Normal vector in eye coordinates vec3 ecNormal = normalize(normalMatrix * inNormal); + if (dot(-ecVertex, ecNormal) < 0) { + // If normal is away from camera, choose its opposite. + // If we add backface culling, this will be backfacing + ecNormal *= -1; + } + // Light calculations vec3 totalAmbient = vec3(0, 0, 0); vec3 totalDiffuse = vec3(0, 0, 0);