0 votes

That problem confuse me for a long time.
If I want to draw a rectangle with a hole manually like this:enter image description here
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:
enter image description here

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 drawcircle(), 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 :D

in Engine by (22 points)

Please log in or register to answer this question.

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 Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.