Forráskód Böngészése

Example of a light shader (#2260)

ludorverr 6 éve
szülő
commit
57ce0a7051
1 módosított fájl, 12 hozzáadás és 2 törlés
  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
 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.
 
 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                                 |