Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Reorganised shader programs

File size: 1.1 KB
Line 
1#version 150
2
3uniform vec3 lightDiffuse;
4uniform vec3 lightSpecular;
5uniform vec4 scaleBias;
6
7uniform sampler2D normalHeightMap;
8uniform sampler2D diffuseMap;
9
10in vec3 oEyeDir;
11in vec3 oLightDir;
12in vec3 oHalfAngle;
13in vec4 oUv0;
14
15out vec4 fragColour;
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 = texture(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(texture(normalHeightMap, newTexCoord).xyz);
38    vec3 diffuse = texture(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    fragColour = vec4(col, 1.0);
43}
Note: See TracBrowser for help on using the repository browser.