There seems to be an extremely limited amount of things you can do with integers in GLSL ES 2.0.
For example:
int
typesSo, it seems the only thing you can really do with integers is:
-
, +
, *
, /
), but only between other integers. No operator exists which allows you to add a float
and int
together.vec
constructors allow you to pass integersIs that really it? Are there any intrinsic functions that take int
parameters other than vec
constructors? Are there any operations you can do between float
and int
?
You are correct, use cases of integers are limited. Per 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.
Since there's no guarantee GLSL ES integer type maps to a hardware integer type, it's only useful for compile-time type checking with little to no effect at runtime. All places that require integers are listed in the spec.
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