Search Unity

Getting confused with z-buffer/rendering order

Discussion in 'Editor & General Support' started by JMab, Feb 11, 2014.

  1. JMab


    Nov 29, 2013
    Getting myself thoroughly confused here.

    I have 4 groups of "things" in my game:

    1) Environment (architecture and terrain) and items (weapons, clothing, loot, etc)
    2) Characters
    3) Selection indicators (quads with transparent circles, rendered at the feet of the selected characters and spell radius indicators, etc)
    4) GUI

    I want to render the selection circles "clipped" by the characters (i.e. the rendering of the selection circle performs a z-test, so the circle parts behind the legs are not rendered).

    I also want to render the selection circles "not clipped" by the environment.

    That's it.

    Here's a small screenshot of what I've currently got:


    The selection circle is correctly clipped by the character's legs, but incorrectly clipped by a sloping bit of cave floor.

    I've got 4 cameras in my scene, for the 4 different groups of items above - the GUI camera is orthographic and renders last, the other 3 are perspective and parented to the same game object.

    I've tried a number of ZTest and ZWrite shader combos for the selection circles, and camera depth settings, but I just can't get the desired result.

    Anyone cracked this problem, or have a pointer?

    Thanks in advance!
  2. JMab


    Nov 29, 2013
    Oops, never mind, I figured it out:

    0: Draw Environment and Items

    1: Draw Selection Indicators (ztest any, zwrite on)

    2: Draw Characters