2 uniform sampler2D sampler2d
; // value of sampler2d
= 3
3 varying vec3 lightDir
; // interpolated surface local coordinate
light
5 varying vec3 viewDir
; // interpolated surface local coordinate view
8 const
float diffuseFactor
= 0.7;
9 const
float specularFactor
= 0.7;
10 vec3 basecolor
= vec3 (0.8, 0.7, 0.3);
21 // Fetch normal from normal map
22 norm
= vec3(texture2D(sampler2d
, vec2 (gl_TexCoord
[0])));
23 norm
= (norm
- 0.5) * 2.0;
25 intensity
= max(dot(lightDir
, norm
), 0.0) * diffuseFactor
;
27 // Compute specular reflection component
28 d
= 2.0 * dot(lightDir
, norm
);
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);