Skip to content

Commit 9773552

Browse files
committed
Emphasize the importance of mipmaps for textureLod() in Screen-reading shaders
This also mentions that reading the normal/roughness buffer is only currently supported in Forward+.
1 parent c1d8358 commit 9773552

File tree

4 files changed

+23
-10
lines changed

4 files changed

+23
-10
lines changed

tutorials/shaders/custom_postprocessing.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ Your scene tree will look something like this:
4040

4141
As of the time of writing, Godot does not support rendering to multiple
4242
buffers at the same time. Your post-processing shader will not have access
43-
to normals or other render passes. You only have access to the rendered
44-
frame.
43+
to other render passes and buffers not exposed by Godot (such as depth or
44+
normal/roughness). You only have access to the rendered frame and buffers
45+
exposed by Godot as samplers.
4546

4647
For this demo, we will use this :ref:`Sprite <class_Sprite2D>` of a sheep.
4748

@@ -60,6 +61,8 @@ shader by `arlez80 <https://bitbucket.org/arlez80/hex-mosaic/src/master/>`_,
6061
shader_type canvas_item;
6162
6263
uniform vec2 size = vec2(32.0, 28.0);
64+
// If you intend to read from mipmaps with `textureLod()` LOD values greater than `0.0`,
65+
// use `filter_nearest_mipmap` instead. This shader doesn't require it.
6366
uniform sampler2D screen_texture : hint_screen_texture, repeat_disable, filter_nearest;
6467
6568
void fragment() {

tutorials/shaders/screen-reading_shaders.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ the third argument to ``textureLod`` and change the hint ``filter_nearest`` to
4444
filter with mipmaps, Godot will automatically calculate the blurred texture for
4545
you.
4646

47+
.. warning::
48+
49+
If the filter mode is not changed to a filter mode that contains ``mipmap`` in its name,
50+
``textureLod`` with a LOD parameter greater than ``0.0`` will have the same appearance
51+
as with the ``0.0`` LOD parameter.
52+
4753
Screen texture example
4854
~~~~~~~~~~~~~~~~~~~~~~
4955

@@ -163,6 +169,11 @@ The following code retrieves the 3D position below the pixel being drawn:
163169
Normal-roughness texture
164170
~~~~~~~~~~~~~~~~~~~~~~~~
165171

172+
.. note::
173+
174+
Normal-roughness texture is only supported in the Forward+ rendering method,
175+
not Mobile or Compatibility.
176+
166177
Similarly, the normal-roughness texture can be used to read the normals and
167178
roughness of objects rendered in the depth prepass. The normal is stored in the
168179
``.xyz`` channels (mapped to the 0-1 range) while the roughness is stored in the

tutorials/shaders/shader_reference/shading_language.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ Full list of hints below:
797797
+----------------------+--------------------------------------------------+-----------------------------------------------------------------------------+
798798
| **sampler2D** | hint_depth_texture | Texture is the depth texture. |
799799
+----------------------+--------------------------------------------------+-----------------------------------------------------------------------------+
800-
| **sampler2D** | hint_normal_roughness_texture | Texture is the normal roughness texture. |
800+
| **sampler2D** | hint_normal_roughness_texture | Texture is the normal roughness texture (only supported in Forward+). |
801801
+----------------------+--------------------------------------------------+-----------------------------------------------------------------------------+
802802

803803
GDScript uses different variable types than GLSL does, so when passing variables
@@ -1285,8 +1285,8 @@ is used, it can be scalar or vector.
12851285
| gvec4_type **textureLod** (gsampler2D s, vec2 p, float lod) | Perform a texture read at custom mipmap. |
12861286
| | |
12871287
| gvec4_type **textureLod** (gsampler2DArray s, vec3 p, float lod) | The LOD defines which mipmap level is used. An LOD value of ``0.0`` |
1288-
| | will use the full resolution texture. |
1289-
| gvec4_type **textureLod** (gsampler3D s, vec3 p, float lod) | |
1288+
| | will use the full resolution texture. If the texture lacks mipmaps, |
1289+
| gvec4_type **textureLod** (gsampler3D s, vec3 p, float lod) | all LOD values will act like ``0.0``. |
12901290
| | |
12911291
| vec4 **textureLod** (samplerCube s, vec3 p, float lod) | |
12921292
| | |
@@ -1295,8 +1295,8 @@ is used, it can be scalar or vector.
12951295
| gvec4_type **textureProjLod** (gsampler2D s, vec3 p, float lod) | Performs a texture read with projection/LOD. |
12961296
| | |
12971297
| gvec4_type **textureProjLod** (gsampler2D s, vec4 p, float lod) | The LOD defines which mipmap level is used. An LOD value of ``0.0`` |
1298-
| | will use the full resolution texture. |
1299-
| gvec4_type **textureProjLod** (gsampler3D s, vec4 p, float lod) | |
1298+
| | will use the full resolution texture. If the texture lacks mipmaps, |
1299+
| gvec4_type **textureProjLod** (gsampler3D s, vec4 p, float lod) | all LOD values will act like ``0.0``. |
13001300
+-----------------------------------------------------------------------------+---------------------------------------------------------------------+
13011301
| gvec4_type **textureGrad** (gsampler2D s, vec2 p, vec2 dPdx, | Performs a texture read with explicit gradients. |
13021302
| vec2 dPdy) | |

tutorials/shaders/shaders_style_guide.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,13 @@ Here is a complete shader example based on these guidelines:
3030
shader_type canvas_item;
3131
// Screen-space shader to adjust a 2D scene's brightness, contrast
3232
// and saturation. Taken from
33-
// https://github.com/godotengine/godot-demo-projects/blob/master/2d/screen_space_shaders/shaders/BCS.shader
33+
// https://github.com/godotengine/godot-demo-projects/blob/master/2d/screen_space_shaders/shaders/BCS.gdshader
3434
35+
uniform sampler2D screen_texture : hint_screen_texture, filter_linear_mipmap;
3536
uniform float brightness = 0.8;
3637
uniform float contrast = 1.5;
3738
uniform float saturation = 1.8;
3839
39-
uniform sampler2D screen_texture : hint_screen_texture, repeat_disable, filter_nearest;
40-
4140
void fragment() {
4241
vec3 c = textureLod(screen_texture, SCREEN_UV, 0.0).rgb;
4342

0 commit comments

Comments
 (0)