不能在 WebGL GLSL 着色器常量 #if 表达式中使用浮点数?
Can't use floats in WebGL GLSL shader constant #if expression?
在 WebGL GLSL 中,我试图做类似的事情:
#if (2.0 > 3.0)
// something
#endif
但是这个错误是:
ERROR: 0:21: 'syntax error' : invalid expression
ERROR: 0:21: '2.0' : unexpected token after conditional expression
A constant expression is one of
• a literal value (e.g., 5 or true)
浮点数不是文字值吗?
同样,我也不确定为什么这不起作用,因为它是一个 const
变量,对值使用常量表达式:
const vec3 x = vec3(1.0);
...
#if (x.x > 1.0)
#endif
ERROR: 0:21: 'x' : unexpected token after conditional expression
ERROR: 0:21: 'syntax error' : invalid expression
ERROR: 0:21: '.' : unexpected token after conditional expression
啊,在预处理器部分的同一文档中,它说:
Expressions following #if and #elif are restricted to expressions operating on literal integer constants, plus identifiers consumed by the defined operator.
这就是浮动、length()
等不起作用的原因。
在 WebGL GLSL 中,我试图做类似的事情:
#if (2.0 > 3.0)
// something
#endif
但是这个错误是:
ERROR: 0:21: 'syntax error' : invalid expression ERROR: 0:21: '2.0' : unexpected token after conditional expression
A constant expression is one of
• a literal value (e.g., 5 or true)
浮点数不是文字值吗?
同样,我也不确定为什么这不起作用,因为它是一个 const
变量,对值使用常量表达式:
const vec3 x = vec3(1.0);
...
#if (x.x > 1.0)
#endif
ERROR: 0:21: 'x' : unexpected token after conditional expression
ERROR: 0:21: 'syntax error' : invalid expression
ERROR: 0:21: '.' : unexpected token after conditional expression
啊,在预处理器部分的同一文档中,它说:
Expressions following #if and #elif are restricted to expressions operating on literal integer constants, plus identifiers consumed by the defined operator.
这就是浮动、length()
等不起作用的原因。