Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: data/branches/Shader_HS18/programs/Example/GLSLES/OffsetMappingFp.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.1 KB
Line 
1#version 100
2precision mediump int;
3precision mediump float;
4
5uniform vec3 lightDiffuse;
6uniform vec3 lightSpecular;
7uniform vec4 scaleBias;
8
9uniform sampler2D normalHeightMap;
10uniform sampler2D diffuseMap;
11
12varying vec3 oEyeDir;
13varying vec3 oLightDir;
14varying vec3 oHalfAngle;
15varying vec4 oUv0;
16
17// Expand a range-compressed vector
18vec3 expand(vec3 v)
19{
20        return (v - 0.5) * 2.0;
21}
22
23void main()
24{
25    // Get the height using the tex coords
26    float height = texture2D(normalHeightMap, oUv0.xy).a;
27
28    // Calculate displacement
29    float displacement = (height * scaleBias.x) + scaleBias.y;
30       
31    vec3 uv2 = vec3(oUv0.xy, 1.0);
32       
33    // calculate the new tex coord to use for normal and diffuse
34    vec2 newTexCoord = ((oEyeDir * displacement) + uv2).xy;
35       
36    // get the new normal and diffuse values
37    vec3 normal = expand(texture2D(normalHeightMap, newTexCoord).xyz);
38    vec3 diffuse = texture2D(diffuseMap, newTexCoord).xyz;
39    vec3 specular = pow(clamp(dot(normal, oHalfAngle), 0.0, 1.0), 32.0) * lightSpecular;
40
41    vec3 col = diffuse * (clamp(dot(normal, oLightDir), 0.0, 1.0) * lightDiffuse) + specular;
42    gl_FragColor = vec4(col, 1.0);
43}
Note: See TracBrowser for help on using the repository browser.