How do you control the draw order of billboarded thin instances?

I am trying to use thin instances to render grass. It pretty much works, but what I have noticed is that the camera depth doesn’t really seem to be taken into account with the draw order of the instances.

I suspect this is a problem with my shader material. I’m using a custom shader to handle the billboarding and coloring of the grass, since thin instances don’t seem play nicely with billboarding, but I am not quite sure how to have each thin instance draw to the correct depth, especially with an alpha layer. :thinking:

Any insight would be greatly appreciated. :bowing_man:

You should not enable alpha blending for the ground, as it does not use blending:

This way, it will always be displayed before the grass because the grass is alpha blended (so, it is displayed last and does not write to the depth buffer).

Thank you! I didn’t even notice the problem with the ground draw, but that’s useful to know about, and was probably affecting the “thickness” of the grass without me realizing too.

Unfortunately, it doesn’t seem to affect the problem with the grass instances drawing over each other at the wrong depth.

Some grass instances are getting drawn in front, despite their placement being behind.

This is because the grass does not write to the depth buffer. You would have to sort them back to front to get a proper display, but it would probably take too long to do that on every frame.

What you can try is to enable writing to the depth buffer and discard the pixels when the alpha value is below a threshold:

It’s not perfect because of the billboard mode (sometimes two blades of grass will change their rendering order when they are really close) but it’s not too bad.


Seems perfect to me, that’s exactly what I was looking for and needed to know. Thanks a ton!

  • turn on depth calculations through the material itself.
  • Discard pixels in the shader so that things behind can still paint. Use alpha value to choose when to discard. (Works well here, cause of pixelated style of scene)
1 Like