Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compute Texture Demo is Brittle + Proposed Fix #1152

Open
EnlightenedOne opened this issue Dec 31, 2024 · 2 comments
Open

Compute Texture Demo is Brittle + Proposed Fix #1152

EnlightenedOne opened this issue Dec 31, 2024 · 2 comments
Labels

Comments

@EnlightenedOne
Copy link

EnlightenedOne commented Dec 31, 2024

Which demo project is affected:
water_plane

OS/device including version:
Godot v4.4.dev.mono (e9504b662) - Windows 10.0.19045 - Multi-window, 1 monitor - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 3070 Laptop GPU (NVIDIA; 31.0.15.3742) - 11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz (16 threads)

Issue description:
The demo code is too brittle to use as reference material. A scene change or scene reload cleans up the texture but does not rebind it. If you add another blank scene to the demo, open the main scene and look at the pretty texture, change tab to the new scene then reopen the main scene the texture will be blank and you wont see any ripples.

I traced the issue to the Texture2DRD not surviving the scene change/reload event. You can fix it by doing the following:

func _ready():
	next_texture = 0;
	t = 0.0
... Replace the get texture with:
			# Set our texture object.
			material.set_shader_parameter("effect_texture", texture);

At the end of the exit tree request ready refire so that the scene will rebuild the freed textures:

func _exit_tree():
...
	request_ready()

Finally make the new Texture2DRD object in _initialize_compute_code:

func _initialize_compute_code(init_with_texture_size):
	# As this becomes part of our normal frame rendering,
	# we use our main rendering device here.
	rd = RenderingServer.get_rendering_device()
	
	# Create a new texture
	texture = Texture2DRD.new()

With these changes I can smoothly reload a scene and not have the compute shader fail.

Another QoL side note, include RenderingDevice.TEXTURE_USAGE_CAN_COPY_FROM_BIT on the tf usage bits so you can preview the texture in the editor.

@Calinou
Copy link
Member

Calinou commented Jan 10, 2025

cc @BastiaanOlij

Feel free to open a pull request for this 🙂

@BastiaanOlij
Copy link
Contributor

Seems fine to improve on this, I wonder if it would be better to leave things we only need to do once in _ready and move some of the code into _enter_tree so it is rerun. It really is only an editor issue I guess.

Either way, I'm happy for a PR for the improvement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants