Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deal with NaN or inf in OpenGL ES 2.0 shaders

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?

like image 955
rsp1984 Avatar asked Sep 03 '25 10:09

rsp1984


1 Answers

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 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.

like image 197
Nicol Bolas Avatar answered Sep 04 '25 23:09

Nicol Bolas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!