Demo scene with Unity standard assets
Asset Store Page.
Several days ago, my classmate from college who is an architect and interested in using Unity to do some design visualization found me and asked me to suggest him a tool to show the geometry Boolean subtraction -- cutting a geometry with another one. Currently CSG(Constructive Solid Geometry) technique is a good solution, however most of them need do mesh modification with CPU computation. Are there any way to "fake" CSG effect with just shaders?
I thought about depth mask, which can mask part of the geometry out and create a "hole" in other geometries. What if not using the depth but "thickness"(front depth and back depth) of the cutting geometry to mask out the fragment within the volume of cutting areas?
Problems & Challenges:
1. Directly using depth test will mess up the whole scene's depth. Need find a way to do"manually" depth test.
2. Should find a way to only rendering the cutting geometries into a texture.
3. Find a good way to save the front and back depth into same texture with reasonable precision.
4. Have to find a solution to "hatch" the cutout region with part of cutting geometries' back faces.
Expanding the usage:
As this shader solution not directly relay on any mesh data, and fully calculated in GPU with a few resources, it works as simple as screen space effect.
I found it can also to create many types of volume decals such as bullet holes and deep footprint and also create some destruction effect.
Decal and destruction test demo.
Architecture Cross section test.