你可以用 GLSL ES 中的整数做什么?

What can you do with integers in GLSL ES?

在 GLSL ES 2.0 中,您可以使用整数做的事情似乎非常有限。

例如:

所以,看起来你唯一能用整数做的事情是:

真的是这样吗?除了 vec 构造函数之外,是否有 任何 接受 int 参数的内部函数?在 floatint 之间,您可以执行 任何 操作吗?

你是对的,整数的用例是有限的。根据 OpenGL ES Shading Language spec、4.1.3:

Integers are mainly supported as a programming aid. At the hardware level, real integers would aid efficient implementation of loops and array indices, and referencing texture units. However, there is no requirement that integers in the language map to an integer type in hardware. It is not expected that underlying hardware has full support for a wide range of integer operations. An OpenGL ES Shading Language implementation may convert integers to floats to operate on them. Hence, there is no portable wrapping behavior.

由于不能保证 GLSL ES 整数类型映射到硬件整数类型,它仅对编译时类型检查有用,在运行时几乎没有影响。 需要整数的所有地方都在规范中列出。