Open PureAsbestos opened 2 weeks ago
I don't think it should be expected that you'll get static type checking, but runtime type checking should be implemented. Silently failing is honestly a weird way of handling it, though it's possible that's part of the graphics API and not really Godot's fault
Describe the project you are working on
This is a QoL feature that is applicable any time you set a shader parameter from code.
Describe the problem or limitation you are having in your project
When setting a shader parameter from GDScript, if you do something like
material.set_shader_parameter("some_vec3", some_int)
, it will generally silently fail / give the wrong data to the shader, rather than produce some kind of error. As a specific real-world example from when I was recently helping someone debug this issue, setting asampler2D
with anImage
rather than anImageTexture
fails without an error and leads to unexpected results.Describe the feature / enhancement and how it helps to overcome the problem or limitation
Add static type checking when setting shader uniforms, so that using inappropriate types will give the user a helpful error instead of silently causing bugs.
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
Passing the wrong type should result in an error message, perhaps something like this:
Error at (..., ...): Expected an argument of type "Texture2D" for the "sampler2D" parameter "my_sampler2d", but got "Image" instead.
Or if you wanted to follow existing type errors more closely:Error at (..., ...): Cannot pass a value of type "Image" as "Texture2D"
Implementation of this feature would probably rely on existing typing infrastructure for both GDScript and GDShader.
If this enhancement will not be used often, can it be worked around with a few lines of script?
This enhancement will be used often and is not easily worked around.
Is there a reason why this should be core and not an add-on in the asset library?
This is about improving the core shader/code experience with enhancements to variable typing that cross between the GDScript and GDShader languages.