From d328369d24d71d48282e6d7aaf4e4c615be279c5 Mon Sep 17 00:00:00 2001 From: Rod Kay Date: Sun, 25 Feb 2024 18:35:44 +1100 Subject: [PATCH] opengl.shaders.lighting: Work around problem with specular highlighting. --- 3-mid/opengl/assets/shader/lighting-frag.snippet | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/3-mid/opengl/assets/shader/lighting-frag.snippet b/3-mid/opengl/assets/shader/lighting-frag.snippet index a04744e..59fde5d 100644 --- a/3-mid/opengl/assets/shader/lighting-frag.snippet +++ b/3-mid/opengl/assets/shader/lighting-frag.snippet @@ -36,7 +36,7 @@ apply_Light (light Light, // Directional light. // Surface_to_Light = normalize (-Light.Site.xyz); - Attenuation = 1.0; // No attenuation for directional lights. + Attenuation = 1.0; // No attenuation for directional lights. } else { @@ -62,19 +62,20 @@ apply_Light (light Light, } } - vec3 lit_surface_Color = surface_Color * Light.Color; + vec3 lit_surface_Color = surface_Color * Light.Color; vec3 Ambient = Light.ambient_Coefficient * lit_surface_Color; float diffuse_Coefficient = max (0.0, dot (Normal, - Surface_to_Light)); + Surface_to_Light)); + vec3 Diffuse = diffuse_Coefficient * lit_surface_Color; float specular_Coefficient = 0.0; if (diffuse_Coefficient > 0.0) { - specular_Coefficient = pow (max (0.0, - dot (Surface_to_Camera, + specular_Coefficient = pow (max (0.01, // Using '0.0' produces wierd results when + dot (Surface_to_Camera, // light shines directly on a flat surface. reflect (-Surface_to_Light, Normal))), frag_Shine); @@ -82,7 +83,7 @@ apply_Light (light Light, vec3 Specular = specular_Coefficient * specular_Color * Light.Color; - return Ambient + Attenuation * (Diffuse + Specular); // Linear color (before gamma correction). + return Ambient + Attenuation * (Diffuse + Specular); // Linear color (before gamma correction). }