Skip to content
0.2.0-dev Download ZIP
68 lines ·1.4 KB Raw
1/* clang-format off */
2#[modes]
3
4mode_sdf =
5mode_shadow = #define MODE_SHADOW
6mode_shadow_RGBA = #define MODE_SHADOW \n#define USE_RGBA_SHADOWS
7
8#[specializations]
9
10#[vertex]
11
12layout(location = 0) in vec3 vertex;
13
14uniform highp mat4 projection;
15uniform highp vec4 modelview1;
16uniform highp vec4 modelview2;
17uniform highp vec2 direction;
18uniform highp float z_far;
19
20#ifdef MODE_SHADOW
21out float depth;
22#endif
23
24void main() {
25 highp vec4 vtx = vec4(vertex, 1.0) * mat4(modelview1, modelview2, vec4(0.0, 0.0, 1.0, 0.0), vec4(0.0, 0.0, 0.0, 1.0));
26
27#ifdef MODE_SHADOW
28 depth = dot(direction, vtx.xy);
29#endif
30 gl_Position = projection * vtx;
31}
32
33#[fragment]
34
35
36uniform highp mat4 projection;
37uniform highp vec4 modelview1;
38uniform highp vec4 modelview2;
39uniform highp vec2 direction;
40uniform highp float z_far;
41
42#ifdef MODE_SHADOW
43in highp float depth;
44#endif
45
46#ifdef USE_RGBA_SHADOWS
47layout(location = 0) out lowp vec4 out_buf;
48#else
49layout(location = 0) out highp float out_buf;
50#endif
51
52void main() {
53 float out_depth = 1.0;
54
55#ifdef MODE_SHADOW
56 out_depth = depth / z_far;
57#endif
58
59#ifdef USE_RGBA_SHADOWS
60 out_depth = clamp(out_depth, -1.0, 1.0);
61 out_depth = out_depth * 0.5 + 0.5;
62 highp vec4 comp = fract(out_depth * vec4(255.0 * 255.0 * 255.0, 255.0 * 255.0, 255.0, 1.0));
63 comp -= comp.xxyz * vec4(0.0, 1.0 / 255.0, 1.0 / 255.0, 1.0 / 255.0);
64 out_buf = comp;
65#else
66 out_buf = out_depth;
67#endif
68}