From 689cc55682969e1a366cbb1cb56f955b281e9ba9 Mon Sep 17 00:00:00 2001 From: Sam Freed Date: Wed, 21 Aug 2024 16:40:58 -0700 Subject: [PATCH] Fix out of date comment about depth buffer --- tutorials/shaders/advanced_postprocessing.rst | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tutorials/shaders/advanced_postprocessing.rst b/tutorials/shaders/advanced_postprocessing.rst index d562e8fd790..8c900b7cecd 100644 --- a/tutorials/shaders/advanced_postprocessing.rst +++ b/tutorials/shaders/advanced_postprocessing.rst @@ -93,11 +93,10 @@ Once defined, the depth texture can be read with the ``texture()`` function. possible when reading from the current viewport. The depth texture cannot be accessed from another viewport to which you have rendered. -The values returned by ``depth_texture`` are between ``0.0`` and ``1.0`` and are nonlinear. +The values returned by ``depth_texture`` are between ``1.0`` and ``0.0`` (corresponding to +the near and far plane, respectively, because of using a "reverse-z" depth buffer) and are nonlinear. When displaying depth directly from the ``depth_texture``, everything will look almost -white unless it is very close. This is because the depth buffer stores objects closer -to the camera using more bits than those further, so most of the detail in depth -buffer is found close to the camera. In order to make the depth value align with world or +black unless it is very close due to that nonlinearity. In order to make the depth value align with world or model coordinates, we need to linearize the value. When we apply the projection matrix to the vertex position, the z value is made nonlinear, so to linearize it, we multiply it by the inverse of the projection matrix, which in Godot, is accessible with the variable