Skip to content

Commit d2e0797

Browse files
authored
Merge pull request #10084 from Chaosus/shader_func_overloading
Fix shader function overloading paragraph
2 parents 41f1124 + c3feaed commit d2e0797

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

tutorials/shaders/shader_reference/shading_language.rst

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -637,13 +637,23 @@ Example below:
637637
result = a + b;
638638
}
639639
640-
.. note::
640+
Function overloading is supported. You can define multiple functions with the same
641+
name, but different arguments. Note that `implicit casting <Casting_>`_ in overloaded
642+
function calls is not allowed, such as from ``int`` to ``float`` (``1`` to ``1.0``).
643+
644+
.. code-block:: glsl
645+
646+
vec3 get_color(int t) {
647+
return vec3(1, 0, 0); // Red color.
648+
}
649+
vec3 get_color(float t) {
650+
return vec3(0, 1, 0); // Green color.
651+
}
652+
void fragment() {
653+
vec3 red = get_color(1);
654+
vec3 green = get_color(1.0);
655+
}
641656
642-
Unlike GLSL, Godot's shader language does **not** support function
643-
overloading. This means that a function cannot be defined several times with
644-
different argument types or numbers of arguments. As a workaround, use
645-
different names for functions that accept a different number of arguments or
646-
arguments of different types.
647657
648658
Varyings
649659
--------

0 commit comments

Comments
 (0)