[12083] | 1 | #version 150 |
---|
| 2 | |
---|
| 3 | uniform vec4 lightDiffuse; |
---|
| 4 | uniform vec4 scaleBias; |
---|
| 5 | uniform vec4 spotParams; |
---|
| 6 | uniform vec4 lightDiffuse1; |
---|
| 7 | uniform vec4 spotParams1; |
---|
| 8 | |
---|
| 9 | uniform sampler2D normalHeightMap; |
---|
| 10 | uniform sampler2D diffuseMap; |
---|
| 11 | uniform sampler2D shadowMap1; |
---|
| 12 | uniform sampler2D shadowMap2; |
---|
| 13 | |
---|
| 14 | in vec3 tangentEyeDir; |
---|
| 15 | in vec3 tangentLightDir[2]; |
---|
| 16 | in vec3 tangentSpotDir[2]; |
---|
| 17 | in vec4 shadowUV[2]; |
---|
| 18 | in vec4 oUv0; |
---|
| 19 | |
---|
| 20 | out vec4 fragColour; |
---|
| 21 | |
---|
| 22 | // Expand a range-compressed vector |
---|
| 23 | vec3 expand(vec3 v) |
---|
| 24 | { |
---|
| 25 | return (v - 0.5) * 2.0; |
---|
| 26 | } |
---|
| 27 | |
---|
| 28 | void main() |
---|
| 29 | { |
---|
| 30 | // get the height using the tex coords |
---|
| 31 | float height = texture(normalHeightMap, oUv0.xy).a; |
---|
| 32 | // scale and bias factors |
---|
| 33 | float scale = scaleBias.x; |
---|
| 34 | float bias = scaleBias.y; |
---|
| 35 | |
---|
| 36 | // calculate displacement |
---|
| 37 | float displacement = (height * scale) + bias; |
---|
| 38 | //float displacement = (height * 0.04) - 0.02; |
---|
| 39 | |
---|
| 40 | vec3 scaledEyeDir = tangentEyeDir * displacement; |
---|
| 41 | |
---|
| 42 | // calculate the new tex coord to use for normal and diffuse |
---|
| 43 | vec2 newTexCoord = (scaledEyeDir + oUv0.xyz).xy; |
---|
| 44 | |
---|
| 45 | // get the new normal and diffuse values |
---|
| 46 | vec3 normal = expand(texture(normalHeightMap, newTexCoord).xyz); |
---|
| 47 | vec4 diffuse = texture(diffuseMap, newTexCoord); |
---|
| 48 | |
---|
| 49 | vec4 col1 = diffuse * clamp(dot(normal, tangentLightDir[0]),0.0,1.0) * lightDiffuse; |
---|
| 50 | // factor in spotlight angle |
---|
| 51 | float rho = clamp(dot(tangentSpotDir[0], tangentLightDir[0]),0.0,1.0); |
---|
| 52 | // factor = (rho - cos(outer/2) / cos(inner/2) - cos(outer/2)) ^ falloff |
---|
| 53 | float spotFactor = pow( |
---|
| 54 | clamp(rho - spotParams.y,0.0,1.0) / (spotParams.x - spotParams.y), spotParams.z); |
---|
| 55 | col1 = col1 * spotFactor; |
---|
| 56 | vec4 col2 = diffuse * clamp(dot(normal, tangentLightDir[1]),0.0,1.0) * lightDiffuse1; |
---|
| 57 | // factor in spotlight angle |
---|
| 58 | rho = clamp(dot(tangentSpotDir[1], tangentLightDir[1]),0.0,1.0); |
---|
| 59 | // factor = (rho - cos(outer/2) / cos(inner/2) - cos(outer/2)) ^ falloff |
---|
| 60 | spotFactor = pow( |
---|
| 61 | clamp(rho - spotParams1.y,0.0,1.0) / (spotParams1.x - spotParams1.y), spotParams1.z); |
---|
| 62 | col2 = col2 * spotFactor; |
---|
| 63 | |
---|
| 64 | // shadow textures |
---|
| 65 | col1 = col1 * textureProj(shadowMap1, shadowUV[0]); |
---|
| 66 | col2 = col2 * textureProj(shadowMap2, shadowUV[1]); |
---|
| 67 | |
---|
| 68 | fragColour = col1 + col2; |
---|
| 69 | } |
---|