Search Unity

Writing custom depth in shader

Discussion in 'High Definition Render Pipeline' started by JM_CG, Oct 21, 2020.

  1. JM_CG

    JM_CG

    Joined:
    Apr 20, 2017
    Posts:
    35
    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
     
  2. JM_CG

    JM_CG

    Joined:
    Apr 20, 2017
    Posts:
    35
    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);
     
    yyysukiii and Egad_McDad like this.