Search Unity

Question How to render an object on top of everything else (VR)

Discussion in 'VR' started by SI_007, Mar 10, 2023.

  1. SI_007

    SI_007

    Joined:
    Aug 10, 2015
    Posts:
    84
    I've tried a few ways to accomplish this simple task via various tutorials and forum posts, but nothing seems to work in VR (setting different material priority values, dual camera, using render object as an added URP render experimental feature).

    I would much appreciate some guidance on how to accomplish this basic action.

    Thanks!
     
    Last edited: Mar 10, 2023
  2. arfish

    arfish

    Joined:
    Jan 28, 2017
    Posts:
    782
    Have you tried searching for "unity shader draw on top of everything"?
     
  3. SI_007

    SI_007

    Joined:
    Aug 10, 2015
    Posts:
    84
    Unfortunately, no result came out from your search suggestion on the forum, while the many other posts & answers I found always come down to using a dual camera system in a non-VR setting.

    I would gladly give up my neighbour's car for the material's sorting priority setting to work as any layman would expect (ex: higher priority values = renders on top of lower priority values).
     
  4. LucasHehir

    LucasHehir

    Joined:
    May 7, 2020
    Posts:
    74
    Not sure why any of the named approaches wouldn't be working, but depending on the kind of object you want to render, an OVROverlay will definitely do that. It's mostly useful for skyboxes or UI but if you set them to Overlay (as opposed to Underlay) it will actually render completely in front of Unitys eye buffer entirely.
     
  5. SI_007

    SI_007

    Joined:
    Aug 10, 2015
    Posts:
    84
    Thank you for your input and suggestion, it is much appreciated. I should have specified that the setup is simple XR (no OVR/SteamVR), with URP.

    Here is an example, using a sphere and a cube. How can the sphere be rendered after the cube (i.e., on top) like in the first pic (without having to use the GUI Textshader - which is for demonstration purpose only).

    Incredibly basic, yet I cannot find a proper solution.

    BTW: I had expected that using a material with a different sorting priority would render the sphere or the cube on top. Unfortunately, it does not.
     

    Attached Files:

  6. LucasHehir

    LucasHehir

    Joined:
    May 7, 2020
    Posts:
    74
    If you're on URP, the Render Objects Feature you mentioned should definitely do the trick. Are you sure the sphere is on the layer nominated in the feature? Maybe post a screenshot of the URP stack.
     
  7. SI_007

    SI_007

    Joined:
    Aug 10, 2015
    Posts:
    84
    Partially SOLVED!

    Thanks again for your help LucasHehir, I discovered that the issue is the Render Objects Feature "Event" (which is set to occur by default "AfterRenderingOpaque").

    I'm not sure why it doesn't work when this occurs after rendering the opaque (shouldn't it?), but in my URP setup, this "Event" must be set to either "AfterRenderingPostProcess" or "AfterRendering" in order for an object (on the appropriate layer) to be rendering on top.
     

    Attached Files:

    LucasHehir likes this.
  8. LucasHehir

    LucasHehir

    Joined:
    May 7, 2020
    Posts:
    74
    I'm not too certain sorry - I'm definitely not the rendering expert at my company, I'll put it to you that way. But I'm glad that some variation worked.

    I've had lots of moments where it's felt like something simple was turning out impossible; there's usually a "make it work" switch hiding somewhere. Best of luck!
     
    SI_007 likes this.