Fixed bug in calculating the specular component of the color in shaders

This commit is contained in:
enricoturri1966 2020-04-08 08:07:36 +02:00
parent ce2e53dbfa
commit 0e2fba6d6f
2 changed files with 12 additions and 4 deletions

View file

@ -65,10 +65,14 @@ void main()
intensity.y = 0.0; intensity.y = 0.0;
if (NdotL > 0.0) if (NdotL > 0.0)
intensity.y += LIGHT_TOP_SPECULAR * pow(max(dot(normal, reflect(-LIGHT_TOP_DIR, normal)), 0.0), LIGHT_TOP_SHININESS); {
vec3 position = (gl_ModelViewMatrix * gl_Vertex).xyz;
intensity.y += LIGHT_TOP_SPECULAR * pow(max(dot(-normalize(position), reflect(-LIGHT_TOP_DIR, normal)), 0.0), LIGHT_TOP_SHININESS);
}
// Perform the same lighting calculation for the 2nd light source (no specular applied). // Perform the same lighting calculation for the 2nd light source (no specular applied).
NdotL = max(dot(normal, LIGHT_FRONT_DIR), 0.0); NdotL = max(dot(normal, LIGHT_FRONT_DIR), 0.0);
if (NdotL > 0.0)
intensity.x += NdotL * LIGHT_FRONT_DIFFUSE; intensity.x += NdotL * LIGHT_FRONT_DIFFUSE;
// compute deltas for out of print volume detection (world coordinates) // compute deltas for out of print volume detection (world coordinates)

View file

@ -35,11 +35,15 @@ void main()
intensity.y = 0.0; intensity.y = 0.0;
if (NdotL > 0.0) if (NdotL > 0.0)
intensity.y += LIGHT_TOP_SPECULAR * pow(max(dot(normal, reflect(-LIGHT_TOP_DIR, normal)), 0.0), LIGHT_TOP_SHININESS); {
vec3 position = (gl_ModelViewMatrix * gl_Vertex).xyz;
intensity.y += LIGHT_TOP_SPECULAR * pow(max(dot(-normalize(position), reflect(-LIGHT_TOP_DIR, normal)), 0.0), LIGHT_TOP_SHININESS);
}
// Perform the same lighting calculation for the 2nd light source (no specular) // Perform the same lighting calculation for the 2nd light source (no specular)
NdotL = max(dot(normal, LIGHT_FRONT_DIR), 0.0); NdotL = max(dot(normal, LIGHT_FRONT_DIR), 0.0);
if (NdotL > 0.0)
intensity.x += NdotL * LIGHT_FRONT_DIFFUSE; intensity.x += NdotL * LIGHT_FRONT_DIFFUSE;
// Scaled to widths of the Z texture. // Scaled to widths of the Z texture.