Skip to content

Commit e6dbfe1

Browse files
authored
Merge pull request godotengine#7236 from Piralein/shader🧙‍♂️
Your first 3D shader - update outdated images and information
2 parents 3bc758d + 9dc3996 commit e6dbfe1

File tree

9 files changed

+22
-17
lines changed

9 files changed

+22
-17
lines changed
-10.1 KB
Binary file not shown.
11.1 KB
Loading
-7.97 KB
Binary file not shown.
27.1 KB
Loading
-5.29 KB
Binary file not shown.
11.2 KB
Loading
29.5 KB
Loading
-22.8 KB
Binary file not shown.

‎tutorials/shaders/your_first_shader/your_first_3d_shader.rst‎

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ This will allow you to see the triangles making up the plane.
7676

7777
.. image:: img/plane.png
7878

79-
Now set ``Subdivide Width`` and ``Subdivide Depth`` to ``32``.
79+
Now set ``Subdivide Width`` and ``Subdivide Depth`` of the :ref:`PlaneMesh <class_planemesh>` to ``32``.
8080

81-
.. image:: img/plane-sub-set.png
81+
.. image:: img/plane-sub-set.webp
8282

8383
You can see that there are now many more triangles in the
8484
:ref:`MeshInstance3D<class_MeshInstance3D>`. This will give us more vertices to work with
@@ -99,18 +99,21 @@ first Spatial shader!
9999
Shader magic
100100
------------
101101

102-
.. image:: img/shader-error.png
102+
.. image:: img/shader-editor.webp
103103

104-
Notice how there is already error? This is because the shader editor reloads
105-
shaders on the fly. The first thing Godot shaders need is a declaration of what
106-
type of shader they are. We set the variable ``shader_type`` to ``spatial``
104+
The new shader is already generated with a ``shader_type``
105+
variable and the ``fragment()`` function.
106+
The first thing Godot shaders need is a declaration
107+
of what type of shader they are.
108+
In this case the ``shader_type`` is set to ``spatial``
107109
because this is a spatial shader.
108110

109111
.. code-block:: glsl
110112
111113
shader_type spatial;
112114
113-
Next we will define the ``vertex()`` function. The ``vertex()`` function
115+
For now ignore the ``fragment()`` function
116+
and define the ``vertex()`` function. The ``vertex()`` function
114117
determines where the vertices of your :ref:`MeshInstance3D<class_MeshInstance3D>` appear in
115118
the final scene. We will be using it to offset the height of each vertex and
116119
make our flat plane appear like a little terrain.
@@ -177,16 +180,16 @@ This will allow you to send a noise texture to the shader. Now look in the
177180
inspector under your material. You should see a section called "Shader Params".
178181
If you open it up, you'll see a section called "noise".
179182

180-
Click beside it where it says "[empty]" and select "New NoiseTexture". Then in
181-
your NoiseTexture click beside where it says "Noise" and select "New
182-
NoiseTexture".
183+
Click beside it where it says "[empty]" and select "New NoiseTexture2D". Then in
184+
your :ref:`NoiseTexture2D <class_noisetexture2D>` click beside where it says "Noise" and select "New
185+
FastNoiseLite".
183186

184-
.. note:: :ref:`FastNoiseLite <class_fastnoiselite>` is used by the NoiseTexture to
187+
.. note:: :ref:`FastNoiseLite <class_fastnoiselite>` is used by the NoiseTexture2D to
185188
generate a heightmap.
186189

187190
Once you set it up and should look like this.
188191

189-
.. image:: img/noise-set.png
192+
.. image:: img/noise-set.webp
190193

191194
Now, access the noise texture using the ``texture()`` function. ``texture()``
192195
takes a texture as the first argument and a ``vec2`` for the position on the
@@ -201,8 +204,10 @@ this case we'll use the ``r``, or ``x`` channel.
201204

202205
.. code-block:: glsl
203206
204-
float height = texture(noise, VERTEX.xz / 2.0 + 0.5).x;
205-
VERTEX.y += height;
207+
void vertex() {
208+
float height = texture(noise, VERTEX.xz / 2.0 + 0.5).x;
209+
VERTEX.y += height;
210+
}
206211
207212
Note: ``xyzw`` is the same as ``rgba`` in GLSL, so instead of ``texture().x``
208213
above, we could use ``texture().r``. See the `OpenGL documentation
@@ -304,10 +309,10 @@ do that by passing in a second noise texture.
304309
305310
uniform sampler2D normalmap;
306311
307-
Set this second uniform texture to another NoiseTexture with another
308-
FastNoiseLite. But this time, check **As Normalmap**.
312+
Set this second uniform texture to another :ref:`NoiseTexture2D <class_noisetexture2D>` with another
313+
:ref:`FastNoiseLite <class_fastnoiselite>`. But this time, check **As Normalmap**.
309314

310-
.. image:: img/normal-set.png
315+
.. image:: img/normal-set.webp
311316

312317
Now, because this is a normalmap and not a per-vertex normal, we are going to
313318
assign it in the ``fragment()`` function. The ``fragment()`` function will be

0 commit comments

Comments
 (0)