From 30f844c961c2c1d21f630d17c2e1db30f8b676da Mon Sep 17 00:00:00 2001 From: timoore Date: Sun, 19 Jul 2009 18:54:10 +0000 Subject: [PATCH] fixes to terrain shader Handle emission and light model ambient value. Test if shininess is 0 to avoid pow(0, 0), which is undefined. --- Shaders/default.frag | 7 ++++--- Shaders/default.vert | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Shaders/default.frag b/Shaders/default.frag index a50f8f497..c3c15e598 100644 --- a/Shaders/default.frag +++ b/Shaders/default.frag @@ -10,7 +10,7 @@ void main() { vec3 n, halfV; float NdotL, NdotHV, fogFactor; - vec4 color = ambient; + vec4 color = ambient + gl_FrontMaterial.emission; vec4 texel; vec4 fragColor; @@ -20,8 +20,9 @@ void main() color += diffuse * NdotL; halfV = normalize(halfVector); NdotHV = max(dot(n, halfV), 0.0); - color += gl_FrontMaterial.specular * gl_LightSource[0].specular - * pow(NdotHV, gl_FrontMaterial.shininess); + if (gl_FrontMaterial.shininess > 0.0) + color += gl_FrontMaterial.specular * gl_LightSource[0].specular + * pow(NdotHV, gl_FrontMaterial.shininess); } texel = texture2D(texture, gl_TexCoord[0].st); fragColor = color * texel; diff --git a/Shaders/default.vert b/Shaders/default.vert index 3e73c3bb7..49eb2aea7 100644 --- a/Shaders/default.vert +++ b/Shaders/default.vert @@ -22,5 +22,6 @@ void main() halfVector = normalize(gl_LightSource[0].halfVector.xyz); diffuse = gl_Color * gl_LightSource[0].diffuse; ambient = gl_Color * gl_LightSource[0].ambient; + ambient += gl_Color * gl_LightModel.ambient; fogCoord = abs(ecPosition.z); }