Help in modifying an outline effect

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:

You can see that the white outline is drawn both for the visible part of the object I’m aiming at and the occluded part. I would like to NOT draw the occluded part at all.

Now, I managed to do this with other outline materials, but not this one. The most I could do was to draw only the visible part but without any outlines, like this:

If you could point me in the right direction I would really appreciate it!

This is the relevant part of the material, where we have the outline result and the computation to check if the current pixel is being occluded or not:

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…

Sorry, but I can’t give you a good answer about this :slight_smile:
Of course it has some performance impact…

Alright, thanks for the help! :slight_smile: