Sometimes we need to render outlines without using post process. For example on mobile devices and VR full-screen post-process calculations are too heavy so we have to find another solution. This short article presents geometry based outlines, very old and tricky method that I’ve used in the Anime Toon Shading package.
Basically, this effect can be easily implemented by using secondary mesh rendered from inside as a shell. Algorithm:
- Duplicate the mesh.
- Extrude the mesh in the direction vertex normal
- Set the material to render from inside.
Lets consider the last point of this algorithm. We have to create a material that will be rendered from inside of mesh. It’s tricky because UE4 doesn’t support full backface culling by default and we have to simulate this functionality by using two-sided material and opacity mask. Setup material for the shell as presented on the image:
How it helps? I have found that the front face of material can be removed from two-sided material by using masked blend mode. We only need to know if a rendered pixel is front or backside to the camera. This can be easily founded by using a TwoSidedSign node that will return 1 if the side of the polygon is positive. Just invert the result of this function and return as opacity mask value of the material.
We’ve already created backface material but additionally, we want to render bigger mesh to see the outlines. Just move the vertex position in direction of normal pre-multiplied by the parameter called ShellWidth. The full material of shell with color parameter should look like this:
Finally, you can do it yourself or just buy one of my packages called Anime Toon Shading and download the full implementation.