Thin instances, node material and custom attribute

Here’s a little PG that demonstrates using a custom attribute with instances (this is more a proof of concept than anything else):

https://playground.babylonjs.com/#ZTTZJ3#1

Instances are using the new thin instance support (Use Thin Instances - Babylon.js Documentation) and the custom attribute is used to vary the metallic and roughness properties of the sphere.

A node material is used as the basis material, and a custom NodeMaterialBlock class is created to handle the custom attribute and inject the metallic/roughness values in the workflow. Doing this way instead of creating a PBRCustomMaterial, for eg, is more future proof as no custom shader code is written, only a custom NodeMaterialBlock which is guaranteed to work in future versions.

I think writing such custom NodeMaterialBlock classes could be made easier with some helpers, however. Maybe something that could/will happen in the future!

[EDIT]
Edited to fix the PBR node material after the changes of the design that occurred lately
[/EDIT]

6 Likes

Awesome :smiley: had no idea these features existed!

Hi @Evgeni_Popov ! Is there any other example playground where feeding a material with thinInstance buffer information to get a custom Material working procedurally throughout all the instances?
This one #ZTTZJ3#1 refers to another playground and I can’t seem to get any further clues on that.
Thanks!

Welcome aboard!

No, I don’t think there are others PGs that are extending NodeMaterialBlock.

However, since 5.0 you can now create custom blocks in the NME that should facilitate reuse.

See Node Material Editor Custom Blocks | Babylon.js Documentation

1 Like

Thanks @Evgeni_Popov for the quick response :slight_smile: