alphaIndex and instancedBuffers

I am trying to use as many instances in my project as possible, but a lot of my meshes need alpha and are not rendered in the correct order even though the order is the same as the z values

I really hoped this would work now that we have instancedBuffers.
Am I missing something, or is it just not meant to be? Is there another way to do this currently?

(toggle useInstances to see how it should look)
https://playground.babylonjs.com/#JYL0LX#5

bonus question: the prototype mesh for the instances is now just set to invisible. Is there a way to get it even more out of the way of all render loops with performance in mind?

In your case you can set material.transparencyMode = BABYLON.Material.MATERIAL_ALPHATEST for the material of the instanced mesh.

It will make it work because the instances will be drawn before the texts (which are alpha blended, so displayed after alpha tested meshes).

However, if you enable alpha blend/transparency on the instanced mesh it won’t work because the instances are all drawn in a single draw call whereas for alpha blended meshes you would need them to be drawn from back to front. So first instance 1, then text 1, then instance 2, then text 2 and so on, which is not possible.

To be sure your master mesh takes up as less ressources as possible, call setEnabled(false) for it.

1 Like

I see, thanks. I think I get how it works now. Alpha blending, instances and draw ordering by depth don’t go together.
Unfortunately, alpha testing is not good enough for what I’m doing :confused: (too ugly).