Shader on instances and alpha


I’m trying to have identical models but some of them depending on position will be semitransparent.

I got this is NodeMaterial all works great, except depth order.


cube.material.needDepthPrePass = true;

My elements are wrongly organized:

and in version 5 acts as a cutting out mask:


What do I do wrong? I will like to have this ordered and with alpha and discharge working In BABYLON 4.2.

Here is the example PG:


Can you share the non working version?

Adding @Evgeni_Popov

You should remove the needDepthPrePass = true flag and set BABYLON.Mesh.INSTANCEDMESH_SORT_TRANSPARENT = true; to fix the sorting order. Note this latter flag is new in 5.0, however, it won’t work in 4.2

Hi @Evgeni_Popov

Thanks for this but do you have something working for 4.2? Cause it should be also possible?

The PG is not a working version. Surprisingly at some point, I was unable to reproduce 1 image but it’s actually the PD I shared. After adding and removing the line with depth sort It was sort of fixed and then never returned back for some reason.

This is annoying because you still in alpha with version 5. Any plans on when you will go out of alpha?

Also, go a bonus question. How can I use this to whole mesh? The transparency even if part of it is affected?

I do not get how - Instances Block “instance” works. Will this select the whole mesh or something? Can’t find a PG with a use case of this at all.

I just want to make this shader have alpha, this is hard to believe that this will be a problem. Is there any other way to do it?


Transparency is a hard problem, see Transparent Rendering | Babylon.js Documentation

Before 5.0, the (transparent) instances could not be sorted so the meshes could be drawn in a wrong order depending on the camera. There’s no way around that in 4.2.

Removing the line is not enough when you test in the Playground, as it is a static value it will retain its latest value from one run to another: you have to set it explicitely to false or true.

Babylon 5.0 release is not coming before some months but we don’t know the date yet.

The rendering order fixed in 5.0 can be overcame by using clones instead of instances: clones are correctly sorted in 4.2

I do not think this is an option cause I got from 200 to 600 clones depending on the scene.

OK. I will try v5 and let you know.