0 votes

Hi all!

I want to create a brush to paint over a texture. It would be something similar to the thing demonstrated in this PR: https://github.com/godotengine/godot/pull/23187

As it is said in this discussion, there are the methods blend_texture and blit_texture that can accomplish something very similar. The problem is that, as far as I know, there is no way to control the alpha channel with this methods. The brush would need to have a transparency option, so several textures could be applied with different levels of alpha... And the same texture need to have different alpha levels at different places. If I understood correctly, it is not possible to do this with the methods mentioned above (not even with the brush / erased proposed in the PR).

So I wonder what could I do to have a flexible brush. I know that there is set_pixel, but I do not know if it would be overkill. Also I have read that it has a very poor performance...

Any ideas? Thank you very much.

asked Aug 9, 2019 in Engine by VictorSeven (67 points)

1 Answer

+1 vote

The problem is that, as far as I know, there is no way to control the alpha channel with this methods

For a custom painting use case, I doubt the alpha changes while you paint, is it? Because then you can just precalculate that alpha in your brush image before painting, for example when the user changes transparency option.

I know that there is set_pixel, but I do not know if it would be overkill

It is surely slower, but I've been using that just fine in my terrain plugin to paint over large images. It starts to lag only with brushes larger than 50 pixels (while also using a system to only upload what changed).
On the other hand, if speed is a concern and your image isn't too big, you could use a GPU-driven approach and use a non-clearing viewport instead.

answered Aug 9, 2019 by Zylann (26,143 points)

I believe I need alpha changes... In fact what I want to do is a kind of terrain editor for 2D textures.

I mean, let's say I paint something with alpha=0.2. Then, I move to another part of the texture, I choose alpha=0.4 and I start to paint. If I understood well, methods like blend_texture need a "brush" that is in fact the same size as the original texture, so what is does is a blend between the two. Therefore, it is not possible to select a different blend I'm different regions... I would have to change brush alpha, changing then all the changes.

If setpixel lags for something larger than 50x50, then maybe is not good enough... I don't know. Do you have example of good use of setpixel and/or the GPU approach?

Thank you very much!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.