为什么 GLSL const bool 不起作用?

Why GLSL const bool doesn't works?

我有一个带 #version 130 的片段着色器,我有一个矢量:uniform vec3 sunPosition;

这很好用:

    bool isTheSunUp = sunPosition.y > 0;

但以下内容不符合:

    const bool isTheSunUp = sunPosition.y > 0;

为什么?

我认为这是因为 sunPosition 不是常量。查看此页面 https://bugs.freedesktop.org/show_bug.cgi?id=25830,似乎当您初始化常量时,您不能将其基于可能变化的内容。

"Initializers for const declarations must be constant expressions"

因为它需要 constant expression,这不是你的情况。