3 // Shader that uses OpenGL state values to do per-pixel lighting
5 // The only light used is gl_LightSource[0], which is assumed to be
8 // Diffuse colors come from the gl_Color, ambient from the material. This is
9 // equivalent to osg::Material::DIFFUSE.
12 #define MODE_DIFFUSE 1
13 #define MODE_AMBIENT_AND_DIFFUSE 2
15 // The constant term of the lighting equation that doesn't depend on
16 // the surface normal is passed in gl_{Front,Back}Color. The alpha
17 // component is set to 1 for front, 0 for back in order to work around
18 // bugs with gl_FrontFacing in the fragment shader.
19 varying vec4 diffuse_term;
22 uniform int colorMode;
24 ////fog "include"////////
25 //uniform int fogType;
27 //void fog_Func(int type);
28 /////////////////////////
33 // Determine the rotation for the building. The Color alpha value provides rotation information
34 float sr = sin(6.28 * gl_Color.a);
35 float cr = cos(6.28 * gl_Color.a);
37 vec3 position = gl_Vertex.xyz;
39 // Rotation of the building and movement into position
40 position.xy = vec2(dot(position.xy, vec2(cr, sr)), dot(position.xy, vec2(-sr, cr)));
41 position = position + gl_Color.xyz;
43 gl_Position = gl_ModelViewProjectionMatrix * vec4(position,1.0);
45 //gl_Position = ftransform();
46 gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
50 normal.xy = vec2(dot(normal.xy, vec2(cr, sr)), dot(normal.xy, vec2(-sr, cr)));
51 normal = gl_NormalMatrix * normal;
53 vec4 ambient_color, diffuse_color;
54 if (colorMode == MODE_DIFFUSE) {
55 diffuse_color = vec4(1.0,1.0,1.0,1.0);
56 ambient_color = gl_FrontMaterial.ambient;
57 } else if (colorMode == MODE_AMBIENT_AND_DIFFUSE) {
58 diffuse_color = vec4(1.0,1.0,1.0,1.0);
59 ambient_color = vec4(1.0,1.0,1.0,1.0);
61 diffuse_color = gl_FrontMaterial.diffuse;
62 ambient_color = gl_FrontMaterial.ambient;
65 diffuse_term = diffuse_color * gl_LightSource[0].diffuse;
66 vec4 constant_term = gl_FrontMaterial.emission + ambient_color *
67 (gl_LightModel.ambient + gl_LightSource[0].ambient);
68 // Super hack: if diffuse material alpha is less than 1, assume a
69 // transparency animation is at work
70 if (gl_FrontMaterial.diffuse.a < 1.0)
71 diffuse_term.a = gl_FrontMaterial.diffuse.a;
74 // Another hack for supporting two-sided lighting without using
75 // gl_FrontFacing in the fragment shader.
76 gl_FrontColor.rgb = constant_term.rgb; gl_FrontColor.a = 1.0;
77 gl_BackColor.rgb = constant_term.rgb; gl_BackColor.a = 0.0;
78 //fogCoord = abs(ecPosition.z / ecPosition.w);