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.
|
2012-02-14 16:38:18 +00:00
|
|
|
#version 120
|
2009-11-14 06:19:09 +00:00
|
|
|
|
2010-08-13 16:49:25 +00:00
|
|
|
#define MODE_OFF 0
|
|
|
|
#define MODE_DIFFUSE 1
|
|
|
|
#define MODE_AMBIENT_AND_DIFFUSE 2
|
2009-11-14 06:19:09 +00:00
|
|
|
|
2010-08-13 16:49:25 +00:00
|
|
|
// The ambient term of the lighting equation that doesn't depend on
|
|
|
|
// the surface normal is passed in gl_{Front,Back}Color. The alpha
|
|
|
|
// component is set to 1 for front, 0 for back in order to work around
|
|
|
|
// bugs with gl_FrontFacing in the fragment shader.
|
|
|
|
varying vec4 diffuse_term;
|
|
|
|
varying vec3 normal;
|
2012-02-14 16:38:18 +00:00
|
|
|
//varying float fogCoord;
|
2010-08-13 16:49:25 +00:00
|
|
|
|
|
|
|
uniform int colorMode;
|
2010-06-15 17:29:24 +00:00
|
|
|
|
2009-11-14 06:19:09 +00:00
|
|
|
void main()
|
|
|
|
{
|
2012-02-14 16:38:18 +00:00
|
|
|
//vec4 ecPosition = gl_ModelViewMatrix * gl_Vertex;
|
2009-11-14 06:19:09 +00:00
|
|
|
gl_Position = ftransform();
|
|
|
|
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
|
|
|
|
normal = gl_NormalMatrix * gl_Normal;
|
2010-08-13 16:49:25 +00:00
|
|
|
vec4 ambient_color, diffuse_color;
|
|
|
|
if (colorMode == MODE_DIFFUSE) {
|
|
|
|
diffuse_color = gl_Color;
|
|
|
|
ambient_color = gl_FrontMaterial.ambient;
|
|
|
|
} else if (colorMode == MODE_AMBIENT_AND_DIFFUSE) {
|
|
|
|
diffuse_color = gl_Color;
|
|
|
|
ambient_color = gl_Color;
|
|
|
|
} else {
|
|
|
|
diffuse_color = gl_FrontMaterial.diffuse;
|
|
|
|
ambient_color = gl_FrontMaterial.ambient;
|
|
|
|
}
|
|
|
|
diffuse_term = diffuse_color * gl_LightSource[0].diffuse;
|
|
|
|
vec4 ambient_term = ambient_color * gl_LightSource[0].ambient;
|
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)
|
2010-08-13 16:49:25 +00:00
|
|
|
diffuse_term.a = gl_FrontMaterial.diffuse.a;
|
2009-11-17 21:57:07 +00:00
|
|
|
else
|
2010-08-13 16:49:25 +00:00
|
|
|
diffuse_term.a = gl_Color.a;
|
2010-06-15 17:29:24 +00:00
|
|
|
// Another hack for supporting two-sided lighting without using
|
|
|
|
// gl_FrontFacing in the fragment shader.
|
2010-08-13 16:49:25 +00:00
|
|
|
gl_FrontColor.rgb = ambient_term.rgb; gl_FrontColor.a = 1.0;
|
|
|
|
gl_BackColor.rgb = ambient_term.rgb; gl_FrontColor.a = 0.0;
|
2012-02-14 16:38:18 +00:00
|
|
|
//fogCoord = abs(ecPosition.z / ecPosition.w);
|
2009-11-14 06:19:09 +00:00
|
|
|
}
|