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

Disabling z-testing?

Discussion in 'UGUI & TextMesh Pro' started by bluescrn, Dec 5, 2014.

  1. bluescrn

    bluescrn

    Joined:
    Feb 25, 2013
    Posts:
    628
    Hi,

    I noticed that I had to set my UI camera to clear the depth buffer, when rendering a canvas on top of a 3D scene, for a HUD. In this case, a full z-clear seems wasteful.

    Modifying the UI-Default shader to keep z-testing turned off works around this - but have I missed a less hacky way to control the 'unity_GUIZTestMode' parameter in the default shader?

    I'm using the 'Screen Space - Camera' render mode
     
  2. phil-Unity

    phil-Unity

    Unity UI Lead Developer Unity Technologies

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    What exactly are you trying to do. Is there a reason your using Screen Space - Camera to render when it seems you want everything to render above everything else anyways, in which case Screen Space - Overlay is what you want.
     
  3. bluescrn

    bluescrn

    Joined:
    Feb 25, 2013
    Posts:
    628
    I'm using 2-3 cameras to render 2-3 'layers' of UI (very back/behind 3D content, main layer, dialog layer). This was originally set up for NGUI.

    But I'm also rendering specific cameras to rendertextures to generate a blurred capture of specific layers - for example, to blur out the game+HUD behind a pause menu, or the scene+UI behind a pop-up dialog - and I'm not sure I could do that, or do it so easily, with multiple overlay canvases?
     
  4. phil-Unity

    phil-Unity

    Unity UI Lead Developer Unity Technologies

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    No with the render textures you'd need to do it with the camera canvas.

    For some reason i'm having trouble picturing what the issue you're seeing is when you dont clear the depth buffer. As long as the cameras are ordered properly depth wise i would have thought you should get proper results.
     
  5. bluescrn

    bluescrn

    Joined:
    Feb 25, 2013
    Posts:
    628
    When I don't clear the depth buffer, the UI elements overlaid on top of the 3D scene (using a separate orthographic camera) wasn't appearing, it 's testing against an inappropriate depth buffer (from the 3D scene camera) and failing the depth test.

    Adding an extra 'clear depth only' to the 2D UI camera obviously fixes it. But as this UI doesn't need any depth testing, it's more efficient to disable the depth testing entirely for the UI.

    It's not a big issue, as there's workarounds (editing the shader/using a custom shader) - It just wasn't immediately obvious why my UI wasn't rendering, and I was a little surprised that the default UI shaders were doing z-testing.
     
  6. phil-Unity

    phil-Unity

    Unity UI Lead Developer Unity Technologies

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    well its only doing z-testing for canvas that are drawn by the camera as there is always a chance that the user wanted to put 3D elements on top of the UI canvas (even more so for world space canvas's). Id go with your work around :)