godotengine / godotengine/godot
Duplicating `ShaderMaterial` reverts certain shader parameters
- Dominant language
- C++
- Stars
- 117k
- Forks
- 26.8k
- PR merge metrics
- PR metrics pending
Description
### Tested versions
Reproducible in v4.5.rc.double.custom_build [bfa330dd5]
Did not test in any other version yet.
### System information
Godot v4.5.rc.double (bfa330dd5) - Windows 11 (build 26100) - Multi-window, 1 monitor - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 3060 Ti (NVIDIA; 32.0.15.8129) - 12th Gen Intel(R) Core(TM) i5-12400F (12 threads) - 31.84 GiB memory
### Issue description
Duplicating a ShaderMaterial with modified shader parameters that were set by code (not in the editor) will reset certain types back to the "default" (editor) values for both the original and the duplicated ShaderMaterial.
For example, if you set a shader parameter to be a certain Vector2, and then duplicate the material, the original and the duplicate materials with both now revert this Vector2 to the one that can be seen in the editor, i.e. the parameter that was just set is gone, even for the original material!
Simple example: Editor shows Vector2(0,0) for some parameter. You change it to Vector2(1, 1) in code (`set_shader_parameter`), and after duplicating this one material, all instances of that same material will now show Vector2(0,0) again.
I can reproduce this for Vector2 and Vector3 types, but not for float and int for example.
### Steps to reproduce
Open the MRP and click play, in the console output you will see the originally set parameter and then the values after `mat_a.duplicate()` has been called.
The editor shows Vector2(0,0) for albedo_texture_size. Changing it to Vector2.ONE and printing the parameter is successfull. But after duplicating, the value reverts back to Vector2(0,0). The same is NOT true for the float point_size for example.
### Minimal reproduction project (MRP)
[min-repro-shader.zip](https://github.com/user-attachments/files/22314547/min-repro-shader.zip)
Contributor guide
Research direction
Start by running the attached min-repro-shader.zip project and inspect the ShaderMaterial duplication path around mat_a.duplicate() and set_shader_parameter. Confirm the reported Vector2 and Vector3 resets, compare them with float and int parameters, and verify that code-set values remain intact after duplication without changing the existing reproduction behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, godot
- Domain
- computer-graphics, game-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100