Godot: isnan() in shader code breaks shader when a non-float is passed into it

Created on 26 May 2018  ·  1Comment  ·  Source: godotengine/godot

Godot version:
3.0.2 Mono

OS/device including version:
KDE Neon
GTX 1060

Issue description:
in a shader you can use isnan() to check if a float is NaN. However, if you pass anything that is not a float into it (such as a integer, vector, matrix, etc) it breaks the shader, yet doesn't give an error message in the editor. You do get a lot of error spam when the game runs, though:

 drivers/gles3/shader_gles3.h:377 - Condition ' !version ' is true. returned: -1

For instance try this shader:

shader_type spatial;

void fragment()
{
    ALBEDO = isnan(vec2(0,0)) ? vec3(1.0) : vec3(0.0);
}

I've assigned it on a sphere here, as you can see, the sphere gets weirdly stretched and is drawn in screen space:
bug

Steps to reproduce:

  1. Add MeshInstance to the scene, assign sphere, and assign a new ShaderMaterial to it.
  2. Put the shader above into it and observe results.

Minimal reproduction project:

shadernanbug.zip

bug core rendering

Most helpful comment

Thanks for the reproducible bug report. I've created a pull request that should fix this bug.

I just wanted to let you know that your shader code won't compile even with the fix because isnan(vec2) returns a boolean vec2. Your code would compile if you specified which element of the vec2 you want to check. For example:

shader_type spatial;

void fragment()
{
    ALBEDO = isnan(vec2(0,0)).x ? vec3(1.0) : vec3(0.0);
}

>All comments

Thanks for the reproducible bug report. I've created a pull request that should fix this bug.

I just wanted to let you know that your shader code won't compile even with the fix because isnan(vec2) returns a boolean vec2. Your code would compile if you specified which element of the vec2 you want to check. For example:

shader_type spatial;

void fragment()
{
    ALBEDO = isnan(vec2(0,0)).x ? vec3(1.0) : vec3(0.0);
}
Was this page helpful?
0 / 5 - 0 ratings