2009-07-15 22:49:36 +00:00
|
|
|
// -*-C++-*-
|
|
|
|
|
|
|
|
varying vec4 diffuse, ambient;
|
|
|
|
varying vec3 normal, lightDir, halfVector;
|
2009-11-17 06:23:21 +00:00
|
|
|
varying float fogCoord, alpha;
|
2009-07-15 22:49:36 +00:00
|
|
|
|
|
|
|
uniform sampler2D texture;
|
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
|
|
|
vec3 n, halfV;
|
|
|
|
float NdotL, NdotHV, fogFactor;
|
2009-07-19 18:54:10 +00:00
|
|
|
vec4 color = ambient + gl_FrontMaterial.emission;
|
2009-07-15 22:49:36 +00:00
|
|
|
vec4 texel;
|
|
|
|
vec4 fragColor;
|
2009-11-17 21:57:07 +00:00
|
|
|
vec4 specular = vec4(0.0);
|
|
|
|
|
2009-07-15 22:49:36 +00:00
|
|
|
n = normalize(normal);
|
|
|
|
NdotL = max(dot(n, lightDir), 0.0);
|
|
|
|
if (NdotL > 0.0) {
|
|
|
|
color += diffuse * NdotL;
|
|
|
|
halfV = normalize(halfVector);
|
|
|
|
NdotHV = max(dot(n, halfV), 0.0);
|
2009-07-19 18:54:10 +00:00
|
|
|
if (gl_FrontMaterial.shininess > 0.0)
|
2009-11-17 21:57:07 +00:00
|
|
|
specular.rgb = (gl_FrontMaterial.specular.rgb
|
|
|
|
* gl_LightSource[0].specular.rgb
|
|
|
|
* pow(NdotHV, gl_FrontMaterial.shininess));
|
2009-07-15 22:49:36 +00:00
|
|
|
}
|
2009-11-17 06:23:21 +00:00
|
|
|
color.a = alpha;
|
2009-11-17 21:57:07 +00:00
|
|
|
// This shouldn't be necessary, but our lighting becomes very
|
|
|
|
// saturated. Clamping the color before modulating by the texture
|
|
|
|
// is closer to what the OpenGL fixed function pipeline does.
|
|
|
|
color = clamp(color, 0.0, 1.0);
|
2009-07-15 22:49:36 +00:00
|
|
|
texel = texture2D(texture, gl_TexCoord[0].st);
|
2009-11-17 21:57:07 +00:00
|
|
|
fragColor = color * texel + specular;
|
2009-07-15 22:49:36 +00:00
|
|
|
fogFactor = exp(-gl_Fog.density * gl_Fog.density * fogCoord * fogCoord);
|
|
|
|
gl_FragColor = mix(gl_Fog.color, fragColor, fogFactor);
|
|
|
|
}
|