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
SceneDepth
and an output typeCMOT Float 1
. - Add
ConvertToDeviceZ(SceneDepth)
to theCode
field. - Pass the result of
SceneTexture:SceneDepth
to the custom expression node.