1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
[require]
GLSL >= 3.30
[fragment shader]
#version 330
#define GLES_OVER_GL
#define MINIFY_START
precision highp float;
precision highp int;
#ifdef MINIFY_START
#define SDEPTH_TYPE highp sampler2D
uniform float camera_z_far;
/* clang-format on */
uniform float camera_z_near;
#else
#define SDEPTH_TYPE mediump usampler2D
#endif
uniform SDEPTH_TYPE source_depth; //texunit:0
uniform ivec2 from_size;
uniform int source_mipmap;
layout(location = 0) out mediump uint depth;
void main() {
ivec2 ssP = ivec2(gl_FragCoord.xy);
// Rotated grid subsampling to avoid XY directional bias or Z precision bias while downsampling.
// On DX9, the bit-and can be implemented with floating-point modulo
#ifdef MINIFY_START
float fdepth = texelFetch(source_depth, clamp(ssP * 2 + ivec2(ssP.y & 1, ssP.x & 1), ivec2(0), from_size - ivec2(1)), source_mipmap).r;
fdepth = fdepth * 2.0 - 1.0;
#ifdef USE_ORTHOGONAL_PROJECTION
fdepth = ((fdepth + (camera_z_far + camera_z_near) / (camera_z_far - camera_z_near)) * (camera_z_far - camera_z_near)) / 2.0;
#else
fdepth = 2.0 * camera_z_near * camera_z_far / (camera_z_far + camera_z_near - fdepth * (camera_z_far - camera_z_near));
#endif
fdepth /= camera_z_far;
depth = uint(clamp(fdepth * 65535.0, 0.0, 65535.0));
#else
depth = texelFetch(source_depth, clamp(ssP * 2 + ivec2(ssP.y & 1, ssP.x & 1), ivec2(0), from_size - ivec2(1)), source_mipmap).r;
#endif
}
[vertex shader]
#version 330
#define GLES_OVER_GL
#define MINIFY_START
precision highp float;
precision highp int;
layout(location = 0) in highp vec4 vertex_attrib;
/* clang-format on */
void main() {
gl_Position = vertex_attrib;
}
/* clang-format off */
|