Can the GLSL macro extension 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;
}

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

+3
source share
1 answer

The GLSL preprocessor is β€œequal” to the standard C preprocessors. Indeed, you can achieve what you want with the following preprocessor definition:

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

But note, since the concatenation operator ( ##) is only available with GLSL 1.30. In fact, using previous versions of GLSL, this macro will generate a compiler error.

Still wondering why you are not using the function pow...

+6
source

All Articles