Mask/cull parts of the object by other objects in 2D

Godot Version



Hello! I have objects (let’s call them type A), other objects (type B) and a background, all in 2D. Type B objects are semitransparent and are partially over type A objects. Is it possible to mask/cull type A objects so their parts that are under type B objects would be invisible? So only the background would be visible behind type B objects. All objects are scattered across the scene tree and aren’t children of each other.

I’m guessing with a shader you can accomplish this if your background is static? Have bg texture as a parameter in the shader, and basically mix each B’s pixel color with color of pixel on the bg texture behind object B.

OR add shader to objects A that makes a region on obj A invisible, and whenever objects B is in object A’s area2d (intersect), obj B sets a parameter on obj A’s shader providing it with its own texture (which will act as the region to make invisible).

dunno, just brainstorming, neither solution is easy :sweat_smile:

1 Like

Yeah, I was just hoping there was a built-in way.