In the material editor, when we use the node SceneTexture with texture id SceneDepth, we get the scene depth in clip space. However, we want to get the depth value(called DeviceZ in Common.ush) that is stored in the depth buffer. We can use the function float ConvertToDeviceZ(float SceneDepth) and float ConvertFromDeviceZ(float DeviceZ) to convert between each other.
Since there is no dedicated expression node for either of them, we have to create a custom material expression manually.
- Create a custom material expression with an input node
SceneDepthand an output typeCMOT Float 1. - Add
ConvertToDeviceZ(SceneDepth)to theCodefield. - Pass the result of
SceneTexture:SceneDepthto the custom expression node.



