Browse Source

Example of a light shader (#2260)

(cherry picked from commit 57ce0a7051309e6f6d57f44a92183e7e9d92ab70)
ludorverr 6 years ago
parent
commit
5e73877627
1 changed files with 12 additions and 2 deletions
  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                                 |