glsl无限常数 [英] glsl infinity constant
问题描述
GLSL是否具有用于+/- infinity或NaN的任何预定义常数?我正在作为一种解决方法,但是我想知道是否有一种更清洁的方法:
Does GLSL have any pre-defined constants for +/-infinity or NaN? I'm doing this as a workaround but I wonder if there is a cleaner way:
// GLSL FRAGMENT SHADER
#version 410
<snip>
const float infinity = 1. / 0.;
void main ()
{
<snip>
}
我知道isinf
函数,但是我需要为变量分配无穷大,以至于无济于事.
I am aware of the isinf
function but I need to assign infinity to a variable so that does not help me.
推荐答案
就像 Nicol 所述,没有预定义的常量.
Like Nicol mentioned, there are no pre-defined constants.
但是,从OpenGL 4.1开始,至少可以保证您的解决方案能够正常工作并正确生成一个无限值.
However, from OpenGL 4.1 on, your solution is at least guaranteed to work and correctly generate an infinite value.
例如参见 glsl 4.4 :
4.7.1范围和精度
...
但是,将非零除以0会导致 正确签名的IEEE Inf :如果同时实现了正零和负零,则正确签名 将生成Inf,否则将生成正Inf.
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.
不过,在使用旧版OpenGL时要小心:
Be careful when you use an older version of OpenGL though:
例如,在 glsl 4.0 中,它说:
4.1.4浮动
...
类似地,处理诸如除以0之类的条件可能会导致不确定的结果,但在任何情况下都不应导致中断或终止处理.
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.
这篇关于glsl无限常数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!