godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
91.23k stars 21.22k forks source link

Shaders : Global uniform declaration breaks loading the project #62941

Open Knand1861 opened 2 years ago

Knand1861 commented 2 years ago

Godot version

4.11 alpha

System information

Windows 11

Issue description

If I declare a global uniform in the shader script, project crashes on next loading; WORKAROUND: deleting the declaration with notepad directly in .tres file before launch and then retyping it again, once loaded. [they work fine during the session (yes, I added global in project settings)]

Steps to reproduce

shader_type canvas_item;
global uniform float g;

void fragment(){
    vec4 color = texture(TEXTURE,UV);
    color.a-=g;
    COLOR = color;
}
  1. Add float global uniform in project settings, so there is no error spotted by the engine.
  2. close and reopen the project.

Minimal reproduction project

No response

Calinou commented 2 years ago

The issue is that per-instance uniforms (and likely global uniforms) aren't implemented for use in 2D (canvas_item) shaders yet. They only work with 3D (spatial) shaders.

As per the other linked issues, can you test this in a 3D (spatial) shader instead of a 2D (canvas_item) shader?

clayjohn commented 2 years ago

I wonder if this is connected to the recent shader caching issues. It would explain why it works after deleting the shader and rewriting it on subsequent loads