How to remove an specific customstencil from scenedepth?

I’m trying to create an outline for everything on the scene, except from certain characters with a Customstencil of 4.

I don’t want those characters to get the outline from that PostProcess Material, but I can’t find a way to say to the material something like “If the Customstencil equals 4, then remove those characters from the Scenedepth”.

I’ve tried using an “If” node where I tell the program to skip the outline generation and getting the other part of the material to apply, but still that didn’t remove the custom stencil from the Scenedepth, and the outline works (is short) adding pixels around the Scenedepth objects. I can’t use just the Customdepth because I have others Customstencils with different colored outlines, so in short, I just need a way to remove that specific Customstencil 4 objects from the Scenedepth (aka outline generation).

I’ll leave an image from the important part of the shader and a link because the page didn’t let me upload the image normally for some reason .-. Thanks in advance :slight_smile: .

Image Link: Screenshot_2.jpg - Google Drive

For one, in your project settings, make sure the Custom Depth pass is “Enabled with Stencil”.

After that, you can use an if like this (in your case, ExcludeStencilValue is 4):

Ok, this works, but it didn’t solve my problem, at the end the material, was too complex and I couldn’t add just a 1 or a 0 in the If node, because we had more parts of the material, at the end, I just found another method to do outlines.

But that was my fault because I couldn’t share the full nodes (non-relevant contract stuff).
I won’t post the method I’ve used because the answer was not for another method of doing outlines, and I will mark k_a_s_s_k_a_s_s answer correct because it does indeed remove stencil values from scene depth, Thanks :).