2
0
Эх сурвалжийг харах

Merge pull request #10244 from tetrapod00/advanced-postprocess-ndc

Add multiple renderer support to Advanced Postprocessing
Max Hilbrunner 8 сар өмнө
parent
commit
96fe4d15df

+ 22 - 4
tutorials/shaders/advanced_postprocessing.rst

@@ -108,10 +108,6 @@ from ``0.0`` to ``1.0`` in the ``z`` direction when using the Vulkan backend.
 Reconstruct the NDC using ``SCREEN_UV`` for the ``x`` and ``y`` axis, and
 Reconstruct the NDC using ``SCREEN_UV`` for the ``x`` and ``y`` axis, and
 the depth value for ``z``.
 the depth value for ``z``.
 
 
-.. note::
-
-    This tutorial assumes the use of the Vulkan renderer, which uses NDCs with a Z-range
-    of ``[0.0, 1.0]``. In contrast, OpenGL uses NDCs with a Z-range of ``[-1.0, 1.0]``.
 
 
 .. code-block:: glsl
 .. code-block:: glsl
 
 
@@ -120,6 +116,28 @@ the depth value for ``z``.
     vec3 ndc = vec3(SCREEN_UV * 2.0 - 1.0, depth);
     vec3 ndc = vec3(SCREEN_UV * 2.0 - 1.0, depth);
   }
   }
 
 
+.. note::
+
+  This tutorial assumes the use of the Forward+ or Mobile renderers, which both
+  use Vulkan NDCs with a Z-range of ``[0.0, 1.0]``. In contrast, the Compatibility
+  renderer uses OpenGL NDCs with a Z-range of ``[-1.0, 1.0]``. For the Compatibility
+  renderer, replace the NDC calculation with this instead:
+  
+  .. code-block:: glsl
+
+    vec3 ndc = vec3(SCREEN_UV, depth) * 2.0 - 1.0;
+
+  You can also use the ``CURRENT_RENDERER`` and ``RENDERER_COMPATIBILITY``
+  built-in defines for a shader that will work in all renderers:
+
+  .. code-block:: glsl
+
+    #if CURRENT_RENDERER == RENDERER_COMPATIBILITY
+    vec3 ndc = vec3(SCREEN_UV, depth) * 2.0 - 1.0;
+    #else
+    vec3 ndc = vec3(SCREEN_UV * 2.0 - 1.0, depth);
+    #endif
+
 Convert NDC to view space by multiplying the NDC by ``INV_PROJECTION_MATRIX``.
 Convert NDC to view space by multiplying the NDC by ``INV_PROJECTION_MATRIX``.
 Recall that view space gives positions relative to the camera, so the ``z`` value will give us
 Recall that view space gives positions relative to the camera, so the ``z`` value will give us
 the distance to the point.
 the distance to the point.