Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: data/data_extern/programs/GLSL150/DepthShadowmapReceiverFp.glsl @ 12202

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

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

File size: 1.9 KB
Line 
1#version 150
2
3uniform float inverseShadowmapSize;
4uniform float fixedDepthBias;
5uniform float gradientClamp;
6uniform float gradientScaleBias;
7uniform float shadowFuzzyWidth;
8
9uniform sampler2D shadowMap;
10out vec4 fragColour;
11in vec4 shadowUV;
12in vec4 oColour;
13
14void main()
15{
16        float centerdepth = texture(shadowMap, shadowUV.xy).x;
17   
18    // gradient calculation
19        float pixeloffset = inverseShadowmapSize;
20    vec4 depths = vec4(
21        texture(shadowMap, shadowUV.xy + vec2(-pixeloffset, 0)).x,
22        texture(shadowMap, shadowUV.xy + vec2(+pixeloffset, 0)).x,
23        texture(shadowMap, shadowUV.xy + vec2(0, -pixeloffset)).x,
24        texture(shadowMap, shadowUV.xy + vec2(0, +pixeloffset)).x);
25
26        vec2 differences = abs( depths.yw - depths.xz );
27        float gradient = min(gradientClamp, max(differences.x, differences.y));
28        float gradientFactor = gradient * gradientScaleBias;
29
30        // visibility function
31        float depthAdjust = gradientFactor + (fixedDepthBias * centerdepth);
32        float finalCenterDepth = centerdepth + depthAdjust;
33
34        // shadowUV.z contains lightspace position of current object
35
36#if FUZZY_TEST
37        // fuzzy test - introduces some ghosting in result and doesn't appear to be needed?
38        //float visibility = saturate(1 + delta_z / (gradient * shadowFuzzyWidth));
39        float visibility = saturate(1 + (finalCenterDepth - shadowUV.z) * shadowFuzzyWidth * shadowUV.w);
40
41        fragColour = vertexColour * visibility;
42#else
43        // hard test
44#if PCF
45        // use depths from prev, calculate diff
46        depths += depthAdjust;
47        float final = (finalCenterDepth > shadowUV.z) ? 1.0 : 0.0;
48        final += (depths.x > shadowUV.z) ? 1.0 : 0.0;
49        final += (depths.y > shadowUV.z) ? 1.0 : 0.0;
50        final += (depths.z > shadowUV.z) ? 1.0 : 0.0;
51        final += (depths.w > shadowUV.z) ? 1.0 : 0.0;
52       
53        final *= 0.2;
54
55        fragColour = vec4(oColour.xyz * final, 1);
56       
57#else
58        fragColour = (finalCenterDepth > shadowUV.z) ? oColour : vec4(0.5,0,0,1);
59#endif
60
61#endif
62   
63}
64
Note: See TracBrowser for help on using the repository browser.