Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can GLSL macro expansion do this?

Consider the following GLSL functions:

float Pow3 (const in float f) {
    return f * f * f;
}

float Pow4 (const in float f) {
    return f * f * f * f;
}

float Pow5 (const in float f) {
    return f * f * f * f * f;
}

... and so on. Is there a way to #define a GLSL macro that can generate n multiplications-of-f-by-itself at compile time, not using the built-in GLSL pow() function of course?

like image 501
metaleap Avatar asked Dec 20 '22 22:12

metaleap


1 Answers

GLSL preprocessor "equals" to the standard C preprocessor. Indeed, you can reach what you want with the following preprocessor definition:

#define POW(a, b) Pow ## b ## (a)

But pay attention, since the concatenation operator (##) is available only starting from GLSL 1.30. Indeed using previous GLSL versions this macro will generate a compiler error.

Still wondering why you don't use the pow function...

like image 174
Luca Avatar answered Jan 19 '23 08:01

Luca