UE4 High Res Screenshot Custom Depth Mask Clipping

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.

Hmm, this is not what I was hoping for

The Setup

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.

An object is set to be rendered into the custom depth pass

Next you use the screenshot tool and enable Use Custom Depth as Mask.

Use custom depth as mask and you should only see the objects that you’ve selected

If you only see a purely green screen at this point, then read on.

The Solution

After a bit of sleuthing, I found a mask material provided by the engine, it calls a single material function:

Engine/EngineMaterials/HighResolutionScreenshotMaskFunction

If you open this function, you will see the nodes below.

We found you!

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.

5 Comments

    • You may need to change the “View Options” (the eye icon on the bottom right of the content browser) to show engine content. Then select the “Engine” category in the content browser and search for it there.

  1. This sounds like just exactly what I need, but Unreal tells me I do not have “sufficient permission to save content” – any idea how to get around this?

    • This is a little problematic since the content being modified is engine content. In my case I had compiled my own engine and so could modify the content. If you are running the binary engine, you may need to perhaps run the engine as administrator and/or make sure that the file in question [YourEngineFolder]\Engine\Content\EngineMaterials\HighResolutionScreenshotMaskFunction.uasset is not set to read only. Let me know if either of these work.

  2. Thanks for the suggestions! Just checked the file and it’s not set to read-only, so I suspect I need to run the engine as an admin. Running as an admin would be the next thing to try but because it’s a work machine that can complicate things (my admin login has its own directory structure). Until then I can get by tweaking it temporarily just to get the alpha mask.

Leave a Reply