Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: data/data_extern/programs/GLSL120/OffsetMappingFp.glsl @ 12412

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

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

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