Editing Textures at Runtime

Godot Version

4.7

Question

So I’ve been making a Landscape/Terrain System where you can paint on heightmap layers onto it. Every single brush stroke is a single layer, so you paint around and create layers (it is setup this way because every layer needs to be editable after the fact). I’ve used Texture2DArrayRD for this task I pass it into my terrain shader and just blend all the layers with a max.
As a small note, I am using _draw functions to draw and utilize the RenderingServer to actually manipulate and copy stuff into memory from the viewport texture, so almost everything happens on the GPU.


(The noise is the first index of the texture array while the painting is currently setup to only write to the second index for easier debugging.)

Now this system works quite nice and as intended but I am struggling to grasp what approach do I use to edit these layers after they have been made. I want to be able to expand the shape, increase its height and mess around with the falloff, and further more this would be an edit happening in realtime :sweat_smile:. After some research I came across Jump Flooding algorithm but I am not sure if that will fulfill my needs here.
I am not sure if Compute Shaders are something I should be looking into for something like this, or perhaps I should ditch this painting approach entirely for some kind of SDF workflow. SDFs seemed like something that could work in my scenario but I am a little weary since they can be quite computationally intensive and I am also a bit unsure of how I would implement them into the workflow I described.

If any Rendering Engineers or anybody that knows a little about this could guide me in the right direction I would be more than grateful :smiley:

PS. I am sorry if I didn’t explain something properly in this post, do feel free to ask any follow-up questions.

I found TerraBrush, which lets you edit the terrain in-game, in real time. Maybe you can pick up a few tips from it.

It includes a special TerraBrushEditor node that you can add to your project to edit the terrain directly from within the game.

I will definitely take a look at it, it probably has some things I could pick up from it, especially if you can change brush settings on demand, it has to have some kind of way they are editing the textures in real time, thanks!

There’s a small catch there.

There’s a demo. But in it, you need to replace the add-on folder with the new version. Then it will work in Godot 4.7.1.