Search Unity

Setting Render Order with UI Canvas and MeshRenderers (Mobile, VR)

Discussion in 'General Graphics' started by Jeff-Rosenberg, Jun 24, 2016.

  1. Jeff-Rosenberg

    Jeff-Rosenberg

    Joined:
    Oct 23, 2012
    Posts:
    26
    I've got a mobile VR game I'm working on where the player controls a mech. The mech's UI-based crosshairs need to be placed at the player's focal point in World Space coordinates so they are 1) useful and 2) don't cause eye strain. Because of the positioning, the crosshairs can become occluded by world geometry. I need a way to render the crosshairs after the player's cockpit and cockpit UI but before the rest of the objects in the scene (environment, enemies, etc).

    I'm having a seriously hard time getting Renderers and Canvases to draw in the right order together.
    • Having the crosshairs use ZTest Off works for the world geometry, but draws the crosshairs on top of the cockpit.
    • Because of my performance constraints I don't think I should use multiple layered cameras.
    • Changing the Sorting Layer on the Canvases only changes the draw order relative to other canvases, so that doesn't help me.
    • Using the shaderlab Offset keyword and a modified UI shader gets me the effect I want, but the offset is different on some Android phones so I can't use that.
    • Material.renderQueue doesn't seem to have any effect on the render order.
    • Renderer's sorting layer only seems to work with some materials (Sprites, ZWrite Off). Since the game uses Unlit shaders I may be able to use this, but Unity's Sprite shader uses frag/vert while my shader uses a surf to recolor the texture.
    I'd prefer not to have many different shaders to maintain, but at this point I'll take anything.

    Imgur album with some screenshots.

    Thanks,
    Jeff
     
    Last edited: Jun 24, 2016