Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash when using modf in own shader #16244

Closed
Nophlock opened this issue Jan 31, 2018 · 10 comments
Closed

Crash when using modf in own shader #16244

Nophlock opened this issue Jan 31, 2018 · 10 comments
Assignees
Milestone

Comments

@Nophlock
Copy link

Godot version:
(3.0-Stable)

OS/device including version:
Windows 10
Radeon RX 570 with Radeon 18.1.1

Issue description:
Today I wanted to play around with the built in shaders and for that I wanted to use the modf command, but as soon as I typed in this line:

if( mod(UV.x,0.1) == 0.0)
{
ALBEDO = vec3(1.0,0.0,0.0);
}

It crashed immediatly and when I saved the shader before it got applied to the object, I couldn't reopen the project/scene until I manually edit the shader in the corresponding shaderfile to something else.

Steps to reproduce:
Create a new mesh, image or any type of objects that accept materials or own shaders. After that create a new "ShaderMaterial" for this object and open the builtin shaderedior. Type in a shader that is using modf or copy the following shader to the editor and wait until Godot wants to apply it:

shader_type spatial;
uniform float grid_size = 1.0;

void fragment()
{
if( modf(UV.x,0.1) == 0.0)
{
ALBEDO = vec3(1.0,0.0,0.0);
}
else
{
ALBEDO = vec3(0.0);
}
}

Note: Godot doesn't crash with the "mod"-Function, only with "modf" and I suggest you not to save the shader, except you want to edit the shaderfile all the time to reopen the project/scene ^^

Minimal reproduction project:
Please note that in this example project I used "mod" so Godot doesn't crash at the startup. Just replace "mod" with "modf" in the shader and you are "good to go".
ModfBug.zip

@vnen vnen added this to the 3.1 milestone Jan 31, 2018
@hpvb
Copy link
Member

hpvb commented Jan 31, 2018

I just tried this and Godot doesn't crash for me. I do get a shader compiler error though:

ERROR: _display_error_with_code: SceneShaderGLES3: Fragment Program Compilation Failed:
0:1166(25): error: function parameter 'out i' is not an lvalue
0:1166(7): error: operands of `==' must have the same type

   At: drivers/gles3/shader_gles3.cpp:168.
ERROR: get_current_version: SceneShaderGLES3: Fragment Program Compilation Failed:
0:1166(25): error: function parameter 'out i' is not an lvalue
0:1166(7): error: operands of `==' must have the same type

   At: drivers/gles3/shader_gles3.cpp:441.
ERROR: get_current_version: Method/Function Failed, returning: __null
   At: drivers/gles3/shader_gles3.cpp:449.
ERROR: bind: Condition ' !version ' is true. returned: false
   At: drivers/gles3/shader_gles3.cpp:123.
ERROR: _get_uniform: Condition ' !version ' is true. returned: -1
   At: drivers/gles3/shader_gles3.h:377.
ERROR: _get_uniform: Condition ' !version ' is true. returned: -1
   At: drivers/gles3/shader_gles3.h:377.
ERROR: _get_uniform: Condition ' !version ' is true. returned: -1
   At: drivers/gles3/shader_gles3.h:377.
ERROR: _get_uniform: Condition ' !version ' is true. returned: -1
   At: drivers/gles3/shader_gles3.h:377.
ERROR: _get_uniform: Condition ' !version ' is true. returned: -1
   At: drivers/gles3/shader_gles3.h:377.

@Nophlock
Copy link
Author

Nophlock commented Jan 31, 2018

@hpvb
Ok, I gave this a try on a Fedora system now and it doesn't crash there. Instead I get the same error message as you(so you probably tested it on Linux too? ^^), which shouldn't popup anyway or did I used modf wrong and this is related to an driver issue on my Windows machine?

@vnen
Copy link
Member

vnen commented Jan 31, 2018

I get the errors on Windows 10 x64 with a Radeon RX 480, but it doesn't crash. Are your drivers up-to-date?

@hpvb
Copy link
Member

hpvb commented Jan 31, 2018

This shader probably shouldn't be submitted to the driver at all though. I'd still call that a bug, irrespective of the driver bug.

@Nophlock
Copy link
Author

@vnen
Yeah I got the newest one or at least the Radeon driver tells me that I have the newest one which is 18.1.1

@hpvb
Alright

Topic:
I don't know if this helps but when I run Godot from the Cmd window to see what Godot is printing when it crashes, I get this:
grafik

@binbitten
Copy link
Contributor

Second argument of modf() is actually an output parameter. Seems godot does not prevent using constants as outputs, which will cause glsl-error or crash depending on the driver.

@Nophlock
Copy link
Author

Nophlock commented Feb 5, 2018

@binbitten
Oh wow, totally overlooked the "out" parameter in the documentation, this explains a few things...

@akien-mga akien-mga changed the title Godot 3 Stable crashes when using modf in own shader Crash when using modf in own shader Feb 13, 2018
@Nophlock
Copy link
Author

Just to give this a little update: I've managed to compile Godot from the sources and with that, enable the Backtrace which hopefully helps more than the old one ...

grafik

@Zylann
Copy link
Contributor

Zylann commented Jul 14, 2018

Godot 3.0.5
Windows 10 64 bits
GeForce GTX 1060 6GB/PCIe/SSE2

I get broken rendering if I use this shader:

shader_type spatial;

uniform sampler2D u_noise;

void fragment() {
	float n = texture(u_noise, UV).r;
	n += modf(TIME, 1.0);
	EMISSION = vec3(n, n, n);
}

@vnen
Copy link
Member

vnen commented Jul 14, 2018

@Zylann as mentioned earlier, second argument of modfis an out parameter.

@reduz reduz self-assigned this Sep 6, 2018
@reduz reduz closed this as completed in d2e642b Nov 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants