Download

Dynamically select parameter name from a collection?

Is there a way to dynamically change which parameter name is being used in a material parameter collection?

Let’s say I have a material and in it I’m referencing a Material Collection that has three parameters: primary, secondary and tertiary. I can manually select which parameter is being used, but is there any way I can change that on the fly?

You can use multiple “if” node inside your material comparing value A with a scalar used to select which parameter you want and each “if” will be connected to a Material Collection with the parameter already set. Not really clean, but will work and of course this will be a completely mess if there are too many parameters to select :-/ but again will work.

Haha yeah, I’ve been toying with something similar. I’ll probably put it into a material function but I was hoping there would be a better way. I’m thinking I’ll probably have 10 different parameters. Not terrible if I put it into a function, but I’m a little nervous about the performance overhead I’d be adding to so many of my materials (I’d be intending to do this all over the place as part of a palette system).

I don’t think it will have any performance issue of using too many "if"s. The possibilities of having 1 material a bit more complex (more instructions, hard to maintain but still 1 material) and several separate materials (less instructions per material but as there are more material means more maintenance work and more GPU memory usage), definitely I would go with 1st choice.

I see that you will use it in a material function (which makes sense) into several materials and in this case, it is even better, because the other possible solution on having several materials with the parameter set would mean even more combinations to care. In any case I will keep an eye on other solutions, but by far without knowing what you are planning to do, makes it harder to go beyond the main question in the 1st post.

I appreciate the feedback! I’ll share some more details in case it inspires other approaches. I’m more-or-less building an archviz tool, and in it nearly every single object can have its color changed. Right now, each object can have a unique, arbitrary color but that gets a little tedious when you want to change the color scheme of an entire space.

So in addition to being able to choose a color, I want to be able to have a selection of user-controlled swatches. The user could assign a seat, a wall, etc. all to the same color swatch (let’s say blue!). They’d all turn blue of course, and then if I change the swatch’s color to red, anything using that swatch would also turn red. It’s a pretty similar paradigm to what’s seen in a lot of graphic design software.

One approach is to have some global swatch entity somewhere and colored objects subscribe to its events. That would work just fine, and it was the approach I was originally taking, but it’s hard to ignore how well suited Material Parameter Collections appear to be for this type of thing, too.

I would tell you to keep an eye for the new feature (still experimental) called Material Layering. It have some other ways of thinking and workflow. It might give you some insights too. Anyway thats the future.