Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: data/branches/Shader_HS18/programs/GLSL/DepthShadowmapNormalMapReceiverFp.glsl @ 12115

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

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

File size: 1.9 KB
Line 
1#version 120
2
3uniform float inverseShadowmapSize;
4uniform float fixedDepthBias;
5uniform float gradientClamp;
6uniform float gradientScaleBias;
7uniform vec4 lightColour;
8
9uniform sampler2D shadowMap;
10uniform sampler2D normalMap;
11
12varying vec3 tangentLightDir;
13varying vec4 oUv;
14varying vec2 oUv2;
15
16// Expand a range-compressed vector
17vec3 expand(vec3 v)
18{
19        return (v - 0.5) * 2.0;
20}
21
22void main()
23{
24
25        // get the new normal and diffuse values
26        vec3 normal = normalize(expand(texture2D(normalMap, oUv2).xyz));
27       
28        vec4 vertexColour = clamp(dot(normal, tangentLightDir),0.0,1.0) * lightColour;
29
30
31        vec4 shadowUV = oUv;
32        // point on shadowmap
33        shadowUV = shadowUV / shadowUV.w;
34        float centerdepth = texture2D(shadowMap, shadowUV.xy).x;
35   
36    // gradient calculation
37        float pixeloffset = inverseShadowmapSize;
38    vec4 depths = vec4(
39        texture2D(shadowMap, shadowUV.xy + vec2(-pixeloffset, 0)).x,
40        texture2D(shadowMap, shadowUV.xy + vec2(+pixeloffset, 0)).x,
41        texture2D(shadowMap, shadowUV.xy + vec2(0, -pixeloffset)).x,
42        texture2D(shadowMap, shadowUV.xy + vec2(0, +pixeloffset)).x);
43
44        vec2 differences = abs( depths.yw - depths.xz );
45        float gradient = min(gradientClamp, max(differences.x, differences.y));
46        float gradientFactor = gradient * gradientScaleBias;
47
48        // visibility function
49        float depthAdjust = gradientFactor + (fixedDepthBias * centerdepth);
50        float finalCenterDepth = centerdepth + depthAdjust;
51
52        // shadowUV.z contains lightspace position of current object
53#if PCF
54        // use depths from prev, calculate diff
55        depths += depthAdjust;
56        float final = (finalCenterDepth > shadowUV.z) ? 1.0 : 0.0;
57        final += (depths.x > shadowUV.z) ? 1.0 : 0.0;
58        final += (depths.y > shadowUV.z) ? 1.0 : 0.0;
59        final += (depths.z > shadowUV.z) ? 1.0 : 0.0;
60        final += (depths.w > shadowUV.z) ? 1.0 : 0.0;
61       
62        final *= 0.2;
63
64        gl_FragColor = vec4(vertexColour.xyz * final, 1);
65       
66#else
67        gl_FragColor = (finalCenterDepth > shadowUV.z) ? vertexColour : vec4(0,0,0,1);
68#endif
69}
70
Note: See TracBrowser for help on using the repository browser.