summaryrefslogtreecommitdiff
path: root/drivers/gles2/shaders/ssao_minify.glsl
diff options
context:
space:
mode:
authorlawnjelly <lawnjelly@gmail.com>2020-11-18 18:11:30 +0000
committerHugo Locurcio <hugo.locurcio@hugo.pro>2021-10-30 02:05:48 +0200
commite3491a37445014cc3527d6f2c1467063222b2dd8 (patch)
tree7f8250aee66fbc382040f0c843a91a5f85238d45 /drivers/gles2/shaders/ssao_minify.glsl
parentd046817536a21358f9c51bf5b932d0a6615ee76a (diff)
Add GLES2 2D renderer + Linux display manager
First implementation with Linux display manager. - Add single-threaded mode for EditorResourcePreview (needed for OpenGL). Co-authored-by: clayjohn <claynjohn@gmail.com> Co-authored-by: Fabio Alessandrelli <fabio.alessandrelli@gmail.com>
Diffstat (limited to 'drivers/gles2/shaders/ssao_minify.glsl')
-rw-r--r--drivers/gles2/shaders/ssao_minify.glsl54
1 files changed, 54 insertions, 0 deletions
diff --git a/drivers/gles2/shaders/ssao_minify.glsl b/drivers/gles2/shaders/ssao_minify.glsl
new file mode 100644
index 0000000000..f654e00a4f
--- /dev/null
+++ b/drivers/gles2/shaders/ssao_minify.glsl
@@ -0,0 +1,54 @@
+/* clang-format off */
+[vertex]
+
+layout(location = 0) in highp vec4 vertex_attrib;
+/* clang-format on */
+
+void main() {
+ gl_Position = vertex_attrib;
+}
+
+/* clang-format off */
+[fragment]
+
+#ifdef MINIFY_START
+
+#define SDEPTH_TYPE highp sampler2D
+uniform float camera_z_far;
+uniform float camera_z_near;
+/* clang-format on */
+
+#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
+}