mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
Added normal inversion in lighting shaders.
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user