How do I setup Render Targets Properly?

Godot Version

4.7 stable

Question

So I am making a small editable landscape/terrain system for my game and figured that for painting height I would use render targets so I would cast rays in 3d space and convert them into texture space to apply a specific alpha texture on to a render target.

The conversion isn’t a problem, the issue I am facing is I cannot figure out how do the SubViewports work for this kind of case. I saw some demos but they all have sprite nodes as children of the SubViewport that define the ViewportTexture. Now I could make it so I add little sprite nodes as I “paint” but that seems like it will add an excessive amount of nodes for a paint stroke and feels like there are other ways of achieving this, but maybe this is a godot-way of doing this kind of thing?

So if anyone could point me in the right direction with this I would be more than grateful :smiley:

You can render a single frame of a non-clearing subviewport only when stroke sprites are added and then delete all sprites. To set this up, switch subviewport’s clear mode to Never and switch the update mode to Once whenever you want to draw its contents.

4.7 also introduced DrawableTexture2D that may be a good alternative to subviewports for use cases like yours.

Thanks for guiding me in the right direction! I ended up using _draw functions to not overload the SubViewport with nodes as described in here: Custom drawing in 2D — Godot Engine (stable) documentation in English

The DrawablTexture2D part also seems quite interesting and will definitely be doing some research on it.

Again thanks for the help! :smiley: