81 lines
2.7 KiB
GLSL
81 lines
2.7 KiB
GLSL
|
// -*-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.
|
||
|
//
|
||
|
// Diffuse colors come from the gl_Color, ambient from the material. This is
|
||
|
// equivalent to osg::Material::DIFFUSE.
|
||
|
#version 120
|
||
|
#define MODE_OFF 0
|
||
|
#define MODE_DIFFUSE 1
|
||
|
#define MODE_AMBIENT_AND_DIFFUSE 2
|
||
|
|
||
|
// The constant 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;
|
||
|
|
||
|
uniform int colorMode;
|
||
|
|
||
|
////fog "include"////////
|
||
|
//uniform int fogType;
|
||
|
//
|
||
|
//void fog_Func(int type);
|
||
|
/////////////////////////
|
||
|
|
||
|
void main()
|
||
|
{
|
||
|
|
||
|
// Determine the rotation for the building. The Color alpha value provides rotation information
|
||
|
float sr = sin(6.28 * gl_Color.a);
|
||
|
float cr = cos(6.28 * gl_Color.a);
|
||
|
|
||
|
vec3 position = gl_Vertex.xyz;
|
||
|
|
||
|
// Rotation of the building and movement into position
|
||
|
position.xy = vec2(dot(position.xy, vec2(cr, sr)), dot(position.xy, vec2(-sr, cr)));
|
||
|
position = position + gl_Color.xyz;
|
||
|
|
||
|
gl_Position = gl_ModelViewProjectionMatrix * vec4(position,1.0);
|
||
|
|
||
|
//gl_Position = ftransform();
|
||
|
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
|
||
|
|
||
|
// Rotate the normal.
|
||
|
normal = gl_Normal;
|
||
|
normal.xy = vec2(dot(normal.xy, vec2(cr, sr)), dot(normal.xy, vec2(-sr, cr)));
|
||
|
normal = gl_NormalMatrix * normal;
|
||
|
|
||
|
vec4 ambient_color, diffuse_color;
|
||
|
if (colorMode == MODE_DIFFUSE) {
|
||
|
diffuse_color = vec4(1.0,1.0,1.0,1.0);
|
||
|
ambient_color = gl_FrontMaterial.ambient;
|
||
|
} else if (colorMode == MODE_AMBIENT_AND_DIFFUSE) {
|
||
|
diffuse_color = vec4(1.0,1.0,1.0,1.0);
|
||
|
ambient_color = vec4(1.0,1.0,1.0,1.0);
|
||
|
} else {
|
||
|
diffuse_color = gl_FrontMaterial.diffuse;
|
||
|
ambient_color = gl_FrontMaterial.ambient;
|
||
|
}
|
||
|
|
||
|
diffuse_term = diffuse_color * gl_LightSource[0].diffuse;
|
||
|
vec4 constant_term = gl_FrontMaterial.emission + ambient_color *
|
||
|
(gl_LightModel.ambient + gl_LightSource[0].ambient);
|
||
|
// Super hack: if diffuse material alpha is less than 1, assume a
|
||
|
// transparency animation is at work
|
||
|
if (gl_FrontMaterial.diffuse.a < 1.0)
|
||
|
diffuse_term.a = gl_FrontMaterial.diffuse.a;
|
||
|
else
|
||
|
diffuse_term.a = 1.0;
|
||
|
// Another hack for supporting two-sided lighting without using
|
||
|
// gl_FrontFacing in the fragment shader.
|
||
|
gl_FrontColor.rgb = constant_term.rgb; gl_FrontColor.a = 1.0;
|
||
|
gl_BackColor.rgb = constant_term.rgb; gl_BackColor.a = 0.0;
|
||
|
//fogCoord = abs(ecPosition.z / ecPosition.w);
|
||
|
//fog_Func(fogType);
|
||
|
}
|