godotengine / godot

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

set_shader_parameter() not showing value in debugger #80662

Open scrapp08 opened 1 year ago

scrapp08 commented 1 year ago

Godot version

4.1.1

System information

MacOS 13.5 - M1 Pro

Issue description

I can see that the parameter has an integer value inside of the debugger, however when setting the shader parameter that value does not set.

Steps to reproduce

Open project, set a breakpoint towards the start of the shader() function. Step through and observe the values of min_height and max_height, and the parameters inside of material.

Minimal reproduction project

Test.zip

clayjohn commented 1 year ago

I tried running your MRP, but it doesn't do anything no matter what. It seems the shader relies on a "terrain color" texture which is not present and MeshGen.mesh() always returns 0 and 12. Could you please upload an MRP that highlights your issue?

In particular, you should have a shader that actually changes its output depending on the uniforms. Right now changing the uniform changes nothing in the shader, so it is impossible to determine if the uniform is being set correctly or not

For example, if I change your fragment function to:

void fragment() {
    float height  = vertex_y;
    float position = inverse_lerp(min_height, max_height, height);
    vec3 colour = texture(terrain_colour, vec2(position, 0)).rgb;
    ALBEDO = colour;
    if (max_height > 1.0) {
        ALBEDO = vec3(0.0);
    }
}

And reload the project, the mesh appears black because max_height is larger than 0 (it is 12).

scrapp08 commented 1 year ago

The issue is that the shader_parameter is still not set to 12, visible when stepping through in debug mode.

Updated MRP with variable min & max heights: Test.zip

clayjohn commented 1 year ago

The issue is that the shader_parameter is still not set to 12, visible when stepping through in debug mode.

Visible where? In the debugger itself?

scrapp08 commented 1 year ago

Yes, in the debugger click on material then have a look at the parameters, you'll see that min_height and max_height don't change.

clayjohn commented 1 year ago

Okay, so to clarify and summarize what I think I am hearing from you.

  1. You are running your script through the debugger
  2. Your script is setting shader uniforms dynamically based on some local variables
  3. The uniforms are updating the shader
  4. When looking at the material in the debugger, the debugger is not showing accurate values for the shader uniforms

Is that correct?

scrapp08 commented 1 year ago

Not just in the debugger, but when looking at the shader parameters in the inspector they also do not update, so I've got no way of knowing if the values have actually changed or not, hence I titled this set_shader_parameter() not working.

image