InstancedMesh Render Order Issue


I think i’ve come across a renderOrder issue when creating an InstancedMesh from an imported glb file, here’s the resulting image of the seemingly wrongly ordered instanced mesh…


As you can see the furthest back instance is rendering on top of the other instances in front of it… for context I’m simply shuffling the instances forwards so that the back most instance jumps to a position 1 unit ahead of the current front most instance in a loop so they are continuously cycling around while moving forwards…

For further context, I’ve sanity checked and tested by creating the instances from a PlaneGeometry and MeshStandardMaterial (as apposed to using references to the imported glb’s geometry and material) which in effect does not have the same “renderOrder” error and renders the order as expected…

Here’s a pen that demonstrates the issue i’m having…

and here’s a link to the simple .glb (it’s just a plane with custom UV’s essentially) + (the material has transparent set to true)

Would anyone know why the renderOrder of the InstanceMesh evaluates fine when using native geometry and material classes but encounters this issue when creating the InstanceMesh from references to an imported glb’s geometry and material?

The instance material is set to transparent=true and depthWrite=false. And instances are not individually sorted before render.


OK awesome! thanks for the solution @gkjohnson adding the following lines fixed the issue

c.material.depthWrite = true
c.material.alphaTest = 0.99

The material setup in Blender is likely not correct before being exported for use in this way, which may be the root of the cause, Blend Mode is set to Alpha Blend instead of Alpha Clip on the material.

the above two lines fix the issue in runtime. thanks for your insight here!

It’s not an issue for this but would you know if they can be? I did look into per instance render order but couldn’t find anything on the subject.

You can sort the array of instance transformation matrices manually relative to the camera before rendering the scene but that’s all afaik.