Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: data/data_extern/programs/GLSL120/OffsetMappingShadowsFp.glsl @ 12412

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

Changed folder structure, deletet some unused files and cleaned up code

File size: 2.0 KB
Line 
1#version 120
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
14varying vec3 tangentEyeDir;
15varying vec3 tangentLightDir[2];
16varying vec3 tangentSpotDir[2];
17varying vec4 shadowUV[2];
18varying vec4 oUv0;
19
20// Expand a range-compressed vector
21vec3 expand(vec3 v)
22{
23        return (v - 0.5) * 2.0;
24}
25
26void main()
27{
28        // get the height using the tex coords
29        float height = texture2D(normalHeightMap, oUv0.xy).a;
30        // scale and bias factors       
31        float scale = scaleBias.x;
32        float bias = scaleBias.y;
33
34        // calculate displacement       
35        float displacement = (height * scale) + bias;
36        //float displacement = (height * 0.04) - 0.02;
37       
38        vec3 scaledEyeDir = tangentEyeDir * displacement;
39       
40        // calculate the new tex coord to use for normal and diffuse
41        vec2 newTexCoord = (scaledEyeDir + oUv0.xyz).xy;
42       
43        // get the new normal and diffuse values
44        vec3 normal = expand(texture2D(normalHeightMap, newTexCoord).xyz);
45        vec4 diffuse = texture2D(diffuseMap, newTexCoord);
46       
47        vec4 col1 = diffuse * clamp(dot(normal, tangentLightDir[0]),0.0,1.0) * lightDiffuse;
48        // factor in spotlight angle
49        float rho = clamp(dot(tangentSpotDir[0], tangentLightDir[0]),0.0,1.0);
50        // factor = (rho - cos(outer/2) / cos(inner/2) - cos(outer/2)) ^ falloff
51        float spotFactor = pow(
52                clamp(rho - spotParams.y,0.0,1.0) / (spotParams.x - spotParams.y), spotParams.z);
53        col1 = col1 * spotFactor;
54        vec4 col2 = diffuse * clamp(dot(normal, tangentLightDir[1]),0.0,1.0) * lightDiffuse1;
55        // factor in spotlight angle
56        rho = clamp(dot(tangentSpotDir[1], tangentLightDir[1]),0.0,1.0);
57        // factor = (rho - cos(outer/2) / cos(inner/2) - cos(outer/2)) ^ falloff
58        spotFactor = pow(
59                clamp(rho - spotParams1.y,0.0,1.0) / (spotParams1.x - spotParams1.y), spotParams1.z);
60        col2 = col2 * spotFactor;
61
62        // shadow textures
63        col1 = col1 * texture2DProj(shadowMap1, shadowUV[0]);
64        col2 = col2 * texture2DProj(shadowMap2, shadowUV[1]);
65
66        gl_FragColor = col1 + col2;
67
68}
Note: See TracBrowser for help on using the repository browser.