godotengine / godot

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

Passing indexed sampler2D array as an argument to a function in shader code prints shader_language.cpp error when shader is saved. #95003

Closed brndd closed 2 months ago

brndd commented 2 months ago

Tested versions

System information

Godot v4.2.2.stable.mono - Fedora Linux 40 (KDE Plasma) - Wayland - Vulkan (Forward+) - dedicated AMD Radeon RX 6700 XT (RADV NAVI22) () - 12th Gen Intel(R) Core(TM) i9-12900K (24 Threads)

Issue description

Writing a custom shader with a uniform array of sampler2D and then sampling one of those samplers from within a function causes the error servers/rendering/shader_language.cpp:5431 - Condition "n->type != Node::NODE_TYPE_VARIABLE" is true. Continuing. to be printed into console whenever the shader is saved.

This could be a mistake in the shader, but I'm reporting this as a bug because the associated line of code in the source has a comment saying "//bug? this should always be a variable".

Steps to reproduce

  1. Create a fresh project.
  2. Create a new shader (Right click in FileSystem, Create New > Resource, choose Shader).
  3. Double click the shader to edit it, paste in the shader code below and hit Ctrl-S (you'll get a nag about having no root node but the external resource being saved, this is not relevant).
  4. Output tab in the bottom panel will contain the error servers/rendering/shader_language.cpp:5431 - Condition "n->type != Node::NODE_TYPE_VARIABLE" is true. Continuing.
shader_type spatial;
uniform sampler2D textures[2];

// Samples a 32bit float texture heightmap
float sample_heightmap(sampler2D sampler, vec2 pos) {
    return texture(sampler, pos).r;
}

void vertex() {
    UV = VERTEX.xz / 2.0 + 0.5;
    //VERTEX.y += texture(textures[0], UV).x; // <-- does not print error
    VERTEX.y += sample_heightmap(textures[0], UV); // <-- prints error
}

If you comment out the second-to-last line and uncomment the line above that (the one that says it does not print the error) then save the shader, the error will not be printed. It seems the error is caused by calling the function.

Minimal reproduction project (MRP)

N/A

brndd commented 2 months ago

Dupe of #94447.