diff options
author | enricoturri1966 <enricoturri@seznam.cz> | 2020-04-08 09:07:36 +0300 |
---|---|---|
committer | enricoturri1966 <enricoturri@seznam.cz> | 2020-04-08 09:07:36 +0300 |
commit | 0e2fba6d6f07f515620483405021f8c83fba0080 (patch) | |
tree | 1d5442588b57f8e8000a1420043864e78d874e15 /resources | |
parent | ce2e53dbfa5469992e7a5b8bacec0d322c506c2f (diff) |
Fixed bug in calculating the specular component of the color in shaders
Diffstat (limited to 'resources')
-rw-r--r-- | resources/shaders/gouraud.vs | 8 | ||||
-rw-r--r-- | resources/shaders/variable_layer_height.vs | 8 |
2 files changed, 12 insertions, 4 deletions
diff --git a/resources/shaders/gouraud.vs b/resources/shaders/gouraud.vs index a9f3f6118..17cc764e2 100644 --- a/resources/shaders/gouraud.vs +++ b/resources/shaders/gouraud.vs @@ -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) diff --git a/resources/shaders/variable_layer_height.vs b/resources/shaders/variable_layer_height.vs index 4f98dfa56..5dd697063 100644 --- a/resources/shaders/variable_layer_height.vs +++ b/resources/shaders/variable_layer_height.vs @@ -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) |