Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: data/branches/Shader_HS18/programs/GLSL120/BumpMapping/Example_BumpMappingSpecularFp.glsl @ 12115

Last change on this file since 12115 was 12115, checked in by wiesep, 5 years ago

Changed folder structure, deletet some unused files and cleaned up code

File size: 1007 bytes
Line 
1#version 120
2
3// General functions
4
5// Expand a range-compressed vector
6vec3 expand(vec3 v)
7{
8        return (v - 0.5) * 2.0;
9}
10
11uniform vec4 lightDiffuse;
12uniform vec4 lightSpecular;
13uniform sampler2D normalMap;
14
15varying vec4 oUv0;
16varying vec3 oTSLightDir;
17varying vec3 oTSHalfAngle;
18
19// NOTE: GLSL does not have the saturate function.  But it is equivalent to clamp(val, 0.0, 1.0)
20
21/* Fragment program which supports specular component */
22void main()
23{
24        // retrieve normalised light vector
25        vec3 lightVec = normalize(oTSLightDir);
26
27        // retrieve half angle and normalise
28        vec3 halfAngle = normalize(oTSHalfAngle);
29
30        // get bump map vector, again expand from range-compressed
31        vec3 bumpVec = expand(texture2D(normalMap, oUv0.xy).xyz);
32
33        // Pre-raise the specular exponent to the eight power
34        float specFactor = pow(clamp(dot(bumpVec, halfAngle), 0.0, 1.0), 4.0);
35
36        // Calculate dot product for diffuse
37        gl_FragColor = (lightDiffuse * clamp(dot(bumpVec, lightVec), 0.0, 1.0)) + 
38                        (lightSpecular * specFactor);
39}
Note: See TracBrowser for help on using the repository browser.