godotengine / godotengine/godot
Texture2Drd nested in ShaderMaterial keeps completely white once an empty RID was assigned to it
- Dominant language
- C++
- Stars
- 117k
- Forks
- 26.8k
- PR merge metrics
- PR metrics pending
Description
### Tested versions
Godot v4.2.2
### System information
Godot v4.2.2.stable.mono - Windows 10.0.22631 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 4070 (NVIDIA; 31.0.15.3161) - AMD Ryzen 9 7900X 12-Core Processor (24 Threads)
### Issue description
For a Texture2Drd used as a shader uniform parameter (already settled in editor and saved in scene), the Texture2Drd keeps completed white once assigned an empty RID even if a valid RID is re-assigned to the Texture2Drd.
And once the Texture2Drd turns to white, it never recovers to correct state even the scene is reloaded (not demonstrated in MRP). So it seems to be a Resource serialization bug?
Replace the uniform parameter with a new Texture2Drd created by code can resolve it.
### Steps to reproduce
1. Create a ShaderMaterial with a sampler2d uniform parameter.
2. Bind a Texture2Drd to the uniform parameter in editor inspector.
3. At runtime, assign an empty RID to this Texture2Drd.
4. Then whatever you re-assign to the Texture2Drd, this Texture2Drd keeps completely white even the full scene is reloaded.
### Minimal reproduction project (MRP)
[test_texture2drd.zip](https://github.com/user-attachments/files/16539534/test_texture2drd.zip)
In the MRP, the upper two ColorRects should be in red, and lower two should be blue.
However, the red ones assigned an empty RID before the red texture is assigned, and they keep completed white in the rest time.

Contributor guide
Research direction
Reproduce the issue with the attached minimal reproduction project, focusing on the ShaderMaterial sampler2d uniform and its Texture2Drd RID assignments. Trace what happens when an empty RID is replaced by a valid RID and when the scene is reloaded; done means the affected ColorRects display the assigned red texture instead of remaining white.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- computer-graphics
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100