Search Unity

Bug? Camera Depth sorting issue when sending to Render Texture

Discussion in 'Shaders' started by alpineboarder, Aug 24, 2018.

  1. alpineboarder

    alpineboarder

    Joined:
    Apr 11, 2013
    Posts:
    15
    Using a plain old camera (no custom projection) and sending it out to a render texture, and something reeaaaly funky is happening to the depth sorting.

    This is what the camera sees:
    Screen Shot 2018-08-24 at 6.23.25 PM.png

    This is what RenderTexture gets:
    Screen Shot 2018-08-24 at 6.23.13 PM.png

    I'm using Metal on MacOS, and had the thought it probably has something to do with the usual ZDepth flip between graphic platforms. So I tried using https://docs.unity3d.com/ScriptReference/GL.GetGPUProjectionMatrix.html ....
    GetGPUProjectionMatrix just turns it into this:
    Screen Shot 2018-08-24 at 6.25.41 PM.png


    I've even tried messing with the shaders taking the RenderTexture to no avail, so my assumption is that this needs to be fixed on the camera projection end of things? Would swapping far and near clip do the trick here? Just a bug? Any help much appreciated !! :confused:

    I'm on LWRP Forward Rendering if that helps!
     
    Last edited: Aug 25, 2018
  2. MSplitz-PsychoK

    MSplitz-PsychoK

    Joined:
    May 16, 2015
    Posts:
    1,278
    RenderTextures have an optional depth buffer. Make sure your RenderTexture has the depth buffer enabled so your objects know who's in front!

    It also wouldn't hurt to make sure your shaders read and write depth values.

    Hope that was it, good luck if it isn't.
     
    Salva_Takuns likes this.
  3. alpineboarder

    alpineboarder

    Joined:
    Apr 11, 2013
    Posts:
    15
    YES that was it!! Turns out you can only get a depth buffer on a render texture by creating it at runtime?? I had it as an asset in the project instead. Very strange, but it's working great now. Thanks a bunch for the insight!! :)
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    I'm confused, depth buffer settings are the third setting on a render texture asset, after the resolution and MSAA.
     
  5. alpineboarder

    alpineboarder

    Joined:
    Apr 11, 2013
    Posts:
    15
    You're right. It turns out I created a "Custom Render Texture" instead of a regular one where that setting is missing :rolleyes: