Does anyone else think a "Switch" node would be useful?

We have Reroutes and Frames, which I can’t imagine living without. Sometimes I make a material or a composite that has several variations and I find myself disconnecting and later reconnecting a lot of the same sockets. If there were were a node that could cycle through multiple inputs and multiple outputs I imagine it would save time.

An added benefit would be the ability to create materials with multiple user-friendly presets. Numbered slots could optionally show labels as well, for example 1. “Polished” 2. “Unpolished” …that sort of thing.

Wires that are plugged into a channel not currently active could grey out to give user feedback that the switch is set to another channel.

What do you guys think?

1 Like

There is a Switch node in the compositor. That node, however, does not exist for materials.

OMG you’re right - and I’ve seen it before. Well my memory sucks.

Yes, I remember looking at it and wishing it existed for materials too. And wishing the number of inputs and outputs could be increased. Come to think of it, seeing it in the compositor may be the reason I often long for it in materials.

So my post is partially not so valid, but still partially valid. ;-p
Thanks for the correction.

Well, this is open source software … so … did you just “Sign Up?” :slight_smile:

Sounds like an excellent idea to me.

I want a switch node for materials.
plz.

I’ve actually found myself wanting on numerous occasions.

Yeah, I know. I’m no software developer though. I even have terrible luck just compiling pre-written code! lol

not sure what you mean by switch, how about driver control mix node, which you attach at the end of your texture output ?.

Or are you more like
Having a big image with various textures, to display one on a object ?.

In a way you could
just add N material nodes
and simply select the output material you want !

happy bl

Use mix shader for shaders, mixrgb for colors. Admittedly each only offers two inputs.

Something like this might be of use…

There’s another one I saw like that posted by somebody else later on which expounded on the idea and had even more inputs. (I’m ok with that.) Reverse engineering that node group shouldn’t be too hard so it just switches with a value input instead of hitting a threshold in a grayscale range.

A case switch would be better than a binary switch.
Also the ability to switch if a node socket is connected or not.

1 Like

Come to think of it, the node group interface has something like this already : a blank socket is added every time you add an input or an output. There could very well be a switch node using that kind of behaviour.

I wrote a switch node for Cycles in OSL as a very first exercise:

#include “stdosl.h”

shader node_switch(
integer switch = 0,
closure color Closure1 = 0,
closure color Closure2 = 0,
output closure color Closure = 0)
{
if (Switch == 0)
Closure = Closure1;
else
Closure = Closure2;
}

That’s awesome, Gottfried!
I think some of the OSL specifications have changed since then though, because when I tried to run it I got this error:


/var/folders/66/07wk3d016tv8w_953qf5_d440000gn/T/tmpkuv19_oj.osl:4: error: Unknown struct name: integer
Error: "/var/folders/66/07wk3d016tv8w_953qf5_d440000gn/T/tmpkuv19_oj.osl", line 4:
'switch' is a reserved word
/var/folders/66/07wk3d016tv8w_953qf5_d440000gn/T/tmpkuv19_oj.osl:4: error: Syntax error: syntax error
/var/folders/66/07wk3d016tv8w_953qf5_d440000gn/T/tmpjl29u6ds.osl:4: error: Unknown struct name: integer
Error: "/var/folders/66/07wk3d016tv8w_953qf5_d440000gn/T/tmpjl29u6ds.osl", line 4:
'switch' is a reserved word
/var/folders/66/07wk3d016tv8w_953qf5_d440000gn/T/tmpjl29u6ds.osl:4: error: Syntax error: syntax error

So I think the word “switch” can no longer be used. What should I replace it with?

Thanks

@Gottfried:

By some miraculous stroke of luck I seem to have got it working, by capitalizing the S in “switch” and shortening “integer” to “int”.
Don’t ask me why I thought that was the right thing to do, but it compiled successfully! Haha

#include "stdosl.h"

shader node_switch(
int Switch = 0,
closure color Closure1 = 0,
closure color Closure2 = 0,
output closure color Closure = 0)
{
if (Switch == 0)
Closure = Closure1;
else
Closure = Closure2;
}

The irony does not escape me:

Maybe I’m not always so terribly unlucky with code after all.

Now how to add more inputs and outputs on this thing? Hmmm…