Debian Codegraph @

src/scene/glsl/generated-pascal/shadow_map_common.fs.inc

raw
1 { -*- buffer-read-only: t -*- }
2 { DON'T EDIT -- this file was automatically generated from "source/shadow_map_common.fs" }
3 '/* Shadow map functions. */' + LineEnding +
4 '' + LineEnding +
5 '/* Define exactly one of PCF* symbols, or none (to not use any PCF).' + LineEnding +
6 ' This is defined (or not) when including this shader in Pascal code,' + LineEnding +
7 ' automatically. */' + LineEnding +
8 '//#define PCF4' + LineEnding +
9 '//#define PCF4_BILINEAR' + LineEnding +
10 '//#define PCF16' + LineEnding +
11 '' + LineEnding +
12 'float castleShadow2D(sampler2DShadow shadowMap, const vec3 shadowMapCoord)' + LineEnding +
13 '{' + LineEnding +
14 ' /* On OpenGLES, we require GLSL "300 es" that allows (and requires) to query' + LineEnding +
15 ' sampler2DShadow using texture*, not shadow2D* functions.' + LineEnding +
16 ' See https://stackoverflow.com/a/22426507' + LineEnding +
17 ' https://www.khronos.org/opengl/wiki/Sampler_(GLSL)' + LineEnding +
18 '' + LineEnding +
19 ' Modern GLSL (from #version 140) also requires it.' + LineEnding +
20 ' */' + LineEnding +
21 ' #ifdef CASTLE_GLSL_VERSION_UPGRADE' + LineEnding +
22 ' return texture(shadowMap, shadowMapCoord);' + LineEnding +
23 ' #else' + LineEnding +
24 ' return shadow2D(shadowMap, shadowMapCoord).r;' + LineEnding +
25 ' #endif' + LineEnding +
26 '}' + LineEnding +
27 '' + LineEnding +
28 'float castleShadow2DProj(sampler2DShadow shadowMap, const vec4 shadowMapCoord)' + LineEnding +
29 '{' + LineEnding +
30 ' #ifdef CASTLE_GLSL_VERSION_UPGRADE' + LineEnding +
31 ' return textureProj(shadowMap, shadowMapCoord);' + LineEnding +
32 ' #else' + LineEnding +
33 ' return shadow2DProj(shadowMap, shadowMapCoord).r;' + LineEnding +
34 ' #endif' + LineEnding +
35 '}' + LineEnding +
36 '' + LineEnding +
37 'float shadow(sampler2DShadow shadowMap, const vec4 shadowMapCoord,' + LineEnding +
38 ' const in float size)' + LineEnding +
39 '{' + LineEnding +
40 ' /* Avoid back-projecting shadows. */' + LineEnding +
41 ' if (shadowMapCoord.z < 0.0) return 0.0;' + LineEnding +
42 '' + LineEnding +
43 ' /* When coord2 is outside (0, 0) - (1, 1) square, it''s never in the shadow.' + LineEnding +
44 ' This makes sense, see' + LineEnding +
45 ' https://github.com/castle-engine/castle-engine/issues/308' + LineEnding +
46 ' and demo-models/shadow_maps/explicit_projection_parameters/' + LineEnding +
47 ' */' + LineEnding +
48 ' vec2 coord2 = shadowMapCoord.st / shadowMapCoord.q;' + LineEnding +
49 ' if (coord2.s < 0.0 || coord2.s > 1.0 ||' + LineEnding +
50 ' coord2.t < 0.0 || coord2.t > 1.0)' + LineEnding +
51 ' return 1.0;' + LineEnding +
52 '' + LineEnding +
53 '#ifdef PCF4_BILINEAR' + LineEnding +
54 '' + LineEnding +
55 ' /* We have to scale up/down by texture size to make the floor/fract' + LineEnding +
56 ' perform real bilinear filtering.' + LineEnding +
57 ' This also means that we have to handle xy and z separately. */' + LineEnding +
58 ' vec2 tc_full = size * coord2;' + LineEnding +
59 ' float z = shadowMapCoord.z / shadowMapCoord.w;' + LineEnding +
60 '' + LineEnding +
61 ' vec2 tc = floor(tc_full.xy);' + LineEnding +
62 ' vec2 f = fract(tc_full.xy);' + LineEnding +
63 ' vec2 f1 = vec2(1.0, 1.0) - f;' + LineEnding +
64 '' + LineEnding +
65 ' return' + LineEnding +
66 ' castleShadow2D(shadowMap, vec3( tc.x / size, tc.y / size, z)) * f1.x * f1.y +' + LineEnding +
67 ' castleShadow2D(shadowMap, vec3( tc.x / size, (tc.y + 1.0) / size, z)) * f1.x * f.y +' + LineEnding +
68 ' castleShadow2D(shadowMap, vec3((tc.x + 1.0) / size, tc.y / size, z)) * f.x * f1.y +' + LineEnding +
69 ' castleShadow2D(shadowMap, vec3((tc.x + 1.0) / size, (tc.y + 1.0) / size, z)) * f.x * f.y;' + LineEnding +
70 '' + LineEnding +
71 '#elif defined(PCF4)' + LineEnding +
72 '' + LineEnding +
73 ' /* PCF with 2x2 kernel */' + LineEnding +
74 ' float offset = shadowMapCoord.w / size;' + LineEnding +
75 ' return (' + LineEnding +
76 ' castleShadow2DProj(shadowMap, shadowMapCoord + vec4(-offset, -offset, 0.0, 0.0)) +' + LineEnding +
77 ' castleShadow2DProj(shadowMap, shadowMapCoord + vec4(-offset, offset, 0.0, 0.0)) +' + LineEnding +
78 ' castleShadow2DProj(shadowMap, shadowMapCoord + vec4( offset, offset, 0.0, 0.0)) +' + LineEnding +
79 ' castleShadow2DProj(shadowMap, shadowMapCoord + vec4( offset, -offset, 0.0, 0.0))' + LineEnding +
80 ' ) / 4.0;' + LineEnding +
81 '' + LineEnding +
82 '#elif defined(PCF16)' + LineEnding +
83 '' + LineEnding +
84 ' float offset = shadowMapCoord.w / size;' + LineEnding +
85 ' return' + LineEnding +
86 ' (' + LineEnding +
87 ' castleShadow2DProj(shadowMap, shadowMapCoord + vec4(-offset * 1.5, -offset * 1.5, 0.0, 0.0)) +' + LineEnding +
88 ' castleShadow2DProj(shadowMap, shadowMapCoord + vec4(-offset * 1.5, -offset * 0.5, 0.0, 0.0)) +' + LineEnding +
89 ' castleShadow2DProj(shadowMap, shadowMapCoord + vec4(-offset * 0.5, -offset * 0.5, 0.0, 0.0)) +' + LineEnding +
90 ' castleShadow2DProj(shadowMap, shadowMapCoord + vec4(-offset * 0.5, -offset * 1.5, 0.0, 0.0)) +' + LineEnding +
91 '' + LineEnding +
92 ' castleShadow2DProj(shadowMap, shadowMapCoord + vec4(-offset * 1.5, offset * 1.5, 0.0, 0.0)) +' + LineEnding +
93 ' castleShadow2DProj(shadowMap, shadowMapCoord + vec4(-offset * 1.5, offset * 0.5, 0.0, 0.0)) +' + LineEnding +
94 ' castleShadow2DProj(shadowMap, shadowMapCoord + vec4(-offset * 0.5, offset * 0.5, 0.0, 0.0)) +' + LineEnding +
95 ' castleShadow2DProj(shadowMap, shadowMapCoord + vec4(-offset * 0.5, offset * 1.5, 0.0, 0.0)) +' + LineEnding +
96 '' + LineEnding +
97 ' castleShadow2DProj(shadowMap, shadowMapCoord + vec4( offset * 1.5, offset * 1.5, 0.0, 0.0)) +' + LineEnding +
98 ' castleShadow2DProj(shadowMap, shadowMapCoord + vec4( offset * 1.5, offset * 0.5, 0.0, 0.0)) +' + LineEnding +
99 ' castleShadow2DProj(shadowMap, shadowMapCoord + vec4( offset * 0.5, offset * 0.5, 0.0, 0.0)) +' + LineEnding +
100 ' castleShadow2DProj(shadowMap, shadowMapCoord + vec4( offset * 0.5, offset * 1.5, 0.0, 0.0)) +' + LineEnding +
101 '' + LineEnding +
102 ' castleShadow2DProj(shadowMap, shadowMapCoord + vec4( offset * 1.5, -offset * 1.5, 0.0, 0.0)) +' + LineEnding +
103 ' castleShadow2DProj(shadowMap, shadowMapCoord + vec4( offset * 1.5, -offset * 0.5, 0.0, 0.0)) +' + LineEnding +
104 ' castleShadow2DProj(shadowMap, shadowMapCoord + vec4( offset * 0.5, -offset * 0.5, 0.0, 0.0)) +' + LineEnding +
105 ' castleShadow2DProj(shadowMap, shadowMapCoord + vec4( offset * 0.5, -offset * 1.5, 0.0, 0.0))' + LineEnding +
106 ' )' + LineEnding +
107 ' / 16.0;' + LineEnding +
108 '#else' + LineEnding +
109 ' /* No PCF */' + LineEnding +
110 ' return castleShadow2DProj(shadowMap, shadowMapCoord);' + LineEnding +
111 '#endif' + LineEnding +
112 '' + LineEnding +
113 '}' + LineEnding +
114 ''