Search Unity

How would one render objects behind all others, like a backdrop?

Discussion in 'Shaders' started by Nyxton, Mar 30, 2017.

  1. Nyxton

    Nyxton

    Joined:
    Mar 30, 2017
    Posts:
    2
    Alright, so I posted this on Reddit already, but I figured it wouldn't hurt to post here, too.

    How would one render objects behind all others, like a backdrop?

    Render Queue, right? That's what I was told, but apparently, 'tis a lie, as Unity seems to be determined to prove.

    Alright, so I made a skydome, using an Additive Particle shader. Does it act as its own sky? No, it adds additional effects I'd like to have to the plain procedural skybox. Simple, right?

    So it looks fine. Great, actually. At least to me, that's subjective. Anywho, the next step was to make sure it was rendered behind everything else so that it wasn't rendered as clipping through things in the distance. And I.. kinda pulled it off?

    However, as you can tell by the images attached, it's not quite there. In Scene view, it looks exactly how I'd like it. In Game view, however.. no.. not at.. GET IT OUT!!

    anywho..

    Right, so.. how do I get that Additive Particle shader to simply render behind the world geometry, but still in front of the actual skybox?

    Edit: Other information: Taking the render queue on the sphere makes the sphere render in front of the skybox, but also clipping through geometry, which rather implies that the skybox is rendered at 2500.

    However, when I look at the skybox material (which is just a clone of the procedural skybox), it's rendering on 1000..

    Edit 2: No, there are no culling masks on the camera, it's set to render everything.
     

    Attached Files:

    • 1.PNG
      1.PNG
      File size:
      479.9 KB
      Views:
      1,475
    • 2.PNG
      2.PNG
      File size:
      473.4 KB
      Views:
      1,410
    • 3.PNG
      3.PNG
      File size:
      223.8 KB
      Views:
      1,385
    • 4.PNG
      4.PNG
      File size:
      286.1 KB
      Views:
      1,336
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,336
    The render queue set on the skybox shader / material is ignored for any skybox rendered using using the skybox material set in the lighting settings. In scene view it renders first, before anything else (effectively render queue 0), and in Unity 4 and prior it also had this behavior. As of Unity 5 the default skybox is relatively expensive, so it renders between render queues 2500 and 2501 (between the change from opaque and transparent queue ranges). It does so by rendering with a unique transform matrix that centers the sky on the camera scaled by the far clipping plane (so it's as far away as possible). The result is it renders behind anything that's previously rendered to the zbuffer, but if you have anything that's transparent (like your additive particle shader sky gradient) it'll just draw on top of that.

    Here are a few solutions: Draw the skybox yourself, or draw your "background" objects in the transparent queues. The first one isn't so straight forward if you want to use the built in procedural sky shader as Unity uses a specially tessellated mesh that's not available. The second method can be done by just scaling the object you want to be "in the background" large enough, or by using a shader that does the same. Just manually scaling the object is the easier way to go though, as using a shader to scale it can make it hard to select and cause it to disappear when you don't expect it to since the actual object isn't scaled so the camera might cull it when the CPU side things it's out of view.
     
  3. Nyxton

    Nyxton

    Joined:
    Mar 30, 2017
    Posts:
    2
    Really good information here. The solution I went with, however, is using a second camera at Depth -1, that just renders the skybox and gradient. And stars. By the way, there's also stars. The main camera renders Depth Only, with everything but the spheres, so it works out pretty well.

    Turned out pretty well, I think:
     
    Agent0023 likes this.
  4. marcospgp

    marcospgp

    Joined:
    Jun 11, 2018
    Posts:
    194
    Posting here because this is #1 result on Google for "unity how to render object behind everything else"

    I was trying to make this work for hours, but only finally managed to do it by disabling "depth priming" in URP renderer settings.

    Now my shader graph based shader can make objects display behind everything else by disabling depth write.

    I was trying to avoid a second camera by all means due to the added complexity and and likely also computational demand.