Transparent placeholder material for submesh - optimized solution?

Hi, I’m using a mesh that I have exported from Blender as a .babylon file that has in total 4 submeshes within it, and I want to use this one mesh with different shaders, each displaying different parts of the main model.
The idea is that 1 submesh will be displayed with every material, and then 1 of the other three submeshes (at different positions on the model) will be shown with another material on it. The other 2 submeshes will be invisible.
Currently im doing this by creating a new standard material, setting it’s alpha to 0, and then using that to fill in the gaps in the multiMaterial array:

const transparentMaterial = new StandardMaterial('testMaterial', scene);
transparentMaterial.alpha = 0;

const multiMaterial = new MultiMaterial(`MultiMaterial`, scene);
multiMaterial.subMaterials.push(mainMaterial, transparentMaterial, moveableMaterial, transparentMaterial);

Im concerned about optimisation, as creating a Standard material for this purpose seems a bit heavy, but i cant leave gaps in the multimaterial array.

Any suggestions on the lightest way to create this invisible placeholder material?
Many thanks :eyes:

Pinging @PirateJC

Hey @Chrisor9 Cool question!

Multimaterial is definitely a way to go with this, but if I were designing this, I’d consider a programatically influenced Node Material (shader). Imagine that every submesh has the same exact material applied to it, but that material has different “branches” that can be executed from your scene code. This includes visibility that you could control with alpha, and also branched logic using the Logical nodes.

As you can guess, this would mean that there would be only 1 single material applied to the submeshes. It would be a single shader that you could influence based on what’s happening in the scene.

So if I were in your shoes, I’d explore the Node Material and its editor for this type of a direction.

https://nme.babylonjs.com/

1 Like