How to wait for shader in viewport to update before getting image?

Godot Version

4.4.1

Question

I’m trying to use Godot’s Subvewport to do some fast rendering to buffers. I have a 3D scene set up that it uses a shader to render a quad. This quad contains data I want to use. I’m setting parameters on the shader first and then calling subviewport.get_viewport().get_texture().get_image() to get the image buffer containing my data.

This all seems to be done in a different thread, though, so is there any way to make sure that after I’ve updated my ShaderMaterial’s parameters that the quad has been redrawn before I call get_texture() to get the buffer image?

Frames are drawn every process cycle on the GPU, then returned to the CPU at some point after the frame is complete.

You can await the next process frame or two to see if it has updated with your details.

1 Like

Thanks for the explanation, that helps clarify what’s going on behind the scenes. I was wondering, do you know if there’s a clean way to ensure at least one full frame has passed before grabbing the image? Like, would using await get_tree().process_frame (or a couple of them in a row) work reliably in this case? Or is there a better pattern to follow when working with SubViewports and shaders this way?

Use the RenderingServer.frame_post_draw signal instead.

1 Like