1// -*-C++-*-
2#version 120
3
4// Shader that uses OpenGL state values to do per-pixel lighting
5//
6// The only light used is gl_LightSource[0], which is assumed to be
7// directional.
8//
9// Diffuse colors come from the gl_Color, ambient from the material. This is
10// equivalent to osg::Material::DIFFUSE.
11vec4 ambientColor();
12vec4 diffuseColor();
13vec4 specularColor();
14vec4 emissionColor();
15
16varying vec4 diffuse, constantColor, matSpecular;
17varying vec3 normal;
18//varying float alpha, fogCoord;
19varying float alpha;
20
21void main()
22{
23    //vec4 ecPosition = gl_ModelViewMatrix * gl_Vertex;
24    //vec3 ecPosition3 = vec3(gl_ModelViewMatrix * gl_Vertex) / ecPosition.w;
25    gl_Position = ftransform();
26    gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
27    normal = gl_NormalMatrix * gl_Normal;
28    diffuse = diffuseColor() * gl_LightSource[0].diffuse;
29    // Super hack: if diffuse material alpha is less than 1, assume a
30    // transparency animation is at work
31    if (gl_FrontMaterial.diffuse.a < 1.0)
32        alpha = gl_FrontMaterial.diffuse.a;
33    else
34        alpha = diffuse.a;
35    constantColor =  emissionColor()
36        + ambientColor() * (gl_LightModel.ambient + gl_LightSource[0].ambient);
37    //fogCoord = abs(ecPosition3.z);
38    matSpecular = specularColor();
39}
40