I’ve been using the outline material of this post, which I modified a bit to suit my needs.
I’m not good at all with materials, and this is the only material I’ve ever used and probably the only one I will ever use, so I’m not very interested right now to understand exactly what is it doing, altough I understand the general idea.
I would like to modify the material so that it won’t draw outlines of an occluded object. This is what it looks like now:
If mesh with custom depth enabled stays behind other meshes without custom depth, this mesh will appear through them.
But if the rest of meshes also have custom depth enabled, so they will occlude each other.
I think in your case custom depth should be enabled for every interactive mesh, but use different stencil index for outlined one, to apply outline by that specific index.
You’re right, activating the custom depth for every mesh that can be outlined and setting the stencil value to something I don’t actually use when rendering the outlines works. But isn’t heavy on performance activating the custom depth for every mesh at all times? In my project it doesn’t have an impact for now, but I’m afraid it might later…