Преглед на файлове

Example of a light shader (#2260)

ludorverr преди 6 години
родител
ревизия
57ce0a7051
променени са 1 файла, в които са добавени 12 реда и са изтрити 2 реда
  1. 12 2
      tutorials/shading/shading_reference/spatial_shader.rst

+ 12 - 2
tutorials/shading/shading_reference/spatial_shader.rst

@@ -268,11 +268,21 @@ render_mode to ``unshaded``. If no light function is written, Godot will use the
 properties written to in the fragment function to calculate the lighting for you (subject to
 properties written to in the fragment function to calculate the lighting for you (subject to
 the render_mode).
 the render_mode).
 
 
-To write a light function, assign something to DIFFUSE_LIGHT or SPECULAR_LIGHT. Assigning nothing 
+To write a light function, assign something to ``DIFFUSE_LIGHT`` or ``SPECULAR_LIGHT``. Assigning nothing 
 means no light is processed.
 means no light is processed.
 
 
 The light function is called for every light in every pixel. It is called within a loop for
 The light function is called for every light in every pixel. It is called within a loop for
-each light type. 
+each light type.
+
+Below is an example of a custom light function using a Lambertian lighting model:
+
+.. code-block:: glsl
+
+    void light() {
+        DIFFUSE_LIGHT += dot(NORMAL, LIGHT) * ATTENUATION * ALBEDO;
+    }
+
+If you want the lights to add together, add the light contribution to ``DIFFUSE_LIGHT`` using ``+=``, rather than overwriting it.
 
 
 +-----------------------------------+---------------------------------------------+
 +-----------------------------------+---------------------------------------------+
 | Built-in                          | Description                                 |
 | Built-in                          | Description                                 |