Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Can a Shader that is in the Overlay Queue receive shadows?

Discussion in 'Shaders' started by Nikul, Jun 15, 2017.

  1. Nikul

    Nikul

    Joined:
    Jul 27, 2012
    Posts:
    11
    Working on a vr title and need my cockpit to render on top of my HUD elements, however 3d objects on Overlay layer do not pick up or cast shadows with my current shader.

    The HUD Elements are in world space using the UI/Overlay shader to render on top of everything else.

    Is this possible?
     
    Last edited: Jun 15, 2017
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    Only objects with a render queue <2500 will receive shadows (Overlay is 4000, Transparent is 3000, AlphaTest is 2450, and the default Geometry is 2000). If your object isn't casting a shadow it's likely because it doesn't have a shadowcaster pass defined, but it's possible it skips rendering the overlay queue and above to the shadow map, it's also possible you just can't tell if it's casting a shadow since the cockpit isn't receiving shadows.

    You might need use two cameras to do what you want with one camera rendering the world, and the second rendering the cockpit.
     
    Nikul likes this.
  3. Nikul

    Nikul

    Joined:
    Jul 27, 2012
    Posts:
    11
    Thanks for the reply, as I understand it, the two camera solution is not viable for VR.

    Everything (shadows) works perfectly before modifying the cockpit shader queue except that my HUD items display through the cockpit, I guess the solution is a UI overlay shader that renders transparently below 2500, so I can set the render queue of my cockpit shader above it?

    Is this possible?
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    Yeah, you could certainly have your "in world" UI draw at an "opaque" queue below 2500, then have your cockpit render at a queue above the UI, but below 2500 still. The issue you will have though is anything below that queue of 2500 will be sorted front to back instead of back to front, so your UI might render "inside out". I stopped trying to make UI exist always "on top" for VR as well as it tends to cause issues with depth vision. Instead I might say have your UI elements render in the world without ZTest Always, and maybe push them towards the player slightly to keep them "on top" of objects they're supposed to be on top of.

    Another alternative would be to use a stencil and have your UI not render where the cockpit rendered.