I am a out of my depth on this one. I want to have intractable objects in my game be outlined but not show through other objects. I also need an effect that will work on meshes with hard normals. Deus Ex: Mankind Divided is the best example for what I’m after. Here’s a shot
These work by rendering out an additional texture somewhere with the outlined objects drawn with a solid color and everything else black. Then run a Sobel (edge detection) shader over that.
This outline effect is very similar with the minor exception of the outlines not being occluded.
You could probably use the _CameraDepthTexture to test for occlusion in the outline buffer shader.
The outline highlight Unity’s editor uses appears to work in a way similar to how I described above.
There are other techniques that render out explicit occluders, like this asset.
If you’re rendering using deferred (like Deus Ex) you might be able to use some custom shaders to draw the objects you want to outline into an unused gbuffer channel (either the alpha of the normal gbuffer, or the alpha of the emission gbuffer).
Thanks for the info, although I am still lost… how do I draw the outlined objects separate from the rest of the scene while still keeping them occluded? I can separate them using “RenderWithShader” function, but then they are not occluded.
That shader isn’t going to do anything by itself, it needs to be used in a system like the other links I posted which renders objects out to a separate render texture, does one (or more) passes on that render texture, and then composites back into the scene.