How Do I Control Z Buffer Depth with Immediate Mode Drawing?

Avatar
  • updated
  • Answered

I'm using the following settings:

Draw.LineGeometry = LineGeometry.Flat2D;
Draw.LineThicknessSpace = ThicknessSpace.Pixels;
Draw.LineThickness = 1; 
Draw.LineEndCaps = LineEndCap.None;
Draw.BlendMode = ShapesBlendMode.Opaque;

Is it possible to make immediate mode calls to Draw.Line and reliably control which lines render on top of other lines?

It seems like the order in which I call Draw.Line doesn't effect the Z Depth of the lines drawn.

Reporting a bug? please specify Unity version:
2021.1.0b6 (4f6b2ade48ff)
Reporting a bug? please specify Shapes version:
3.0.0
Reporting a bug? please specify Render Pipeline:
Built-in render pipeline
Pinned replies
Avatar
Freya Holmér creator
  • Answer
  • Answered

Immediate mode draw order will always be the order in which you tell it to draw the lines, so the first Draw.X you call will be furthest back, the last Draw.X you call will be closest/on top

however, Opaque shapes will also write to the depth buffer, so if you draw an opaque line close to the camera, and then an opaque line further behind that line, the closer line will still be on top since it wrote to the depth buffer, so I'm guessing this is what you're seeing! If you want to specifically make sure it's in the order you draw things, then using transparent instead of opaque will do that

Avatar
Freya Holmér creator
Quote from marcus r

Thanks for clarifying Freya, makes perfect sense.

P.S Great job creating Shapes! 

thanks 💖

Avatar
Freya Holmér creator
Quote from marcus r

Thanks for clarifying Freya, makes perfect sense.

P.S Great job creating Shapes! 

thanks 💖

Avatar
marcus r

Thanks for clarifying Freya, makes perfect sense.

P.S Great job creating Shapes! 

Avatar
Freya Holmér creator
  • Answer
  • Answered

Immediate mode draw order will always be the order in which you tell it to draw the lines, so the first Draw.X you call will be furthest back, the last Draw.X you call will be closest/on top

however, Opaque shapes will also write to the depth buffer, so if you draw an opaque line close to the camera, and then an opaque line further behind that line, the closer line will still be on top since it wrote to the depth buffer, so I'm guessing this is what you're seeing! If you want to specifically make sure it's in the order you draw things, then using transparent instead of opaque will do that