Description

Shaders that compare custom depth and pixel depth get wrong output values because the ranges are different. This error is most noticeable over large distances.

The difference in ranges is due to the Custom Depth being run through ConvertFromDeviceZ() in hlsl which uses a epsilon offset (View_InvDeviceZToWorldZTransform[3]) that comes from CreateInvDeviceZToWorldZTransform() in SceneView.cpp

// Subtract a tiny number to avoid divide by 0 errors in the shader when a very far distance is decided from the depth buffer.
// This fixes fog not being applied to the black background in the editor.
SubtractValue -= 0.00000001f;

Pixel Depth doesn't go through this logic, though in theory you could make it by sending it through something like this

return ConvertFromDeviceZ(ConvertToDeviceZ(PixelDepth));

The custom depth node should use the full depth range like Pixel Depth.

(Example graph comparing custom depth and pixel depth)

[Link Removed]

Steps to Reproduce

Steps to Reproduce

1. Create new Unreal Project
2. Delete all landscape/fog/atmosphere actors from default level (basically everything except for SkyLight & DirectionalLight)
3. Add cube to scene set transform to Location (X=-750000086.000000,Y=0.000000,Z=90420.000000) Rotation (Pitch=0.000000,Yaw=45.000000,Roll=0.000000) Scale (X=10000000.000000,Y=10000000.000000,Z=10000000.000000)
4. Create new tranlucent material with
5. Assign translucent material to cube
6. Move the camera outside the cube and rotate it so it is facing the cube

Expected

The full cube is drawn in red

Actual

Only part of the cube is drawn in red and the rest is clipped

Have Comments or More Details?

There's no existing public thread on this issue, so head over to Questions & Answers just mention UE-335270 in the post.

0
Login to Vote

Unresolved
ComponentUE - Rendering Architecture - Shaders
Affects Versions5.35.45.55.65.75.8
CreatedSep 25, 2025
UpdatedSep 25, 2025
View Jira Issue