I’ve been doing some composite work in UE4, the final step of which is to use the High Resolution Screenshot tool to capture an image using the custom depth as a mask.
What this is supposed to do is capture only objects that are rendering with custom depth and mask out everything else. The result should be a nice rendering of only the custom depth objects and a transparent background, ready for compositing.
In practice, I was finding that I couldn’t even see my custom depth objects, as if there were a far clipping plane obscuring them.
For each object that should exist in your mask, you have to select it and check the following option. You may have to do this in bulk depending on your scene.
Next you use the screenshot tool and enable Use Custom Depth as Mask.
If you only see a purely green screen at this point, then read on.
After a bit of sleuthing, I found a mask material provided by the engine, it calls a single material function:
If you open this function, you will see the nodes below.
The constant that is circled is the maximum scene depth that the material will render. The default is 10,000, so anything beyond this distance will be lost. Increase this value to the maximum distance that your objects will be from the camera.