Debian Codegraph @

Shaders/default.vert

raw
1 // -*-C++-*-
2
3 // Shader that uses OpenGL state values to do per-pixel lighting
4 //
5 // The only light used is gl_LightSource[0], which is assumed to be
6 // directional.
7 //
8 // Diffuse colors come from the gl_Color, ambient from the material. This is
9 // equivalent to osg::Material::DIFFUSE.
10 #version 120
11 #define MODE_OFF 0
12 #define MODE_DIFFUSE 1
13 #define MODE_AMBIENT_AND_DIFFUSE 2
14
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;
20 varying vec3 normal;
21 varying vec4 ecPosition;
22
23 uniform int colorMode;
24
25 void setupShadows(vec4 eyeSpacePos);
26
27 ////fog "include"////////
28 //uniform int fogType;
29 //
30 //void fog_Func(int type);
31 /////////////////////////
32
33 void main()
34 {
35 gl_Position = ftransform();
36 ecPosition = gl_ModelViewMatrix * gl_Vertex;
37 gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
38 gl_TexCoord[2] = gl_TextureMatrix[2] * gl_MultiTexCoord2;
39 normal = gl_NormalMatrix * gl_Normal;
40 vec4 ambient_color, diffuse_color;
41 if (colorMode == MODE_DIFFUSE) {
42 diffuse_color = gl_Color;
43 ambient_color = gl_FrontMaterial.ambient;
44 } else if (colorMode == MODE_AMBIENT_AND_DIFFUSE) {
45 diffuse_color = gl_Color;
46 ambient_color = gl_Color;
47 } else {
48 diffuse_color = gl_FrontMaterial.diffuse;
49 ambient_color = gl_FrontMaterial.ambient;
50 }
51 diffuse_term = diffuse_color * gl_LightSource[0].diffuse;
52 vec4 constant_term = gl_FrontMaterial.emission + ambient_color *
53 (gl_LightModel.ambient + gl_LightSource[0].ambient);
54 // Super hack: if diffuse material alpha is less than 1, assume a
55 // transparency animation is at work
56 if (gl_FrontMaterial.diffuse.a < 1.0)
57 diffuse_term.a = gl_FrontMaterial.diffuse.a;
58 else
59 diffuse_term.a = gl_Color.a;
60 // Another hack for supporting two-sided lighting without using
61 // gl_FrontFacing in the fragment shader.
62 gl_FrontColor.rgb = constant_term.rgb; gl_FrontColor.a = 1.0;
63 gl_BackColor.rgb = constant_term.rgb; gl_BackColor.a = 0.0;
64 //fogCoord = abs(ecPosition.z / ecPosition.w);
65 //fog_Func(fogType);
66 setupShadows(ecPosition);
67 }