How to use blend_rect_mask?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Lisandro Lorea
:warning: Old Version Published before Godot 3 was released.

I’m using Godot 2.1.4 and blend_rect_mask seems to be doing the same as blit_rect_mask. That is, it’s not blending, just blitting every pixel where the mask’s alpha is !=0. Is this a bug or am I doing something wrong?
I tried both png and webp formats and checked that both the src image and the mask have an alpha channel.

extends Node2D

onready var canvas = get_node("canvas")
var brush = Image()
var color = Image()
var image = Image()
var tex

func _ready():
	print("Initialized")
	image.load("res://images/canvas.png")
	brush.load("res://images/star2.webp")
	color.load("res://images/red.png")
	tex = ImageTexture.new()
	tex.create_from_image(image)
	canvas.set_texture(tex)
	set_process(true)
	set_process_unhandled_input(true)
	
func _unhandled_input(event):
	if event.is_action_pressed("click"):
		var mouse_pos = get_global_mouse_pos()
		image.blend_rect_mask(color, brush, brush.get_used_rect(), mouse_pos - 0.5 * brush.get_used_rect().size )
		#image.blend_rect(brush, brush.get_used_rect(), mouse_pos - 0.5 * brush.get_used_rect().size )
		#image.brush_transfer(color, color, mouse_pos)
		tex.create_from_image(image)
		canvas.set_texture(tex)
:bust_in_silhouette: Reply From: mollusca

The blend and blit methods treat the mask in the same way: if the alpha value of the mask pixel is non-zero the pixel gets blended/blitted. The difference is that blitting replaces the destination pixel with the source pixel, while blending blends the destination pixel with the source pixel.
blend vs blit

Oh, I see. I was expecting the mask alpha to affect the source alpha.

Lisandro Lorea | 2017-11-14 12:46

hi Mollusca, are the 2 methods able to work with partially transparent mask pixels?
or do they only check for the mask pixel alfa to be 0 or >0?

Andrea | 2021-08-30 12:55