| 1 |
/* clang-format off */ |
| 2 |
#[modes] |
| 3 |
|
| 4 |
mode_sdf = |
| 5 |
mode_shadow = #define MODE_SHADOW |
| 6 |
mode_shadow_RGBA = #define MODE_SHADOW \n#define USE_RGBA_SHADOWS |
| 7 |
|
| 8 |
#[specializations] |
| 9 |
|
| 10 |
#[vertex] |
| 11 |
|
| 12 |
layout(location = 0) in vec3 vertex; |
| 13 |
|
| 14 |
uniform highp mat4 projection; |
| 15 |
uniform highp vec4 modelview1; |
| 16 |
uniform highp vec4 modelview2; |
| 17 |
uniform highp vec2 direction; |
| 18 |
uniform highp float z_far; |
| 19 |
|
| 20 |
#ifdef MODE_SHADOW |
| 21 |
out float depth; |
| 22 |
#endif |
| 23 |
|
| 24 |
void 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 |
|
| 36 |
uniform highp mat4 projection; |
| 37 |
uniform highp vec4 modelview1; |
| 38 |
uniform highp vec4 modelview2; |
| 39 |
uniform highp vec2 direction; |
| 40 |
uniform highp float z_far; |
| 41 |
|
| 42 |
#ifdef MODE_SHADOW |
| 43 |
in highp float depth; |
| 44 |
#endif |
| 45 |
|
| 46 |
#ifdef USE_RGBA_SHADOWS |
| 47 |
layout(location = 0) out lowp vec4 out_buf; |
| 48 |
#else |
| 49 |
layout(location = 0) out highp float out_buf; |
| 50 |
#endif |
| 51 |
|
| 52 |
void 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 |
} |