Using custom attribute with material plugin

When making a material plugin, is there a way to make use of a custom attribute? I looked in the examples and linked BJS classes in the material plugin documentation but it seems none of them are using a custom attribute…

So here’s my attempt to get this working in a simple PG where the box should be red if the attribute is working. Anybody know where I went wrong or if it’s supported? Thanks! :slight_smile:

Update: it seems one way to make it work is to assign a customShaderNameResolve function to the material like on the updated PG below. I still wonder if there is or should be a way to do it through the plugin class thou? Maybe could add a getAttributes function? :thinking:

You are totally correct, currently material plugins do not support custom attributes.

I think it would be a tiny addition to plugins making them even more powerful. Do you want to try and do a PR for it ? or I can do it ?

Okay I’ll give it a go in the morning. :+1:

1 Like

Nice !!!

1 Like

Okay here’s a little PR for it. :slight_smile:

And also here’s the test PG using it:


Hmm now that I’m using this more, I’ve found the need to be able to use the mesh to help decide what attributes to use with the plugin. Was thinking it would be good to pass the mesh in but now seeing how prepareDefines passes both the scene and the mesh, I guess it would be good to pass both to getAttributes as well in case the scene proves useful as well? :thinking:

I am not seeing any issues by doing so here :slight_smile:

Sweet here’s the new PR for it. :beers:

And for the test PG I just added code to log the scene and mesh for a quick test for now. :slight_smile: