How to create an intersection gap in an object using shaders? (as if a saw goes through and leaves a gap)

Hi!

I’m trying to create an effect where when a saw goes through a log a gap or hole is left where the saw has already gone through, almost like the saw “negates” the rendering of the log where they intersect. The idea is to able to see the insides of the log as if it were solid on the gap part.

I’ve tried using stencil shaders but to my understanding they are screen space, so the “mask” object (the saw) would always stay in front and no depth would be considered.

Another idea is to make an “intersection object” that is rendered only where the saw and log itersect with culling set to front (would act as the inside part of the log), but I couldn’t make it work…

Any ideas on how I could achieve this effect?

(make the red part of the image “invisible” taking depth into account)

135465-untitled-gap.jpg

Managed to figure it out.

user /u/The_Humble_Frank on reddit pointed me to this video on youtube that shows a way to do it: Unity Sort-of-Tutorial: Making Fake Holes [Render queues, depth masks, and physics tricks] - YouTube