Godot: Shader builtin allowed as argument names but shadowing does not work, leads to wrong results or failed compilation

Created on 22 Oct 2019  路  4Comments  路  Source: godotengine/godot

Godot version:
3.1.1

Issue description:
I discovered that it is possible to pass a global shader parameters like TIME or UV to the functions without passing it in the main vertex/fragment/light functions.

Steps to reproduce:

Write a simple shader:
image

Minimal reproduction project:

AShaderTestBug.zip

bug shaders

All 4 comments

As mentioned by a friendly user in #33156, this can also cause shaders to break, e.g. with:

shader_type canvas_item;

vec4 f(sampler2D TEXTURE, vec2 UV, float TIME) {
    vec4 tx = texture(TEXTURE, UV);
    return tx;
}

void fragment() {
    COLOR = f(TEXTURE, UV, TIME);
}

Yeah, censoring for the win. I don't agree with merging bugs which behave differently and expected results are different, but whatever, it's your project and it seems bug issues are for engine developers, not for engine users... :disappointed:

What probably happens here is that the values for the builtin TIME, UV, TEXTURE, etc. are automatically injected in the custom function and used, overriding the parameters that use their name. So shadowing is broken, what should happen is that the function parameters should have precedence over the builtins -- or possibly this syntax should simply not be allowed, as it's confusing anyway.

Both here and in the example from #33156, the actual values passed to the method don't matter, what is used is the code inside the function itself with the builtins replaced. When using one which is specific to a custom function like TEXTURE in fragment(), the shader fails compiling.

Anyway, I'm found a way to fix this issue

Was this page helpful?
0 / 5 - 0 ratings