godotengine / godot

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

Instance uniform values set via Inspector are lost when editing shader #87835

Open paulmiller opened 9 months ago

paulmiller commented 9 months ago

Tested versions

reproduced in 4.0.4.stable & 4.2.1.stable

System information

Godot v4.2.1.stable unknown - Arch Linux #1 SMP PREEMPT_DYNAMIC Fri, 05 Jan 2024 16:20:41 +0000 - Tty - Vulkan (Forward+) - dedicated NVIDIA GeForce GTX 1070 (nvidia; 545.29.06) - Intel(R) Core(TM) i7-6700 CPU @ 3.40GHz (8 Threads)

Issue description

If you have a shader with an instance uniform, and you assign it a value via the Inspector, then edit the shader, the value you set will be lost.

Steps to reproduce

This shader has 2 variables, uniform vec3 left_color and instance uniform vec3 right_color, with values assigned via the Inspector.

1

Start typing in the shader. If your edit isn't immediately valid, the idle parser will complain, and remove the uniforms from the Inspector.

2

This isn't a problem for left_color, because the red value gets restored after fixing the shader. But right_color's value is lost. (The 3D view still has the old color.)

3

If we now save, close, and reopen the project, the 3D view will have the wrong color as well.

4

Minimal reproduction project (MRP)

uniform-test.zip

docssy commented 6 months ago

I think I have a similar bug on v4.2.2 that just burned at least 2 hours. Call it a panel override.

1) Create your shader uniform with the shader panel open that would show the uniforms that can be edited. Try this without a hint range first. 2) Set the uniform in the panel to something. 2alternate) Do not touch the panel. Instead, recode the shader parameters 2) Change the shader uniform parameters in code. Different value, different type. 3) Try to use the expected code value in your shader.

Example. Create a uniform vec2(1.0) Do above steps, force the panel to something like 0.75. Redo the code, maybe make it a vec3. Attempt to code against expecting a vec3, and expecting the 1.0

End result is that the shader continues to use the panel's version of whatever was there first, instead of the code. There is no warning that there is a mismatch between the panel and the parameters of the uniform once Godot validates the shader code.

In my case specifically, I had a uniform vec4 that I changed to a uniform mat4 and then changed it to a const mat4 - so why would it continue to read off the panel?!?!?!.

My recommended solutions are: 1) HIGHLIGHT to the user of the panel shader uniform position, and upwards to show that the shader parameters are out of bounds, or that a code change affects the available uniforms in the panel 2) HIGHLIGHT in the shader code window, the relevant uniforms that are in conflict with the panel. 3) Ignore the panel version and default to the shader for the use of variables when there is a mismatch.

docssy commented 6 months ago

Exactly like this. I didn't set those with the panel image