glsl infinity constant

南笙酒味 提交于 2019-12-01 15:16:13
Jan Rüegg

Like Nicol mentioned, there are no pre-defined constants.

However, from OpenGL 4.1 on, your solution is at least guaranteed to work and correctly generate an infinite value.

See for example in glsl 4.4:

4.7.1 Range and Precision

...

However, dividing a non-zero by 0 results in the appropriately signed IEEE Inf: If both positive and negative zeros are implemented, the correctly signed Inf will be generated, otherwise positive Inf is generated.

Be careful when you use an older version of OpenGL though:

For example in glsl 4.0 it says:

4.1.4 Floats

...

Similarly, treatment of conditions such as divide by 0 may lead to an unspecified result, but in no case should such a condition lead to the interruption or termination of processing.

There are no pre-defined constants for it, but there is the isinf function to test if something is infinity.

While I'm at it, are there constants for other things like FLT_MAX FLT_EPSILON etc the way there are in C?

No, there are not.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!