Skip to content

Commit 17e6a5f

Browse files
Calinoumhilbrunner
andauthored
Mention function overloading not being supported in Shading language (#6940)
* Mention function overloading not being supported in Shading language This also adds a performance note for `discard`. --------- Co-authored-by: Max Hilbrunner <[email protected]>
1 parent b2f204c commit 17e6a5f

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

tutorials/shaders/shader_reference/shading_language.rst

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ behave differently depending on the hardware.
535535
}
536536
537537
Instead, always perform a range comparison with an epsilon value. The larger the
538-
floating-point number (and the less precise the floating-point number, the
538+
floating-point number (and the less precise the floating-point number), the
539539
larger the epsilon value should be.
540540

541541
.. code-block:: glsl
@@ -551,9 +551,15 @@ information.
551551
Discarding
552552
----------
553553

554-
Fragment and light functions can use the **discard** keyword. If used, the
554+
Fragment and light functions can use the ``discard`` keyword. If used, the
555555
fragment is discarded and nothing is written.
556556

557+
Beware that ``discard`` has a performance cost when used, as it will prevent the
558+
depth prepass from being effective on any surfaces using the shader. Also, a
559+
discarded pixel still needs to be rendered in the vertex shader, which means a
560+
shader that uses ``discard`` on all of its pixels is still more expensive to
561+
render compared to not rendering any object in the first place.
562+
557563
Functions
558564
---------
559565

@@ -574,7 +580,8 @@ syntax:
574580
575581
576582
You can only use functions that have been defined above (higher in the editor)
577-
the function from which you are calling them.
583+
the function from which you are calling them. Redefining a function that has
584+
already been defined above (or is a built-in function name) will cause an error.
578585

579586
Function arguments can have special qualifiers:
580587

@@ -592,6 +599,14 @@ Example below:
592599
result = a + b;
593600
}
594601
602+
.. note::
603+
604+
Unlike GLSL, Godot's shader language does **not** support function
605+
overloading. This means that a function cannot be defined several times with
606+
different argument types or numbers of arguments. As a workaround, use
607+
different names for functions that accept a different number of arguments or
608+
arguments of different types.
609+
595610
Varyings
596611
--------
597612

0 commit comments

Comments
 (0)