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,11 +65,15 @@ void main()
intensity.y = 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).
NdotL = max(dot(normal, LIGHT_FRONT_DIR), 0.0);
intensity.x += NdotL * LIGHT_FRONT_DIFFUSE;
if (NdotL > 0.0)
intensity.x += NdotL * LIGHT_FRONT_DIFFUSE;
// compute deltas for out of print volume detection (world coordinates)
if (print_box.actived)

View file

@ -35,12 +35,16 @@ void main()
intensity.y = 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)
NdotL = max(dot(normal, LIGHT_FRONT_DIR), 0.0);
intensity.x += NdotL * LIGHT_FRONT_DIFFUSE;
if (NdotL > 0.0)
intensity.x += NdotL * LIGHT_FRONT_DIFFUSE;
// Scaled to widths of the Z texture.
if (object_max_z > 0.0)