Search Unity

How to get a plane's draw order to the background?

Discussion in 'Shaders' started by dongrout, May 28, 2017.

  1. dongrout

    dongrout

    Joined:
    Nov 22, 2016
    Posts:
    3
    I have a plane and a cube with the top surface the same and their renderings are conflicting with each other. To recreate it, add in a plane with Y=0. Now add in a 1x1x1 cube with Y = -0.5. Change the cube to using a red material and you see the conflict.

    How can I get the plane to draw in the background to let the cube surface show? I've tried downloading the builtin_shaders.zip and making my own Background.shader from the Standard.shader file. In it I set `Tags { "Queue"="Background" "RenderType"="Background" "PerformanceChecks"="False" }` in 2 spots but this doesn't do anything.
     
  2. LukasCh

    LukasCh

    Unity Technologies

    Joined:
    Mar 9, 2015
    Posts:
    102
    This is called z-fighting, I warn it has nothing to do with render order (https://en.wikipedia.org/wiki/Z-fighting)

    What exactly you want to achieve, because I can't really think up good scenario to change standard shader order queue to background. Any way if I remember correctly you can't easily change render queue for standard shader, because we change it through C# editor script (Reason: standard shader has few options "Opaque", "Transparent", "Cutout", that requires overriding render queue). I recommend reading this https://docs.unity3d.com/Manual/SL-SubShaderTags.html, for some render queue knowledge.
     
  3. dongrout

    dongrout

    Joined:
    Nov 22, 2016
    Posts:
    3
    I was thinking that if it would draw the plane first and the draw the cube then the top surface of the cube would show through the plane. But if it really did that, then the whole cube would show, even the part below the plane. I guess a solution would be to cut a hole in the plane to match the cube. The solution I went with was to move the cube up a little so it pokes through the plane.
     
  4. LukasCh

    LukasCh

    Unity Technologies

    Joined:
    Mar 9, 2015
    Posts:
    102
    Glad to hear you found this simple solution of for your issue.

    Any way I wanted to clarify more in depth why it happens:
    - When you render any shapes in 3d space, usually u want them to have correct ordering in z-space (So that objects that are near the camera re not blocked by farther objects). This is achieved by rendering shapes depth too into z-buffer (More info https://en.wikipedia.org/wiki/Z-buffering).
    - However when you have two surfaces that are in the same plane, z-buffering can't really solve which pixel of these surfaces should go first (This phenomena called z-fighting). In nut-shell it happens because of float precision.
    - Also keep in mind that render queue has very little effect on actual object position in space, because as I mentioned before its handled by z-buffer. The cases where render-queue really matters are: when rendering transparent shapes, for optimization reasons, or if u have z-buffer test disabled.