Skip to content

Commit d3f86dc

Browse files
committed
Add concatenation to shader preprocessor
1 parent 05fe756 commit d3f86dc

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

tutorials/shaders/shader_reference/shader_preprocessor.rst

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,30 @@ General syntax
4747
Defines the identifier after that directive as a macro, and replaces all
4848
successive occurrences of it with the replacement code given in the shader.
4949
Replacement 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

5353
Defines with replacements may also have one or more *arguments*, which can then
5454
be passed when referencing the define (similar to a function call).
5555

5656
If 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
6075
anywhere within the shader (including in uniform hints).
6176
``#define`` can also be used to insert arbitrary shader code at any location,

0 commit comments

Comments
 (0)