GLSL宏扩展能做到这一点吗?

met*_*eap 4 opengl macros shader glsl fragment-shader

考虑以下GLSL函数:

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;
}
Run Code Online (Sandbox Code Playgroud)

... 等等.有没有一种方法,以#定义一个宏GLSL可以产生ñ乘法-OF- ˚F逐本身在编译的时候,不使用内置GLSL POW()当然功能?

Luc*_*uca 7

GLSL预处理器"等于"标准C预处理器.实际上,您可以使用以下预处理器定义达到您想要的效果:

#define POW(a, b) Pow ## b ## (a)
Run Code Online (Sandbox Code Playgroud)

但要注意,因为连接运算符(##)仅从GLSL 1.30开始可用.确实使用以前的GLSL版本,此宏将生成编译器错误.

还在想你为什么不使用这个pow功能......

  • 对不起,伙计,没有前面。但双引号等于没有定义。我们不知道你的“等于”是什么意思。如果你的意思是“除了可变宏扩展之外的等于”,那么请写下来。我被答案误导,认为“__VA_ARGS__”实际上是可能的。 (2认同)