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?
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...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With