如何在OpenGL ES 2.0着色器中处理NaN或inf [英] How to deal with NaN or inf in OpenGL ES 2.0 shaders
本文介绍了如何在OpenGL ES 2.0着色器中处理NaN或inf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这基于以下问题:检测NaN的最佳方法OpenGL着色器
标准GLSL定义了isnan()和isinf()函数以进行检测. OpenGL ES 2.0着色语言没有.尽管如此,我该如何处理NaN和Infs?
This is based on the question: Best way to detect NaN's in OpenGL shaders
Standard GLSL defines isnan() and isinf() functions for detection. OpenGL ES 2.0 shading language doesn't. How can I deal with NaNs and Infs nevertheless?
推荐答案
您可以通过仅适用于NaN的条件来检查NaN:
You can check for NaN via a condition that will only be true for NaN:
bool isNan(float val)
{
return (val <= 0.0 || 0.0 <= val) ? false : true;
}
isinf
有点困难.没有机制可以将浮点数转换为其整数表示形式并使用位.因此,您必须将它与一个适当的大数字进行比较.
isinf
is a bit more difficult. There is no mechanism to convert the float into its integer representation and play with the bits. So you'll have to compare it against a suitably large number.
这篇关于如何在OpenGL ES 2.0着色器中处理NaN或inf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文