Added normal inversion in lighting shaders.

This commit is contained in:
codeanticode
2012-04-10 22:24:30 +00:00
parent af80f01f9d
commit 22c71c712f
4 changed files with 32 additions and 16 deletions
@@ -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);
@@ -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);