Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: data/branches/Shader_HS18/programs/Example/GLSL150/Example_BumpMappingSpecularFp.glsl @ 12083

Last change on this file since 12083 was 12083, checked in by wiesep, 6 years ago

Reorganised shader programs

File size: 1.0 KB
Line 
1#version 150
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
15in vec4 oUv0;
16in vec3 oTSLightDir;
17in vec3 oTSHalfAngle;
18
19out vec4 fragColour;
20
21// NOTE: GLSL does not have the saturate function.  But it is equivalent to clamp(val, 0.0, 1.0)
22
23/* Fragment program which supports specular component */
24void main()
25{
26        // retrieve normalised light vector
27        vec3 lightVec = normalize(oTSLightDir);
28
29        // retrieve half angle and normalise
30        vec3 halfAngle = normalize(oTSHalfAngle);
31
32        // get bump map vector, again expand from range-compressed
33        vec3 bumpVec = expand(texture(normalMap, oUv0.xy).xyz);
34
35        // Pre-raise the specular exponent to the eight power
36        float specFactor = pow(clamp(dot(bumpVec, halfAngle), 0.0, 1.0), 4.0);
37
38        // Calculate dot product for diffuse
39        fragColour = (lightDiffuse * clamp(dot(bumpVec, lightVec), 0.0, 1.0)) + 
40                        (lightSpecular * specFactor);
41}
Note: See TracBrowser for help on using the repository browser.