1
0
Fork 0
fgdata/Shaders/model-default.frag
timoore 56fc0f9076 clamp lighting values and support transparency material animation
The transparency animation support is a hack, but should get the job done
for a bit.


Author: Tim Moore <timoore@redhat.com>
2009-11-17 21:57:07 +00:00

37 lines
1.2 KiB
C++

// -*-C++-*-
varying vec4 diffuse, constantColor;
varying vec3 normal, lightDir, halfVector;
varying float alpha, fogCoord;
uniform sampler2D texture;
void main()
{
vec3 n, halfV;
float NdotL, NdotHV, fogFactor;
vec4 color = constantColor;
vec4 texel;
vec4 fragColor;
vec4 specular = vec4(0.0);
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);
if (gl_FrontMaterial.shininess > 0.0)
specular.rgb = (gl_FrontMaterial.specular.rgb
* gl_LightSource[0].specular.rgb
* pow(NdotHV, gl_FrontMaterial.shininess));
}
color.a = alpha;
// 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);
texel = texture2D(texture, gl_TexCoord[0].st);
fragColor = color * texel + specular;
fogFactor = exp(-gl_Fog.density * gl_Fog.density * fogCoord * fogCoord);
gl_FragColor = mix(gl_Fog.color, fragColor, fogFactor);
}