How to cut-out a hole in wall?

So I want to be able to cutout a hole in my mesh - this is for windows in a wall.
The way I am doing it is rendering in separate camera an alpha clipping mask with a camera that just renders the cut-out object in black, and everything else in white, like this:


and here is the result with the cutout in the wall:

That’s all well and good but it has some flaws. The first one I think I know how to fix, is that it will render this cutout even through other wall (see image below). I think if I do some kind of depth test first I can probably resolve this

The bigger issue I have, is that the other walls cannot be seen through the cutout, as these would never been seen in the inital draw, so after alpha clipping they are just invisible, like this:

So what can I do about his? something with stencil buffers? I don’t really know what those are but think maybe they are related to this kind of thing?

Also how can I make sure the shadows also have a “gap” in them, now that light should pass through the hole.

Finally here is the simple shadergraph I am using, thanks

I assume you don’t want to just cut the hole in 3d wall mesh, right?

I want to avoid it as it wont be trivial. The windows are not all square, and they can be place anywhere on the wall.

1 Like

I’d suggest looking into RealtimeCSG, a free plugin for Unity which can do CSG (constructive solid geometry). I built a house in Unity with that.
https://realtimecsg.com/

There is also Probuilder, but I liked RealtimeCSG better.

The mesh is procedurally generated so something like pro builder is not suited

Procedurally generated at run-time (as you play the game) or offline?

If offline, you’d just have to save out the mesh.
If run-time, you could probably still use RealtimeCSG because it also has an API (but I haven’t tried it).

What you are trying to do is basically screenspace CSG. Something like that does exist, but I don’t think, it’s a good idea. I am not aware of any game that shipped with it. How would you do collision detection, for example?

You could use alpha cutout in your material but that won’t work if you wall has thickness to it.