# Possible to control a Driver from a Group Node input slider?

Sometimes I create Material Groups to be used as appendable reusable assets. Unfortunately sometimes parameters I want to control using a Group Node's slider are not available for routing to a Group Node's input socket. Some examples of these are the Color Ramp and the Mapping Node.

So here's what I want to do:

Can this be done? If so, how?

Thanks!

• All the functionality of the mapping node can be reconstructed fairly easily (you definition of easy math may be different from mine) via some math nodes, color ramp is a bit trickier but I believe it is still possible. Would you be open to such solutions? – PGmath Oct 29 '15 at 14:34
• Could you please add a small example file with the node setup? – batFINGER Oct 29 '15 at 15:12
• @batFINGER You got it! A .blend is now included. – Mentalist Oct 29 '15 at 16:29
• @PGmath I'm certainly curious about how you could do that, and it would be useful. A solution that doesn't vary by node type is ideal (drivers?) - but if that can't be worked out, then at least being able to make something like a color ramp is better than nothing. – Mentalist Oct 29 '15 at 16:40
• @Mentalist The disadvantage to making a homemade color ramp is that it would have a set number of color swatches, and you obviously can't make the nice graphical display etc. But if you are just controlling it via a group socket neither of those should matter. The homemade mapping nodes, on the other hand, is extremely useful, even for normal use. I'll work on an answer showing those two, if you can think of any other similar nodes I can try to make them from scratch too. – PGmath Oct 29 '15 at 17:44

As far as I know, I don't think it is possible to drive a Color Ramp or Mapping nodes from another socket (but I am not super experienced in drivers). However I have managed to re-create the color ramp and mapping node with math nodes, which you can plug inputs into directly.

## Color Ramp

Unfortunately there is no way to create a group node exactly like the Color Ramp, with addable and removable color swatches. To get around this I have created a node with two movable swatches, you can then combine multiple of these nodes together to have the functionality of multiple swatches.

### The theory:

The two input colors are plugged directly into a Mix RGB node. The two Pos inputs need to be sent through a function and plugged into the mix factor. The position of the first swatch needs to be mapped to $0$ to get just the first color out of the mix node. The position of the second swatch needs to be mapped to $1$ to get just the second color out of the mix node.

### The math:

Here's a graph to visualize what we are trying to do, on the x-axis is the input factor of the color ramp, on the y-axis is the desired output, $a$ and $b$ are the positions of the two swatches.

With some simple algebra we can find the equation of the line to be:

$$y = \frac{1}{b-a}x + \frac{a}{a-b}$$

The math nodes below are simply replicating this equation. The final Add node also has Clamp checked to clamp the output to the interval $[0,1]$, which is what the mix node accepts.

## Mapping node

The mapping node has three functions it can Translate (move), Rotate, and Scale the texture. Since often not all of these are needed I will create separate group nodes for each of these functions.

If you don't have a decent understanding about how texture coordinates work you may want to read my answer here. The basic theory of manipulation texture coordinates is to separate the components of the vector with a Separate XYZ node, manipulate the components individually, then combine them back into a vector with a Combine XYZ node.

### Mapping Node - Translation

Translation is easy, to translate $V$ to $V^\prime$ just add the desired amounts to each of the components of $V$.

In the above node setup I actually used Subtract nodes instead of Add so positive values will move the texture to the right instead of left.

### Mapping Node - Scaling

Scaling is the same as translating, just multiply the individual coordinates by the scale factor instead of adding.

### Mapping Node - Rotation

Rotation is a little more complicated and I won't take the time to derive the equations here, but they are pretty standard pre-calc formulas. Here are the formulas for rotation.

Around the x-axis

\begin{aligned} x^\prime &= x\\ y^\prime &= y\cos{\theta} - z\sin{\theta}\\ z^\prime &= y\sin{\theta} + z\cos{\theta} \end{aligned}

Around the y-axis

\begin{aligned} x^\prime &= x\cos{\theta} - z\sin{\theta}\\ y^\prime &= y\\ z^\prime &= x\sin{\theta} + z\cos{\theta} \end{aligned}

Around the z-axis \begin{aligned} x^\prime &= x\cos{\theta} - y\sin{\theta}\\ y^\prime &= x\sin{\theta} + y\cos{\theta}\\ z^\prime &= z \end{aligned}

Note: the first two nodes in each of the rotation setups convert the degree input to radians, which is what the trig math nodes want.

And finally, here's a .blend file with all the above node groups.

• Wow! This is amazing... useful and really fun to play around with too. It's like Xmas on Halloween, haha! You're a genius. Thank you for dedicating your time to make something so cool! I'm going to be twisting vectors around like a madman now. – Mentalist Oct 31 '15 at 8:23
• @Mentalist Glad you like it! But I'm no genius, I just love math! – PGmath Oct 31 '15 at 12:36
• Well, humble sir, I could never have put together something like this. So how about I phrase it as: Thanks for using your talent of math comprehension to share new possibilities with the rest of us! I'm really terrible with math unless I can see it in geometric relationships. I can't take an equation and translate it into something meaningful. So your node setups are like a wheelchair to someone who is mathematically unable to stand on two legs. Ironically though, seeing it as nodes makes more sense than as equations, so I might actually learn something about math from your constructions. – Mentalist Oct 31 '15 at 15:24
• I was trying to consolidate your Rotation X, Rotation Y, and Rotation Z nodes into a single Rotation node with three sliders for X,Y,Z values. However somewhere in the process I seem to have screwed something up because when set at the default 0,0,0 values it is still causing a change in rotation. Would you mind taking a look at my .blend to see what I did wrong, and perhaps show me how these X,Y,Z values could be input through a single Group Node to match the format of the Translate and Scale ones? Thank you! – Mentalist Nov 3 '15 at 17:22
• Never mind my last comment - I realized it's easier to just chain them one after another: X, Y, Z and then group those three groups into a single "Rotate" node. – Mentalist Nov 4 '15 at 20:44