Writing custom depth in shader

Hey there,

I’m trying to write custom depth in a variant of the lit shader (I’m doing sphere impostors)

It seems the available starting points are posInput.linearDepth and posInput.deviceDepth, and the expectation for SV_Depth seems to be deviceDepth.

Is there a built in function to convert from linearDepth to deviceDepth?

Thanks

Found the solution, which is actually using the ApplyDepthOffsetPositionInput function (which is in Common.hlsl), which recalcs the position and hence the depth as a byproduct of that. It needs to be enabled with Pixel Displacement On in the material (which wraps _DEPTHOFFSET_ON).

This should go before GetSurfaceAndBuiltinData

ApplyDepthOffsetPositionInput(vecViewForwardDir, radius * normalSS.z, GetViewForwardDir(), UNITY_MATRIX_VP, posInput);

2 Likes