From e4d395de4885af4b85d40ed0d0827fc8b928324f Mon Sep 17 00:00:00 2001 From: tetrapod00 <145553014+tetrapod00@users.noreply.github.com> Date: Thu, 24 Oct 2024 23:58:50 -0700 Subject: [PATCH] Note limitation of shader world coordinates with large world coordinates --- tutorials/physics/large_world_coordinates.rst | 17 +++++++++++++++++ .../shader_reference/shading_language.rst | 1 + 2 files changed, 18 insertions(+) diff --git a/tutorials/physics/large_world_coordinates.rst b/tutorials/physics/large_world_coordinates.rst index b09b080fb..1550da1ce 100644 --- a/tutorials/physics/large_world_coordinates.rst +++ b/tutorials/physics/large_world_coordinates.rst @@ -229,6 +229,23 @@ some limitations when it comes to 3D rendering precision: - :ref:`Triplanar mapping ` doesn't benefit from increased precision. Materials using triplanar mapping will exhibit visible jittering when far away from the world origin. +- In double-precision builds, world space coordinates in a shader ``fragment()`` + function can't be reconstructed from view space, for example: + + .. code-block:: glsl + + vec3 world = (INV_VIEW_MATRIX * vec4(VERTEX, 1.0)).xyz; + + Instead, calculate the world space coordinates in the ``vertex()`` function and + pass them using a :ref:`varying`, for example: + + .. code-block:: glsl + + varying vec3 world; + void vertex() { + world = (MODEL_MATRIX * vec4(VERTEX, 1.0)).xyz; + } + 2D rendering currently doesn't benefit from increased precision when large world coordinates are enabled. This can cause visible model snapping to occur when diff --git a/tutorials/shaders/shader_reference/shading_language.rst b/tutorials/shaders/shader_reference/shading_language.rst index 793bb06fd..8113e749a 100644 --- a/tutorials/shaders/shader_reference/shading_language.rst +++ b/tutorials/shaders/shader_reference/shading_language.rst @@ -662,6 +662,7 @@ function calls is not allowed, such as from ``int`` to ``float`` (``1`` to ``1.0 vec3 green = get_color(1.0); } +.. _doc_shading_language_varyings: Varyings --------