Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Reorganised shader programs

File size: 2.1 KB
Line 
1#version 150
2
3uniform vec4 lightDiffuse;
4uniform vec4 scaleBias;
5uniform vec4 spotParams;
6uniform vec4 lightDiffuse1;
7uniform vec4 spotParams1;
8
9uniform sampler2D normalHeightMap;
10uniform sampler2D diffuseMap;
11uniform sampler2D shadowMap1;
12uniform sampler2D shadowMap2;
13
14in vec3 tangentEyeDir;
15in vec3 tangentLightDir[2];
16in vec3 tangentSpotDir[2];
17in vec4 shadowUV[2];
18in vec4 oUv0;
19
20out vec4 fragColour;
21
22// Expand a range-compressed vector
23vec3 expand(vec3 v)
24{
25        return (v - 0.5) * 2.0;
26}
27
28void 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}
Note: See TracBrowser for help on using the repository browser.