Draw order and depth issues with plane instances

I ran into an issue where the draw order of planes gets messed up when using instances. The ones in the foreground of the scene will often appear behind the ones that should be in the background.

In this Playground Example I’m creating a plane with the texture and material I want to have and then create an instance of it for each unit.
You can see the problem described above when moving the camera around.

In the next Playground Example I’m only sharing the texture and material, but am creating a new plane for each unit.
You can see that there are no issues and it is displaying properly.

This might be a limitation of instances, but I feel like it seems more like a bug which is why I’m posting it in this section.
When creating a new plane mesh each time instead of using an instance we’re looking at performance losses, so it would be awesome if this worked with instances.


1 Like

Possibly something to do with transparency and opacity. This way seems to work https://playground.babylonjs.com/#K36J7W#5

This might be worth a read Transparency and How Meshes Are Rendered - Babylon.js Documentation

1 Like

Indeed, it seems instances are not sorted when they have a material with transparency, contrary to regular meshes. I don’t know if it’s a limitation or not - @Deltakosh or @sebavan will know.

The PG from @JohnK does work because it is only using alpha testing and not alpha transparency (the opacity texture has been removed), meaning the meshes are rendered normally, by writing/checking the depth buffer.

1 Like

Instances are meant to be fast so we do not sort them.
I would recommend using the solution from JohnK for sure :slight_smile:

1 Like

Thank you for the answers!
I see it’s not a bug then, but behaving the way it should be.

This is mostly working out, however the planes will be influenced by lighting instead of behaving ‘unlit’.
I changed it up a bit by using both a diffuse texture and an emissive texture which is closer to that, but the contrast is still a bit different :confused:

1 Like