File tree Expand file tree Collapse file tree 1 file changed +17
-2
lines changed
tutorials/shaders/shader_reference Expand file tree Collapse file tree 1 file changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -47,15 +47,30 @@ General syntax
4747Defines the identifier after that directive as a macro, and replaces all
4848successive occurrences of it with the replacement code given in the shader.
4949Replacement is performed on a "whole words" basis, which means no replacement is
50- performed if the string is part of another string (without any spaces separating
51- it).
50+ performed if the string is part of another string (without any spaces or
51+ operators separating it).
5252
5353Defines with replacements may also have one or more *arguments *, which can then
5454be passed when referencing the define (similar to a function call).
5555
5656If the replacement code is not defined, the identifier may only be used with
5757``#ifdef `` or ``#ifndef `` directives.
5858
59+ If the *concatenation * symbol (``## ``) is present in the replacement code then
60+ it will be removed upon macro insertion, together with any space surrounding
61+ it, and join the surrounding words and arguments into a new token.
62+
63+ .. code-block :: glsl
64+
65+ uniform sampler2D material0;
66+
67+ #define SAMPLE(N) vec4 tex##N = texture(material##N, UV)
68+
69+ void fragment() {
70+ SAMPLE(0);
71+ ALBEDO = tex0.rgb;
72+ }
73+
5974 Compared to constants (``const CONSTANT = value; ``), ``#define `` can be used
6075anywhere within the shader (including in uniform hints).
6176``#define `` can also be used to insert arbitrary shader code at any location,
You can’t perform that action at this time.
0 commit comments