Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: data/branches/Shader_HS18/programs/Example/GLSLES/Example_BumpMappingSpecularFp.glsles @ 12091

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

Updated programs and adjusted Material to work with GLSL>150

File size: 1.0 KB
Line 
1#version 100
2precision mediump int;
3precision mediump float;
4
5// General functions
6
7// Expand a range-compressed vector
8vec3 expand(vec3 v)
9{
10        return (v - 0.5) * 2.0;
11}
12
13uniform vec4 lightDiffuse;
14uniform vec4 lightSpecular;
15uniform sampler2D normalMap;
16
17varying vec4 oUv0;
18varying vec3 oTSLightDir;
19varying vec3 oTSHalfAngle;
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(texture2D(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        gl_FragColor = (lightDiffuse * clamp(dot(bumpVec, lightVec), 0.0, 1.0)) +
40                        (lightSpecular * specFactor);
41}
Note: See TracBrowser for help on using the repository browser.