godotengine / godotengine/godot
shader uniform float changes to int when calling set_shader_parameter() in GDScript with an int
- Dominant language
- C++
- Stars
- 117k
- Forks
- 26.8k
- PR merge metrics
- PR metrics pending
Description
### Tested versions
- Reproducible in 4.4.1.stable and 4.5.dev1
### System information
Ubuntu 22.04
### Issue description
Calling ```set_shader_parameter(param, value)``` with a different typed value changes the underlying type of the shader parameter. The [documentation](https://docs.godotengine.org/en/stable/tutorials/shaders/shader_reference/shading_language.html#setting-uniforms-from-code) mentions undefined behavior when setting shader uniforms, but in most other cases, GDScript is happy to convert `int` to `float` with no problems.
Ideally, `set_shader_parameter()` could do the same implicit type conversion with `float` and `int`, or at the very least display some kind of warning that there is a mismatched type. I'm not sure if there is any use case for changing the type of shader uniforms.
I'd be happy to attempt a PR for this, but I wanted to check if there were any reasons for allowing this undefined behavior.
### Steps to reproduce
1. Create a `.gdshader` with a ```uniform float param```, and attach it to a ```ShaderMaterial```.
2. Call ```shader_material.set_shader_parameter("param", 1)```. `param` now behaves like an integer, particularly when being animated.
3. Call ```create_tween().tween_property(shader_material, ^":shader_parameter/param", 0, 1)```. `param` jumps directly from 1 to 0 at the midpoint of the tween.
### Minimal reproduction project (MRP)
[test.zip](https://github.com/user-attachments/files/19493785/test.zip)
Contributor guide
Research direction
Reproduce the behavior using the provided test.zip and the documented set_shader_parameter() and shader_parameter tween calls. Trace how an integer value is stored for a float uniform, then verify that the completed change preserves float behavior and continuous tween interpolation without regressing other shader parameter types.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- game-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100