nurgan
nurgan

Reputation: 329

float variable does not compare in any way

I am doing some stuff in a glsl fragment shader, and getting some strange results. The code i use for calculations should for now not really be relevant, but for some kind of "debugging" I display colors dependent on the range a variable is in.

The coded for that is: (shadow is a float)

if(shadow == 0.0f)
{
    vFragColor = vec4(1.0f, 0.0f, 0.0f, 0.0f);
}
else if(shadow == 1.0f)
{
    vFragColor = vec4(0.0f, 1.0f, 0.0f, 0.0f);
}
else if(shadow < 1.0f && shadow > 0.0f)
{
    vFragColor = vec4(0.0f, 0.0f, 1.0f, 0.0f);
}
else if(shadow < 0.0f)
{
    vFragColor = vec4(1.0f, 0.0f, 1.0f, 0.0f);
}
else if(shadow > 1.0f)
{
    vFragColor = vec4(0.0f, 1.0f, 1.0f, 0.0f);
}
else
{
    vFragColor = vec4(1.0f, 1.0f, 1.0f, 0.0f);
}

From my understanding, it should not be possible to enter the "else" at the end, since the code before checks for any possible value. But what happens is, that for the areas where I get some strange results, and I wanted to do that kind of "debugging", the code enters the "else" statement.

Does anybody know how this could happen? I do not understand this at all...

Upvotes: 2

Views: 1263

Answers (1)

datenwolf
datenwolf

Reputation: 162164

floats can also be "Not a Number"

Upvotes: 6

Related Questions