Surface2D is a Godot 4 plugin adding polygonal surfaces on which decals can drawn.
-
Copy
addons/surface_2dfolder intoaddonsdirectory of your project. -
Enable this plugin in
Project > Project Settings... > Plugins.
-
Add a new
Surface2Dnode to the scene. -
Draw the shape of your surface by adding points in the scene view.
-
Choose a rendering layer to use for drawing decals (by default it is layer 2).
-
Set
cull_maskof the surface andvisibility_layerof the canvas item to that layer.
- Now when this canvas item intersects with the surface it should be drawn on it.
visibility_layer and cull_mask of the surface itself should NOT overlap (or the surface will try to draw itself on itself which normally causes a tsunami of errors).
It is a good practice to name rendering layers, similarly to physics layers, in Project Settings.
If a node you want to draw has a parent of CanvasItem type, then that parent has to also have an appropriate visibility_layer set.
In other words, visibility_layer propagates down the tree, similarly to how transforms do.
For understanding how mask culling and visibility layers work I recommend this excellent tutorial. Surface2D uses mechanisms mentioned there.

