Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Render 3D object behind all others

Discussion in 'General Graphics' started by Blueknight1758, Feb 3, 2016.

  1. Blueknight1758

    Blueknight1758

    Joined:
    Jul 27, 2013
    Posts:
    13
    I'm creating a space game and have created various objects i want to be in the background without the object itself being ridiculously large. I've achieved this by putting them on a seperate layer and using a seperate camera to render them which works great but when I add normal objects they sometimes appear behind the background objects.
    This is caused by the background camera being closer to the background objects then the main camera is to the normal objects. It can be fixed by making the background objects really large but I would like no to do that as it causes other issues. Is there a way to fix this?



    I want the black object to render behind the white 'space station'
     
  2. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    I must not understand the logic of multiple cameras and layers to control depth for 3D objects.
    So since I don't understand this question might seem silly.

    Why not just scale the objects to the correct size and set there z depth to the correct distance away from the camera - to control the size and render order of the 3D objects - with one camera?
     
  3. Blueknight1758

    Blueknight1758

    Joined:
    Jul 27, 2013
    Posts:
    13
    That would work. But we're talking distances of a few thousand units here. So would result in a huge camera clipping distance. Also very large objects seem to have strange artifacts on them from lighting so I'd like to avoid that.
     
    theANMATOR2b likes this.
  4. smd863

    smd863

    Joined:
    Jan 26, 2014
    Posts:
    292
    You need to have your foreground (i.e. second) camera's clear option set to depth-only, then everything rendered with the foreground camera should appear in front of everything rendered by the background camera. If you don't clear the depth, you will get comparisons between depth-values from completely different scales being compared and errors with which objects should be obscuring each other.
     
    theANMATOR2b and Blueknight1758 like this.
  5. Blueknight1758

    Blueknight1758

    Joined:
    Jul 27, 2013
    Posts:
    13
    That works, the camera was set to not clear anything. I really should of known. Thank you very much.