Hi there. I’m trying to create a post process material that creates an outline around certain objects. What i need is to have different colors depending on what a mesh is. I’ve read this in the forums:
There is a new feature in 4.9 that
allows Custom Depth with Custom
Stencil. It allows another buffer to
be accessed called Custom Stencil that
allows each static mesh to have a
single Byte from 0-255 to be sent to
that buffer. This can then be used in
the shader to mask props as different
colours when being highlighted for
example.
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.
Can you show a screenshot of the connections in the material using that BitMask to select different colors? I can’t seem to figure it out how to use the SceneTexture: CustomStencil to select them.
RyanB, is there a way to allow the custom stenciled element to be occluded normally, in the case that we want post processing for a given mesh yet don’t want it to render on top of everything else?
You can use an if node to check if custom depth is greater or less than scene depth. If it is greater, plug a 0, if it is less than or equal plug in a 1 and then use that as your mask.