1
0
Fork 0
fgdata/Shaders/model-default.frag
timoore 8e2077e330 Created different default shaders for models.
These use the vertex color as the diffuse part of the lighting equation,
instead of both ambient and diffuse.


Author: Tim Moore <timoore@redhat.com>
2009-11-14 06:19:09 +00:00

31 lines
898 B
C++

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