2009-07-15 22:49:36 +00:00
|
|
|
// -*-C++-*-
|
|
|
|
|
2010-08-13 16:49:25 +00:00
|
|
|
// Ambient term comes in gl_Color.rgb.
|
2011-12-01 21:03:40 +00:00
|
|
|
#version 120
|
|
|
|
|
2010-08-13 16:49:25 +00:00
|
|
|
varying vec4 diffuse_term;
|
|
|
|
varying vec3 normal;
|
2009-07-15 22:49:36 +00:00
|
|
|
|
|
|
|
uniform sampler2D texture;
|
|
|
|
|
2011-12-01 21:03:40 +00:00
|
|
|
////fog "include" /////
|
|
|
|
uniform int fogType;
|
|
|
|
|
|
|
|
vec3 fog_Func(vec3 color, int type);
|
|
|
|
//////////////////////
|
|
|
|
|
2020-11-10 00:45:54 +00:00
|
|
|
float getShadowing();
|
|
|
|
|
2009-11-19 16:20:51 +00:00
|
|
|
float luminance(vec3 color)
|
|
|
|
{
|
|
|
|
return dot(vec3(0.212671, 0.715160, 0.072169), color);
|
|
|
|
}
|
|
|
|
|
2009-07-15 22:49:36 +00:00
|
|
|
void main()
|
|
|
|
{
|
2011-02-17 22:19:03 +00:00
|
|
|
vec3 n;
|
2009-07-15 22:49:36 +00:00
|
|
|
float NdotL, NdotHV, fogFactor;
|
2010-08-13 16:49:25 +00:00
|
|
|
vec4 color = gl_Color;
|
|
|
|
vec3 lightDir = gl_LightSource[0].position.xyz;
|
|
|
|
vec3 halfVector = gl_LightSource[0].halfVector.xyz;
|
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);
|
2011-02-17 22:19:03 +00:00
|
|
|
|
2010-08-13 16:49:25 +00:00
|
|
|
// If gl_Color.a == 0, this is a back-facing polygon and the
|
|
|
|
// normal should be reversed.
|
2011-02-17 22:19:03 +00:00
|
|
|
n = (2.0 * gl_Color.a - 1.0) * normal;
|
|
|
|
n = normalize(n);
|
2010-08-13 16:49:25 +00:00
|
|
|
|
2011-02-17 22:19:03 +00:00
|
|
|
NdotL = dot(n, lightDir);
|
2009-07-15 22:49:36 +00:00
|
|
|
if (NdotL > 0.0) {
|
2020-11-10 00:45:54 +00:00
|
|
|
float shadowmap = getShadowing();
|
|
|
|
color += diffuse_term * NdotL * shadowmap;
|
2011-02-17 22:19:03 +00:00
|
|
|
NdotHV = max(dot(n, halfVector), 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
|
2020-11-10 00:45:54 +00:00
|
|
|
* pow(NdotHV, gl_FrontMaterial.shininess)
|
|
|
|
* shadowmap);
|
2009-07-15 22:49:36 +00:00
|
|
|
}
|
2010-08-13 16:49:25 +00:00
|
|
|
color.a = diffuse_term.a;
|
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;
|
2011-12-01 21:03:40 +00:00
|
|
|
|
|
|
|
fragColor.rgb = fog_Func(fragColor.rgb, fogType);
|
|
|
|
gl_FragColor = fragColor;
|
2020-11-10 00:45:54 +00:00
|
|
|
}
|