Debian Codegraph @

Shaders/planet.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 vec3 ecViewDir;
22 varying vec3 VTangent;
23
24 uniform int colorMode;
25
26 attribute vec3 tangent;//, binormal;
27
28
29
30 void main()
31 {
32
33 vec4 ep = gl_ModelViewMatrixInverse * vec4(0.0,0.0,0.0,1.0);
34 ecViewDir = (gl_ModelViewMatrix * (ep - gl_Vertex)).xyz;
35
36 gl_Position = ftransform();
37 gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
38 normal = gl_NormalMatrix * gl_Normal;
39 VTangent = gl_NormalMatrix * tangent;
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 vec4 light_diffuse = vec4 (1.0,1.0,1.0,1.0);
52 vec4 light_ambient = vec4 (0.03, 0.03, 0.03, 1.0);
53
54 diffuse_term = diffuse_color * light_diffuse;//gl_LightSource[0].diffuse;
55 vec4 constant_term = gl_FrontMaterial.emission + ambient_color *
56 (gl_LightModel.ambient + light_ambient);
57 // Super hack: if diffuse material alpha is less than 1, assume a
58 // transparency animation is at work
59 if (gl_FrontMaterial.diffuse.a < 1.0)
60 diffuse_term.a = gl_FrontMaterial.diffuse.a;
61 else
62 diffuse_term.a = gl_Color.a;
63 // Another hack for supporting two-sided lighting without using
64 // gl_FrontFacing in the fragment shader.
65 gl_FrontColor.rgb = constant_term.rgb; gl_FrontColor.a = 1.0;
66 gl_BackColor.rgb = constant_term.rgb; gl_BackColor.a = 0.0;
67 //fogCoord = abs(ecPosition.z / ecPosition.w);
68 //fog_Func(fogType);
69 }