Color instance buffer not working with instanced Node Material?


I can’t seem to set the colour of meshes that are instanced using a Node Material and I am unsure why. Changing the sphere material to a Standard Material in the below playground makes everything work as instended so I think it must be the node material? This is my first foray into Node Material creation so I’m assuming I am doing something wrong in the Node Material setup that is causing the colour to be overriden?

I can see the colour apply for a split second as seen in the attached video…

Playground with an example

Many thanks :slight_smile:

Hello there! The brief moment where you saw the colored spheres was when they were using the Standard Material before being overriden by the Node, and to use instance colors with it you just need to rename the buffer to instanceColor, and use the same name node as a input in your node material: Node Material and Instances | Babylon.js Playground ( :smiley:

If you want to learn more about instances and node materials, I recommend keeping an eye on our medium page Babylon.js – Medium as @PatrickRyan is going to post soon a super interesting story about how to create variations in instances using node materials :smiley:


Thank you so much for that! I will definetly keep an eye on that Medium page :slight_smile:

Unfortunately, within our project the meshes only appear white and do not respond to their color being changed :thinking:

I can’t see why it would behave differently in our project vs the PG.
Our instance is setup like so,

setupMaster: (master) => {
    master.receiveShadows = true;
    master.doNotSyncBoundingInfo = true;
    master.alwaysSelectAsActiveMesh = true;
    master.registerInstancedBuffer("instanceColor", 4);
    master.instancedBuffers.instanceColor = new Color4(1, 1, 1, 1);
  setupInstance: (instance) => {
    instance.instancedBuffers.instanceColor = new Color3(0, 0, 0);

and colour changes are applied when needed via

setColor(color: Color3, brightness = 0) {
    const col = this.cellMesh.instancedBuffers.instanceColor as Color3;
    col.set(color.r + brightness, color.g + brightness, color.b + brightness);

Ah! I managed to get this to work by feeding the mesh color into the PBR node’s baseColor input. Not sure if this is the correct way to solve this however :smile:

1 Like

No worries, this is a correct way of passing instance color to affect PBR color :slight_smile: You can make it even simpler as there’s no need for the ColorMerger node (Vectors and Colors are the same thing underneath, we only have the different nodes for convenience):


Aaand you can check the Medium now, Patrick posted and he shows another way where you can use this instanceColor to look up different textures for the same node material!

Creating Variations in Instances Using Node Materials | by Babylon.js | Jan, 2023 | Medium