URP DepthPrepass exploration&Shader does not display problem analysis

The question "Shader created through the right-click menu under URP does not display any content" diverges, which extends the discussion of URP DepthPrepass.

Causes of the above problems

In the URP default pipeline, before rendering opaque objects, if one of the following situations occurs before Execute deep write Pass:

  • yes RenderFeature need Depth Texture / Normal Texture
  • Camera selected DepthTexture (Forced opening or Pipeline Asset check DepthTexture)
  • DepthPrimingMode && Forward Rendering && RenderType Base && CameraType != Reflection

Unity calls this process DepthPrepass.

Next, when rendering opaque objects:

  • Not open Depth Priming Mode
    • If there is no special statement, use ZTest LessEqual Elimination of slice elements by means of
    • Not used Depth Texture
  • open Depth Priming Mode
    • Default Use ZTest Equal , combined Depth Texture To eliminate slice elements
    • Optimization of Overdraw for opaque queues

If the shader of an opaque object does not contain the Pass specified by DepthPrepass, Prepass will not write the depth of the current object.

Since there is no write depth, DepthPrimingMode The depth of the lower slice element is always not equal to the depth map, so the slice element is naturally eliminated.

The new URP is checked by default DepthPrimingMode , so the shader file created by right clicking does not display anything.

Specified Pass and calling time

In the URP default pipeline, two sets of passes are hard coded using the Pass Tag name:

  • DepthOnlyPass: DepthOnly
  • DepthNormalOnlyPass: DepthNormals / DepthNormalsOnly

In the default pipeline, the logic for selecting DepthOnlyPass or DepthNormalOnlyPass is as follows:

 if(requiresDepthPrepass) { if(renderPassInputs.requiresNormalsTexture) { if(this.actualRenderingMode == RenderingMode. Deferred) { //Other contents are omitted m_DepthNormalPrepass.Setup(xxx); }else { m_DepthNormalPrepass.Setup(xxx); } EnqueuePass(m_DepthNormalPrepass); }else { if(this.actualRenderingMode !=  RenderingMode.Deferred) { m_DepthPrepass.Setup(xxx); EnqueuePass(m_DepthPrepass); } } }

According to the URP source code, when the RenderFeature (such as SSAO) has Normal enabled, DepthNormalOnlyPass will be executed, otherwise DepthOnlyPass will be executed.

What's the usage?

As mentioned above, this is to optimize OverDraw of opaque queues.

Although we expect the opaque queue to render from front to back, this sort is a rough sort of mesh, not a sort of image or slice (the CPU side cannot process the image or slice by pixel). OverDraw always exists.

Using ZTest Equal in combination with depth maps, the overdraw of opaque queues will be significantly optimized.

Solution to initial problems

It doesn't matter

turn off Depth Priming Mode , anyway Depth Priming Mode + MSAA The profit on TBR GPU is not necessarily large.

A safe approach

Opaque objects should complete the relevant Pass honestly. Depth Pass is only for writing depth, and the content should not be too complex.

If there is no vertex or slice displacement, just copy the Pass of URP Lit.

Zimiao haunting blog (azimiao. com) All rights reserved. Please note the link when reprinting: https://www.azimiao.com/10070.html
Welcome to the Zimiao haunting blog exchange group: three hundred and thirteen million seven hundred and thirty-two thousand

Comment

*

*