Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: data/branches/Shader_HS18/programs/Example/GLSLES/DepthShadowmapNormalMapReceiverFp.glsles @ 12091

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

Updated programs and adjusted Material to work with GLSL>150

File size: 2.5 KB
Line 
1#version 100
2
3precision highp int;
4precision highp float;
5
6uniform float inverseShadowmapSize;
7uniform float fixedDepthBias;
8uniform float gradientClamp;
9uniform float gradientScaleBias;
10uniform float shadowFuzzyWidth;
11uniform vec4 lightColour;
12
13uniform sampler2D shadowMap;
14uniform sampler2D normalMap;
15
16varying vec3 tangentLightDir;
17varying vec4 vUv0;
18varying vec4 vUv1;
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
29        // get the new normal and diffuse values
30        vec3 normal = normalize(expand(texture2D(normalMap, vUv1.xy).xyz));
31        vec4 vertexColour = clamp(dot(normal, tangentLightDir), 0.0, 1.0) * vec4(0.590839, 0.36056, 0.13028, 1.0);
32        vec4 shadowUV = vUv0;
33        // point on shadowmap
34#if LINEAR_RANGE
35        shadowUV.xy = shadowUV.xy / shadowUV.w;
36#else
37        shadowUV = shadowUV / shadowUV.w;
38#endif
39        float centerdepth = texture2D(shadowMap, shadowUV.xy).x;
40   
41    // gradient calculation
42        float pixeloffset = inverseShadowmapSize;
43    vec4 depths = vec4(
44        texture2D(shadowMap, shadowUV.xy + vec2(-pixeloffset, 0.0)).x,
45        texture2D(shadowMap, shadowUV.xy + vec2(+pixeloffset, 0.0)).x,
46        texture2D(shadowMap, shadowUV.xy + vec2(0.0, -pixeloffset)).x,
47        texture2D(shadowMap, shadowUV.xy + vec2(0.0, +pixeloffset)).x);
48
49        vec2 differences = abs( depths.yw - depths.xz );
50        float gradient = min(gradientClamp, max(differences.x, differences.y));
51        float gradientFactor = gradient * gradientScaleBias;
52
53        // visibility function
54        float depthAdjust = gradientFactor + (fixedDepthBias * centerdepth);
55        float finalCenterDepth = centerdepth + depthAdjust;
56
57        // shadowUV.z contains lightspace position of current object
58
59#if FUZZY_TEST
60        // fuzzy test - introduces some ghosting in result and doesn't appear to be needed?
61        //float visibility = saturate(1 + delta_z / (gradient * shadowFuzzyWidth));
62        float visibility = saturate(1.0 + (finalCenterDepth - shadowUV.z) * shadowFuzzyWidth * shadowUV.w);
63
64        gl_FragColor = vertexColour * visibility;
65#else
66        // hard test
67#if PCF
68        // use depths from prev, calculate diff
69        depths += depthAdjust;
70        float final = (finalCenterDepth > shadowUV.z) ? 1.0 : 0.0;
71        final += (depths.x > shadowUV.z) ? 1.0 : 0.0;
72        final += (depths.y > shadowUV.z) ? 1.0 : 0.0;
73        final += (depths.z > shadowUV.z) ? 1.0 : 0.0;
74        final += (depths.w > shadowUV.z) ? 1.0 : 0.0;
75       
76        final *= 0.2;
77
78        gl_FragColor = vec4(vertexColour.xyz * final, 1.0);
79       
80#else
81        gl_FragColor = (finalCenterDepth > shadowUV.z) ? vertexColour : vec4(0.0, 0.0, 0.0, 1.0);
82#endif
83
84#endif
85        gl_FragColor = vec4(1.0,0.0,1.0, 1.0);
86   
87}
Note: See TracBrowser for help on using the repository browser.