2009-11-14 06:19:09 +00:00
|
|
|
// -*-C++-*-
|
|
|
|
|
|
|
|
// Shader that uses OpenGL state values to do per-pixel lighting
|
|
|
|
//
|
|
|
|
// The only light used is gl_LightSource[0], which is assumed to be
|
|
|
|
// directional.
|
|
|
|
//
|
2009-11-17 21:57:07 +00:00
|
|
|
// Diffuse colors come from the gl_Color, ambient from the material. This is
|
|
|
|
// equivalent to osg::Material::DIFFUSE.
|
2009-11-14 06:19:09 +00:00
|
|
|
|
|
|
|
varying vec4 diffuse, constantColor;
|
|
|
|
varying vec3 normal, lightDir, halfVector;
|
2009-11-17 06:23:21 +00:00
|
|
|
varying float alpha, fogCoord;
|
2009-11-14 06:19:09 +00:00
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
2009-11-17 06:23:21 +00:00
|
|
|
vec4 ecPosition = gl_ModelViewMatrix * gl_Vertex;
|
|
|
|
vec3 ecPosition3 = vec3(gl_ModelViewMatrix * gl_Vertex) / ecPosition.w;
|
2009-11-14 06:19:09 +00:00
|
|
|
gl_Position = ftransform();
|
|
|
|
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
|
|
|
|
normal = gl_NormalMatrix * gl_Normal;
|
|
|
|
lightDir = normalize(vec3(gl_LightSource[0].position));
|
|
|
|
halfVector = normalize(gl_LightSource[0].halfVector.xyz);
|
|
|
|
diffuse = gl_Color * gl_LightSource[0].diffuse;
|
2009-11-17 21:57:07 +00:00
|
|
|
// Super hack: if diffuse material alpha is less than 1, assume a
|
|
|
|
// transparency animation is at work
|
|
|
|
if (gl_FrontMaterial.diffuse.a < 1.0)
|
|
|
|
alpha = gl_FrontMaterial.diffuse.a;
|
|
|
|
else
|
|
|
|
alpha = gl_Color.a;
|
2009-11-17 06:23:21 +00:00
|
|
|
constantColor = gl_FrontLightModelProduct.sceneColor
|
2009-11-14 06:19:09 +00:00
|
|
|
+ gl_FrontMaterial.ambient * gl_LightSource[0].ambient;
|
2009-11-17 06:23:21 +00:00
|
|
|
fogCoord = abs(ecPosition3.z);
|
2009-11-14 06:19:09 +00:00
|
|
|
}
|