How to make NME material for thin instances with color attribute?

Heya :slight_smile: I’m trying to use NME to make a material for a mesh with thin instances, but can’t get the color attribute to work.

Here’s a simple NME that uses the instances block and color attribute for example: NME Material

It works well with instances like here: Instances PG

But with thin instances, they’re drawn black like here: Thin Instances PG

The PG’s are simple ones from the documentation with just the material changed to the above NME material. And if you comment out lines 47 and 48 on the Thin Instances PG you can see the color attribute working with the default material.

Not sure if it worked before or if it’s even something that’s supposed to work? Or if not maybe there’s a workaround? :thinking:

PS I tried changing the attribute kind from “color” to “instanceColor” in case it’s related to that recent change but it didn’t help.

Update: I tried the Thin Instances PG with BJS version 4 and it did work then so seems to be a regression… Maybe @Evgeni_Popov can help? :slight_smile: :pray:

or maybe @sebavan ?

1 Like

So I did find a (temp :pray:) workaround from this demo of custom attributes, although it’s not as conventient since the connections to other blocks must be made in code rather than just using NME. :slight_smile:

The god of war weapon demos are broke in v5 too :frowning: :cry:

1 Like

So I did just find a simpler fix at least. Running the below code after loading the NME material seems to work to make the material compatible with the new thin instance attribute “instanceColor”.

const colorBlock = nodeMaterial.getBlockByName("color");
colorBlock.setAsAttribute("instanceColor");
nodeMaterial.build();

cc @sebavan / @cedric: I think we should add automatic support for instanceColor like we did in other materials

@jeremy-coleman:Which demo are you referring to? cc @PatrickRyan as I think this is your weapons demo

1 Like

Yes sorry shoulda linked a pg. It’s Patrick’s weapon demo here (unsure if its the original copy or a fork)
.https://playground.babylonjs.com/#7XU4D8#3

I just did a quick search for “daggerMagicActive” to find all the forks (7 total)

All are the same, except that this one. It gets passed the loading screen, although doesn’t work. It’s probably someone’s failed experiment, but could be useful to compare for debugging. Note: this is not the one that used to work!!
.https://playground.babylonjs.com/#XZK9RB#0

I also noticed patrick’s music vizualizer is broken too! :crying_cat_face: :ocean: :swimming_man:
.https://www.babylonjs-playground.com/#HA3E1B#19

Ohhhhhh this is not related but I ll fix both Demos ASAP

I will also submit a fix for the instanceColor by adding an extra attribute in NME to differentiate from the vertex colors.

Music visualizer: https://www.babylonjs-playground.com/#HA3E1B#27 (a couple new where not in the right place)

Next :slight_smile:

2 Likes

Ok got the one for the god of war demo and it is related to some of our latest tangents changes moving from vec3 to vec4. I ll push a back compat fix for it tomorrow with the instanceColor one :slight_smile:

2 Likes

Both will be fixed by Pull requests · BabylonJS/Babylon.js · GitHub @Blake you ll need to use the instanceColor attribute instead.

3 Likes

I tried the test build for the PR but couldn’t get it working (tried changing the name from “color” to
“instanceColor” but didn’t help). It looks like the changes to serialization are for the other issue so saving from the live NME with the old serialization code should work for testing the color fix right? Thanks! :slight_smile:

1 Like

Here is the fix live: Thin instances simple example | Babylon.js Playground (babylonjs.com)

2 Likes

Aah it uses a different block than instances now, ok thanks! :beers:

2 Likes