Ok, I'm getting closer:
var fondo
var fondoData
var brushData
var whiteData
func _ready():
set_process_input(true)
fondo = ResourceLoader.load("res://assets/empty.png")
fondoData = fondo.get_data()
whiteData = ResourceLoader.load("res://assets/white.png").get_data()
brushData = ResourceLoader.load("res://assets/brush_bw.png").get_data()
func _input(event):
if Input.is_mouse_button_pressed(1):
var realPos = event.pos
realPos.x -= brushData.get_width() / 2
realPos.y -= brushData.get_height() / 2
fondoData.brush_transfer( whiteData, brushData, realPos )
get_node("cabeza/luces/luz").get_texture().set_data(fondoData)
fondoData.brush_transfer works like this:
- fondoData is the background image.
- whiteData is an image with same size that you want to put over fondoData
- brushData is a grayscale image that will be used as brush
- realPos is the position where you want to paint
pretty simple actually, and this is working, but still very slow (although faster that previous attempts).
Another way that works is not using lightmask and instead of whiteData use the image data. same bad performance tho
Maybe shaders its the answer...