2018-08-27 07:31:48 +02:00
|
|
|
/* clang-format off */
|
2016-12-04 16:45:30 +01:00
|
|
|
[vertex]
|
|
|
|
|
2018-08-24 13:42:18 +02:00
|
|
|
layout(location = 0) in highp vec4 vertex_attrib;
|
2018-08-27 07:31:48 +02:00
|
|
|
/* clang-format on */
|
2016-12-04 16:45:30 +01:00
|
|
|
|
|
|
|
void main() {
|
|
|
|
|
|
|
|
gl_Position = vertex_attrib;
|
|
|
|
}
|
|
|
|
|
2018-08-27 07:31:48 +02:00
|
|
|
/* clang-format off */
|
2016-12-04 16:45:30 +01:00
|
|
|
[fragment]
|
|
|
|
|
|
|
|
#ifdef MINIFY_START
|
|
|
|
|
|
|
|
#define SDEPTH_TYPE highp sampler2D
|
|
|
|
uniform float camera_z_far;
|
2018-08-27 07:31:48 +02:00
|
|
|
/* clang-format on */
|
2016-12-04 16:45:30 +01:00
|
|
|
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);
|
|
|
|
|
2018-08-24 13:42:18 +02:00
|
|
|
// 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
|
2016-12-04 16:45:30 +01:00
|
|
|
|
|
|
|
#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;
|
2017-09-08 01:16:33 +02:00
|
|
|
#ifdef USE_ORTHOGONAL_PROJECTION
|
2018-08-24 13:42:18 +02:00
|
|
|
fdepth = ((fdepth + (camera_z_far + camera_z_near) / (camera_z_far - camera_z_near)) * (camera_z_far - camera_z_near)) / 2.0;
|
2017-09-08 01:16:33 +02:00
|
|
|
#else
|
2016-12-04 16:45:30 +01:00
|
|
|
fdepth = 2.0 * camera_z_near * camera_z_far / (camera_z_far + camera_z_near - fdepth * (camera_z_far - camera_z_near));
|
2017-09-08 01:16:33 +02:00
|
|
|
#endif
|
2016-12-04 16:45:30 +01:00
|
|
|
fdepth /= camera_z_far;
|
2018-08-24 13:42:18 +02:00
|
|
|
depth = uint(clamp(fdepth * 65535.0, 0.0, 65535.0));
|
2016-12-04 16:45:30 +01:00
|
|
|
|
|
|
|
#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
|
|
|
|
}
|