Good day everyone! I was looking to get some pointers/feedback on some cross section implementation I have been trying to get working at the place I work at.
For a bit of context we have an App that allows Users to use their CAD data in a staging environment similar to power point, so they can make presentations, instruction manuals and other neat stuff with it. Users in the CAD field usually require for a way of showing a cross section of their models for most of the use cases we cover so I have been trying to implement a cross section feature with no luck (Im not a programmer but i have I do understand the basics to work closely with shaders and post-processing effects within blender, ue and a bit of unity).
Now the way i tried to implement it follows this hidden gem of a japanese blog post from 2016
( Unity でスクリーンスペースのブーリアン演算をやってみた - 凹みTips )
What they do is a mix of Z-depth, stencils and changing the order in which they render these Layers. We only need a couple of renderer features, Shaders with stencils and two objects, the one subtractor and the subtracted.
So if I got it right they implement this screen space boolean in the following order:
- Write the Z-Depth from the object to be subtracted (Named subtractee from now on)
- Use a Stencil mask to mark the areas that can be removed with the subtractor
- Write the Z-Depth of the Backfaces of the Subtractee and save it for a later operation
- Render the Backfaces of the subtractor with ZTest set to Greater
- Compare the depth of the backface of the subtractor with the backface of the subtractee we prepared in advance (in the blog post the mention setting the depth to the maximum value of 1.0 so the subtractor penetrates the backfaces of the subtractee, but I have not been able to set this up using the renderer feature in combination with shaders and stencils, this might be part of the main problem)
- Remove the stencils operation to make the initial mask so it doesn’t interfere with anything else
Trying to implement these exact workflow has left me with the following
The first problem is as mentioned in step 5, I dont know how to properly set the depth of the subtractor to its maximum value so that it penetrates the subtractee and secondly i dont know how to make the objects that are not marked for the operation but are inside this boolean to show upas they normally should
Here are the screenshot of the renderer features, the ones using shaders have nothing but a backface setup in them and set their colormask to 0 so they dont render
My quesiton would be if anyone knows how to properly fix the step 5 so that the boolean operation takes place on the back and the objects not marked for the operation are still visible ? im open to even use scripting if possible. (Everything implemented inside of URP in unity 2022f1)
Thanks in advance to anyone that can help or give some insight into this