Search Unity

How to always render one object on top?

Discussion in 'Universal Render Pipeline' started by homer_3, Aug 26, 2021.

  1. homer_3

    homer_3

    Joined:
    Jun 19, 2011
    Posts:
    111
    While using URP, I have 1 object that I want to always render on top of everything else. I'm using the default URP lit shader. Is there an option I can pass to the shader to set ztest to always?
     
    aparajithsairam likes this.
  2. pw_prg_yinchao

    pw_prg_yinchao

    Joined:
    Feb 14, 2020
    Posts:
    18
    Although you set material/shader's
    ZTest
    to
    Always
    , it just only on the top of all objects whose
    ZTest
    is not set to
    Always
    or
    Great
    etc.

    First of all, UIs are excluded.

    Then, there are some choices:
    1. Set material to a large render queue, maybe
    Overlay
    which value is 4000, and set
    ZTest
    to
    Always
    . Now, if you did not add any render feature, this material should be on the top of all scene objects.
    All
    RenderQueue
    s you can choose:
    Code (CSharp):
    1. public enum RenderQueue
    2. {
    3.     Background = 1000,
    4.     Geometry = 2000,
    5.     AlphaTest = 2450, // we want it to be in the end of geometry queue
    6.     GeometryLast = 2500, // last queue that is considered "opaque" by Unity
    7.     Transparent = 3000,
    8.     Overlay = 4000,
    9. }
    2. (More recommend) Add a render feature, with a event large enough, like
    Before RenderingPostProcessing
    (which means do rendering just before post-processing), and override its
    Depth
    option with
    Write Depth
    unchecked and
    Depth Test
    is
    Always
    .

    Finally it will like
    upload_2021-8-27_17-56-41.png
    (Don't forget to select your appropriate
    Layer Mask
    )

    All
    Event
    s you can choose:
    Code (CSharp):
    1. public enum RenderPassEvent
    2. {
    3.     BeforeRendering = 0,
    4.     BeforeRenderingShadows = 50,
    5.     AfterRenderingShadows = 100,
    6.     BeforeRenderingPrepasses = 150,
    7.     AfterRenderingPrePasses = 200,
    8.     BeforeRenderingOpaques = 250,
    9.     AfterRenderingOpaques = 300,
    10.     BeforeRenderingSkybox = 350,
    11.     AfterRenderingSkybox = 400,
    12.     BeforeRenderingTransparents = 450,
    13.     AfterRenderingTransparents = 500,
    14.     BeforeRenderingPostProcessing = 550,
    15.     AfterRenderingPostProcessing = 600,
    16.     AfterRendering = 1000,
    17. }
     
    Last edited: Aug 27, 2021
  3. homer_3

    homer_3

    Joined:
    Jun 19, 2011
    Posts:
    111
    Setting the render queue of the material to 4000 via script seemed to work perfect for me. Thanks!
     
    xyzvoyager likes this.