Line | |
---|
1 | #version 150 |
---|
2 | |
---|
3 | uniform vec3 lightDiffuse; |
---|
4 | uniform vec3 lightSpecular; |
---|
5 | uniform vec4 scaleBias; |
---|
6 | |
---|
7 | uniform sampler2D normalHeightMap; |
---|
8 | uniform sampler2D diffuseMap; |
---|
9 | |
---|
10 | in vec3 oEyeDir; |
---|
11 | in vec3 oLightDir; |
---|
12 | in vec3 oHalfAngle; |
---|
13 | in vec4 oUv0; |
---|
14 | |
---|
15 | out vec4 fragColour; |
---|
16 | |
---|
17 | // Expand a range-compressed vector |
---|
18 | vec3 expand(vec3 v) |
---|
19 | { |
---|
20 | return (v - 0.5) * 2.0; |
---|
21 | } |
---|
22 | |
---|
23 | void 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.