[12115] | 1 | #version 120 |
---|
| 2 | |
---|
| 3 | uniform vec4 lightDiffuse; |
---|
| 4 | uniform vec4 lightSpecular; |
---|
| 5 | uniform vec4 scaleBias; |
---|
| 6 | uniform float exponent; |
---|
| 7 | uniform sampler2D normalHeightMap; |
---|
| 8 | |
---|
| 9 | varying vec3 tangentEyeDir; |
---|
| 10 | varying vec3 tangentLightDir[2]; |
---|
| 11 | varying vec4 shadowUV[2]; |
---|
| 12 | varying vec4 oUv0; |
---|
| 13 | |
---|
| 14 | vec4 lit(float NdotL, float NdotH, float m) { |
---|
| 15 | |
---|
| 16 | float ambient = 1.0; |
---|
| 17 | float diffuse = max(NdotL, 0.0); |
---|
| 18 | float specular = step(0.0, NdotL) * max(NdotH * m, 0.0); |
---|
| 19 | |
---|
| 20 | return vec4(ambient, diffuse, specular, 1.0); |
---|
| 21 | } |
---|
| 22 | |
---|
| 23 | vec3 expand(vec3 v) |
---|
| 24 | { |
---|
| 25 | return (v - 0.5) * 2.0; |
---|
| 26 | } |
---|
| 27 | |
---|
| 28 | /* |
---|
| 29 | Pixel Shader for doing bump mapping with parallax plus diffuse and specular lighting by masterfalcon |
---|
| 30 | */ |
---|
| 31 | void main() |
---|
| 32 | { |
---|
| 33 | float height = texture2D(normalHeightMap, oUv0.xy).a; |
---|
| 34 | float displacement = (height * scaleBias.x) + scaleBias.y; |
---|
| 35 | vec2 newTexCoord = ((tangentEyeDir * displacement) + oUv0.xyz).xy; |
---|
| 36 | vec3 bumpVec = expand(texture2D(normalHeightMap, newTexCoord).xyz); |
---|
| 37 | vec3 N = normalize(bumpVec); |
---|
| 38 | |
---|
| 39 | vec3 halfAngle = normalize(tangentEyeDir + tangentLightDir[0]); |
---|
| 40 | float NdotL = dot(normalize(tangentLightDir[0]), N); |
---|
| 41 | float NdotH = dot(normalize(halfAngle), N); |
---|
| 42 | |
---|
| 43 | vec4 Lit = lit(NdotL, NdotH, exponent); |
---|
| 44 | |
---|
| 45 | gl_FragColor = lightDiffuse * Lit.y + lightSpecular * Lit.z; |
---|
| 46 | } |
---|