I’m making an outline effect with multiple colors using stencil. In order to make it I looked around a lot on forums, youtube and so on. But there is still one thing that I can’t solve, and it’s outlines on objects that have custom depth enabled.
The main idea is to sample each pixel around the current pixel and if one of them doesn’t have a custom depth then I draw the outline. The problem is that it doesn’t take into account other objects that have custom depth, so the result looks like this:
In this image each object that has an outline has a different stencil index, while all other objects in the scene don’t have custom depth enabled. As you can see the outlines “stop” when the objects with custom depth overlap, which is what I don’t want. I would like in this case that the pyramid outline was fully shown (because it’s on top of the cube and in front of the pillar in the back).
To fix this I tried to do this: for any pixel around the current one I check if it has custom depth enabled and if the stencil index is different from the one on the current pixel. If so, I consider that pixel as if it didn’t have custom depth, so I draw the outline. This kinda works, this is the result:
As you can see now there are “too many” outlines. I can’t find a way to fix this at all… any ideas?