Last change
on this file since 12373 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
|
Rev | Line | |
---|
[12115] | 1 | #version 120 |
---|
| 2 | |
---|
| 3 | uniform vec3 lightDiffuse; |
---|
| 4 | uniform vec3 lightSpecular; |
---|
| 5 | uniform vec4 scaleBias; |
---|
| 6 | |
---|
| 7 | uniform sampler2D normalHeightMap; |
---|
| 8 | uniform sampler2D diffuseMap; |
---|
| 9 | |
---|
| 10 | varying vec3 oEyeDir; |
---|
| 11 | varying vec3 oLightDir; |
---|
| 12 | varying vec3 oHalfAngle; |
---|
| 13 | varying vec4 oUv0; |
---|
| 14 | |
---|
| 15 | // Expand a range-compressed vector |
---|
| 16 | vec3 expand(vec3 v) |
---|
| 17 | { |
---|
| 18 | return (v - 0.5) * 2.0; |
---|
| 19 | } |
---|
| 20 | |
---|
| 21 | void 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.