SVN commit 1009233 by rivol: Fix specular lighting calculation. M +7 -3 material-object.frag M +7 -3 material-ship.frag --- trunk/playground/games/astrododge/data/shaders/material-object.frag #1009232:1009233 @@ -14,10 +14,14 @@ float specularity = 30.0; float NdotL = max(dot(N, L), 0.0); - vec3 R = 2.0 * NdotL * N - L; - vec3 V = normalize(-vertexEye.xyz); - float spec = pow(max(dot(R, V), 0.0), specularity); + float spec = 0.0; + if (NdotL > 0.0) { + vec3 R = 2.0 * NdotL * N - L; + vec3 V = normalize(-vertexEye.xyz); + spec = pow(max(dot(R, V), 0.0), specularity); + } + return (texColor * NdotL + specular*spec) * Lcolor; } --- trunk/playground/games/astrododge/data/shaders/material-ship.frag #1009232:1009233 @@ -10,10 +10,14 @@ float specularity = 30.0; float NdotL = max(dot(N, L), 0.0); - vec3 R = 2.0 * NdotL * N - L; - vec3 V = normalize(-vertexEye.xyz); - float spec = pow(max(dot(R, V), 0.0), specularity); + float spec = 0.0; + if (NdotL > 0.0) { + vec3 R = 2.0 * NdotL * N - L; + vec3 V = normalize(-vertexEye.xyz); + spec = pow(max(dot(R, V), 0.0), specularity); + } + return shipBaseColor * Lcolor * (NdotL * diffuse + spec * specular); }