How not to render parts of mesh that overlaps another mesh

Good evening,
I currently have a jacket and T-shirt behind it.
I’m trying to understand how I can not display parts of the shirt that overlap the jacket.
I tried to play with stencil buffer but didn’t get results here.

Any ideas of what can help me here?
Here’s my playground.

P.S. Yes, I can easily adjust 3d models in Blender, but the task is to solve it for intersections globally for more models automatically.

Thank you

Using the stencil will only work if the shirt is completely contained “inside” the jacket, but you can see in this screenshot that the shirt leaks outside the sleave:


I don’t think there’s any way to fix the problem with some clever technique, you will have to update the model to make sure it remains inside the jacket…

1 Like

Any chance it can be done using fragment shader and passing depth texture or something?
Or it’s also wouldn’t work?

I don’t know how the part that leaks could be hidden in any way, you would need something to be drawn there (before the shirt is rendered, to update either a depth or a stencil texture) for that to be possible…

Thank you!