root/OpenSceneGraph-Data/trunk/shaders/lookup.vert

Revision 7004 (checked in by robert, 2 years ago)

Added osgTerrain look filters.

Line 
1 uniform float filterWidth;
2 uniform bool lightingEnabled;
3
4 varying vec2 texcoord[9];
5
6
7 vec3 fnormal(void)
8 {
9     //Compute the normal
10     vec3 normal = gl_NormalMatrix * gl_Normal;
11     normal = normalize(normal);
12     return normal;
13 }
14
15 void directionalLight(in int i,
16                       in vec3 normal,
17                       inout vec4 ambient,
18                       inout vec4 diffuse,
19                       inout vec4 specular)
20 {
21    float nDotVP;         // normal . light direction
22    float nDotHV;         // normal . light half vector
23    float pf;             // power factor
24
25    nDotVP = max(0.0, dot(normal, normalize(vec3 (gl_LightSource[i].position))));
26    nDotHV = max(0.0, dot(normal, vec3 (gl_LightSource[i].halfVector)));
27
28    if (nDotVP == 0.0)
29    {
30        pf = 0.0;
31    }
32    else
33    {
34        pf = pow(nDotHV, gl_FrontMaterial.shininess);
35
36    }
37    ambient  += gl_LightSource[i].ambient;
38    diffuse  += gl_LightSource[i].diffuse * nDotVP;
39    specular += gl_LightSource[i].specular * pf;
40 }
41
42
43
44 void main()
45 {
46     gl_Position = ftransform();
47
48     if (lightingEnabled)
49     {   
50         vec4 ambient = vec4(0.0);
51         vec4 diffuse = vec4(0.0);
52         vec4 specular = vec4(0.0);
53
54
55         vec3 normal = fnormal();
56
57         directionalLight(0, normal, ambient, diffuse, specular);
58
59         vec4 color = gl_FrontLightModelProduct.sceneColor +
60                      ambient  * gl_FrontMaterial.ambient +
61                      diffuse  * gl_FrontMaterial.diffuse +
62                      specular * gl_FrontMaterial.specular;
63
64         gl_FrontColor = color;
65
66     }
67     else
68     {
69         gl_FrontColor = gl_Color;
70     }
71
72     float delta = filterWidth;
73
74     texcoord[0].xy = gl_MultiTexCoord0.xy + vec2(-delta, delta);
75     texcoord[1].xy = gl_MultiTexCoord0.xy + vec2(-delta, 0);
76     texcoord[2].xy = gl_MultiTexCoord0.xy + vec2(-delta, -delta);
77     texcoord[3].xy = gl_MultiTexCoord0.xy + vec2(0, delta);
78     texcoord[4].xy = gl_MultiTexCoord0.xy + vec2(0, 0);
79     texcoord[5].xy = gl_MultiTexCoord0.xy + vec2(0, -delta);
80     texcoord[6].xy = gl_MultiTexCoord0.xy + vec2(delta, delta);
81     texcoord[7].xy = gl_MultiTexCoord0.xy + vec2(delta, 0);
82     texcoord[8].xy = gl_MultiTexCoord0.xy + vec2(delta, -delta);
83    
84 }
Note: See TracBrowser for help on using the browser.