On a static mesh, you can set “Render Custom Depth” as well as a byte value for the “Custom Depth Stencil Value”.
In the post process material, drop a scene texture sample and select “CustomStencil”.
You can get a mask for each desired value using the material function “BitMask” by plugging the SceneTexture:CustomStencil to the BitMask input and a constant for each bit you wish you mask for.
You could perform a sobel type post process for each main color. The easiest example to copy is from the “Stylized rendering” example project.
You also need to go into the editor project settings under rendering ->post processing and set the “custom depth stencil pass” setting to Enabled with Stencil. You probably have to restart the editor for it to take effect.