Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: data/data_extern/programs/GLSL/DepthShadowmapReceiverFp.glsl @ 12302

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

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

File size: 1.6 KB
Line 
1#version 120
2
3uniform float inverseShadowmapSize;
4uniform float fixedDepthBias;
5uniform float gradientClamp;
6uniform float gradientScaleBias;
7
8uniform sampler2D shadowMap;
9
10varying vec4 oUv;
11varying vec4 outColor;
12
13void main()
14{
15        vec4 shadowUV = oUv;
16        // point on shadowmap
17        shadowUV = shadowUV / shadowUV.w;
18        float centerdepth = texture2D(shadowMap, shadowUV.xy).x;
19   
20    // gradient calculation
21        float pixeloffset = inverseShadowmapSize;
22    vec4 depths = vec4(
23        texture2D(shadowMap, shadowUV.xy + vec2(-pixeloffset, 0)).x,
24        texture2D(shadowMap, shadowUV.xy + vec2(+pixeloffset, 0)).x,
25        texture2D(shadowMap, shadowUV.xy + vec2(0, -pixeloffset)).x,
26        texture2D(shadowMap, shadowUV.xy + vec2(0, +pixeloffset)).x);
27
28        vec2 differences = abs( depths.yw - depths.xz );
29        float gradient = min(gradientClamp, max(differences.x, differences.y));
30        float gradientFactor = gradient * gradientScaleBias;
31
32        // visibility function
33        float depthAdjust = gradientFactor + (fixedDepthBias * centerdepth);
34        float finalCenterDepth = centerdepth + depthAdjust;
35
36        // shadowUV.z contains lightspace position of current object
37#if PCF
38        // use depths from prev, calculate diff
39        depths += depthAdjust;
40        float final = (finalCenterDepth > shadowUV.z) ? 1.0 : 0.0;
41        final += (depths.x > shadowUV.z) ? 1.0 : 0.0;
42        final += (depths.y > shadowUV.z) ? 1.0 : 0.0;
43        final += (depths.z > shadowUV.z) ? 1.0 : 0.0;
44        final += (depths.w > shadowUV.z) ? 1.0 : 0.0;
45       
46        final *= 0.2;
47
48        gl_FragColor = vec4(outColor.xyz * final, 1);
49       
50#else
51        gl_FragColor = (centerdepth > shadowUV.z) ? vec4(outColor.xyz,1) : vec4(0,0,0,1);
52#endif
53}
54
Note: See TracBrowser for help on using the repository browser.