Simplest way to achieve blend mode in custom draw

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By yikescloud

That problem confuse me for a long time.
If I want to draw a rectangle with a hole manually like this:

Grey grid is the transparent area
Here’s the node code

extends Node2D
func _draw():
	draw_rect(Rect2(50, 200, 150, 150), Color(1, 0, 0, 0))
	draw_circle(Vector2(200, 200), 100, Color(1, 0, 0, 0.9))

and the shader code:

shader_type canvas_item;

void fragment() {
    COLOR.a = 1.0 - COLOR.a;

Without shader:
enter image description here

With Shader
enter image description here

I think enable the shader, the result should be like this:

The problem is _draw() function is not draw all the things on a cache, then apply the shader, then draw it on the screen, it apply the shader after every time you call function like draw_circle(), draw_rect(), etc. So I cant draw some mask effects like the first image shows. And I try light2D, because light2D only support texture, so I cant use custom draw either.

Thanks for any advice :smiley: