godotengine / godotengine/godot
Updating texture_rd_rid of Texture#DRD is not reflected by user materials of the Texture#DRD in certain cases
- Dominant language
- C++
- Stars
- 117k
- Forks
- 26.8k
- PR merge metrics
- PR metrics pending
Description
### Tested versions
- Reproducible in v4.5.stable
### System information
Godot v4.5.stable - Ubuntu 22.04.5 LTS 22.04 on X11 - X11 display driver, Multi-window, 1 monitor - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 4060 Laptop GPU - 13th Gen Intel(R) Core(TM) i9-13900HX (32 threads) - 31.03 GiB memory
### Issue description
When a compositor effect with `@tool` enabled modifies the `texture_rd_rid` field of a `Texture#DRD` (true for both 2D and 3D versions) in its `_render_callback`, so that the texture is now associated to some RD textures generated on the fly, things generally work **only for the first time of execution** within 1 editor session.
After closing and reopening the scene again, the materials using that `Texture#DRD` behave as if that texture slot is bound to nothing (not even the black-and-purple missing texture).
See MRP and steps to reprod for details.
### Steps to reproduce
Open the MRP and you should see something like this:
Then, close the current scene and reopen it through the file system dock, and you would see this:
Re-assigning the `Texture#DRD` to the slot in the material would fix it.
If not reproducible, try to follow these steps:
1. Close all scenes
2. Open `scene.tscn`
3. Open `sphere.tscn`
4. Switch back to `scene.tscn` without closing `sphere.tscn`
5. Close `scene.tscn`
6. Open `scene.tscn`
It _seems_ that not having `sphere.tscn` open while opening and closing `scene.tscn` does not spawn this issue.
~~It _seems_ that this is only relevant when running code in the editor - try to run `scene.tscn`, which has a camera pointing towards the sphere with procedural texture, and you would see this:~~
Update: It COULD happen when playing from editor, but I cannot figure out the exact trigger of this. It happened in my production project when I have a Texture3DRD read by a material applied to a FogVolume (similarly, re-assigning the texture parameters at runtime fixes the visual). However, building a similar setup in MRP does not trigger the issue.
### Minimal reproduction project (MRP)
[mrp_mat_chain_reload.zip](https://github.com/user-attachments/files/23295816/mrp_mat_chain_reload.zip)
Contributor guide
Research direction
Start by opening the attached mrp_mat_chain_reload.zip and reproduce the failure with scene.tscn and sphere.tscn, focusing on the compositor effect's _render_callback and Texture#DRD texture_rd_rid changes. Trace how the material texture binding is restored when scenes are closed and reopened; done means the procedural RD texture remains available to user materials after the documented reload sequence.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- computer-graphics, game-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100