fixed: auto_ptr -> unique_ptr
[opensg.git] / Examples / CSM / Shader / BumpMap / bump.fp
blob6609ad4d2a8c55874fc0e7135043b8bcbaf70fc8
2 uniform sampler2D sampler2d; // value of sampler2d = 3
3 varying vec3 lightDir; // interpolated surface local coordinate light
4 // direction
5 varying vec3 viewDir; // interpolated surface local coordinate view
6 // direction
8 const float diffuseFactor = 0.7;
9 const float specularFactor = 0.7;
10 vec3 basecolor = vec3 (0.8, 0.7, 0.3);
12 void main (void)
14 vec3 norm;
15 vec3 r;
16 vec3 color;
17 float intensity;
18 float spec;
19 float d;
21 // Fetch normal from normal map
22 norm = vec3(texture2D(sampler2d, vec2 (gl_TexCoord[0])));
23 norm = (norm - 0.5) * 2.0;
24 norm.y = -norm.y;
25 intensity = max(dot(lightDir, norm), 0.0) * diffuseFactor;
27 // Compute specular reflection component
28 d = 2.0 * dot(lightDir, norm);
29 r = d * norm;
30 r = lightDir - r;
31 spec = pow(max(dot(r, viewDir), 0.0) , 6.0) * specularFactor;
32 intensity += min (spec, 1.0);
34 // Compute final color value
35 color = clamp(basecolor * intensity, 0.0, 1.0);
37 // Write out final fragment color
38 gl_FragColor = vec4 (color, 1.0);