Using gradients to twist textures into a spiral

On:

|

, ,

|

Mapping node: What is it?

The Mapping node is super helpful! It lets you transform images by moving their Location, Scale, and Rotation. With other textures and numerical inputs, you can do all kinds of fun distortions to images! I like using it best with generated images, like a Noise Texture or a Gradient Texture.

Along with the Mapping node, we also use the Texture Coordinate node, which lets us decide which coordinate system we’ll use to transform with the Mapping node.

For this image, we’ll use UV space, but all of the other ones have their own uses. Using Object space lets you use the object’s XYZ coordinates for lots of fun effects, and the Camera coordinates let you make a texture more or less lay flat against the camera’s view angle, which can also be super handy for stylized effects!

Node Wrangler

For this, you’ll definitely want to have the Node Wrangler addon! It has tons of really useful features, and for this tutorial, the Ctrl+T shortcut will be super handy, because you can have any texture selected, and press Ctrl+T to create the Texture Coordinate and Mapping nodes automatically set up with your selected image. I usually don’t mix different texture coordinate systems (i.e. do everything in UV, or everything in Object), but you can do some wild stuff with that too.

Mapping types and the Z rotation vector

The different mapping types will yield different transformations. When you have Point selected, for example, Z rotation will always occur form the 0,0 coordinate on the bottom left of the texture space. On the image above, you can see that I rotate the gradient by 60 degrees in the positive direction, using the 0,0 coordinate as its pivot point.

The tricky thing here is that regardless of where you move the image’s location with the mapping node here, it’ll still always rotate with the 0,0 coordinate as the pivot point for Z rotation. This is because when Point is selected, the mapping node is evaluated in this order: Scale –> Rotate –> Translate. Because translation occurs last, you can’t move the rotation pivot point!

And here is with the Texture type selected. Initially, there’s no difference, but the big thing here is that the evaluation occurs in this order: Translate –> Rotate –> Scale. With this, we can move the pivot point 0.5m upwards in the X axis, and 0.5m to the right in the Y axis. By doing that, you put the pivot point in the middle of the UV! Now when you rotate, you rotate around the center!

Okay, but how does this make a spiral?

Because we’ll be using a different sort of gradient for this. Instead of a Linear gradient, let’s switch over to Spherical! With the spherical gradient, we have a linear gradient of values starting with 1 at the very center, and fading out to 0 at the edges.

Remember, White=1, Black=0! With just this information, we are able to tell Blender “Please rotate around this axis, by this much, and have it strongest at the center, and weakest at the border.

Let’s move that pivot point to the center by moving in the X and Y directions by 0.5m, and then let’s plug a checkerboard texture to see what we get!

So first, we create a Checker Texture, and then we set the type of mapping to Texture and move it by 0.5 in the X and Y directions. Then, we’ll need the Separate XYZ and Combine XYZ nodes, because we’re trying to get the gradient to only rotate in the Z axis, but not affect X or Y.

Connect the Combine XYZ node into the rotation for the Checker Texture’s Mapping node, and connect the Gradient Texture’s Color into Separate XYZ, and then Z to Z on the two XYZ nodes. Because we moved both the gradient’s and the checker texture’s pivot points to the center, now the gradient causes a spiral!

Creating a stronger spiral, and rotating the texture without distorting it further

However, this spiral looks a little puny for my taste. It’s only spinning a little bit!

This is where Math nodes come in! For this, we’ll need to connect Multiply and Add (in that order) between the Separate XYZ and Combine XYZ nodes.

Now you can control how much it twists by multiplying the Z value, and then you can rotate the entire texture around its center by adding. The reason for this is that on the gradient texture, we’re multiplying a gradient of values. For example, at the center, we have a value of 1, and we’re multiplying that by 5, so we get a rotation of 5. Near the edges, the value is lower, so instead we’re multiplying something like 0.2 by 5, this getting only a rotation value of 1.

The center looks too big!

Yes it does. Although this does twist the texture, and although more rotation is occurring at the center, the other points in the checker texture that are further away from the center make it so that even small rotation values move them quite far.

To solve that, we’re going to use the gradient for something else, namely Scale! Let’s plug the Gradient Color into a Color Ramp, and then plug that into the vector Scale of the Mapping node for the checker texture. See what happens when we invert it.

At first, by just plugging the gradient as is, we have Scale be closer to 1 the closer it gets to the center, and closer to 0 the further away from the center it gets. When you scale something to 0, it becomes smaller and smaller, while 1 is the default scale value.

When we invert it, instead we make it so that the further away from the center we are, the closer we get to 1, but the closer to the center we get, the closer we get to a scale of 0.

Now, we can play with the color stops and the color values on the Color Ramp. For example, if we select the black stop and change its value from fully black (i.e. 0) to a dark gray (i.e. 0.2), then instead of scaling all the way down to 0 at the center, the image will be scaled only down to 0.2, leading to a less extreme stretch.

You can also move the color stops around to control the progression of the gradient.

Hot tip: You can get the same effect by using the Map Range node instead, and that one even lets you go past values of 0 and 1!

Spiraling other images

Check out what we get if we instead use other image types! My favorite is the Noise Texture.

Noise Texture
Voronoi Texture
Wave Texture

Using Noise for a cooler effect

I really like using a noise texture for this sort of thing, so let’s play around with that a little. We’ll be using some color ramps here to get some cool colors going.

Let’s do a couple things here.

First, set the Noise Texture to 4D. The cool thing about 4D textures is that it gives us a free dimension to play with, which we can animate to get some nice noise variation without having to move the texture in the XYZ coordinates!

Let’s also bring up the detail to 5 and the scale to 3 so that we have more interesting variations between the black and white parts.

And then let’s also bring the two color stops in the Color Ramp closer together so that we get a starker transition between light and dark values. With this, we have our mask ready, where we’ll use its light and dark values to drive visibility.

Hot tip: You can use Shift+P to join a node into a Frame, and then you can rename that frame to more easily label important node groups!

Next, let’s use a second color ramp to create a cool blue color gradient. If we bring the two stops closer together, we can get the lighter part to be near the center of each white island, and the darker parts be at the edges of those islands.

Then we connect the mask and the gradient together with a Mix Color node set to Multiply, and that node connects into a Hue/Saturation/Value node for better control over value and saturation.

This is the basic setup! Now we have a nice-looking, colorful spiral that we can twist and spin however we want, and we get the bonus 4th dimension on the noise texture that we can animate to give us additional random movement.

Now, let’s make the black parts transparent.

Transparent BSDF and Mix Shader

Here, we’ll connect the mask into the Factor of a Mix Shader node. If we connect a Transparent BSDF shader on the first input and our colors into the second input, we make it so that the black parts (i.e. 0) correspond to transparency, and the white parts (i.e. 1) correspond to our colors!

Now, if you tweak the mask, you’ll change how much of the image is transparent, and how much is opaque without disturbing the color gradient.

I don’t like that you can see the edges of the flat plane!

Neither do I. Let’s fix that. To fix it, we’ll go all the way back to our gradient texture, and use some more math.

You can add reroutes with / with Node Wrangler! It makes things a lot clearer.

First we pull out a link from the color of our gradient, and then connect it to a Color Ramp, which we then connect to a Multiply math node. We also connect our mask to that node, and then connect that back into the Factor of our Mix Shader.

We then move the color ramps closer together so that we remove the edges of the UV, but preserve the center.

What we’ve done here is that we’re multiplying everything that is far from the center by 0, so no matter the value it was before on the mask, it’ll turn to 0. Similarly, we multiply values closer to the center by 1, so that whatever value they were before remains preserved. For example, if at a certain point in the spiral mask there was a value of 0.8, where it’s mostly opaque but a little bit transparent, if it’s closer to the center, it’ll get multiplied by 1, but if it’s further away, it’ll get multiplied by a smaller value, like 0.2, getting us a final value of 0.16 instead.

Animating the spiral

Now that we have this set up, we have a few different values we can play with! The main ones will be:

Math Add
W value on a 4D noise texture

The Math Add node and the W value on the 4D texture.

By animating the Add value, we can rotate the entire texture all at once, making it spin around its pivot point.

By animating the W value, we move the 4D texture in a 4th dimension, which will essentially make white and black portions appear and disappear, giving the impression of a fluid movement.

And if you want to animate the texture fading out, you can add a Math Multiply node just before the Mix Shader Factor so that we can animate that value going from 1 to 0.

Recap

So with all this, we’ve created a setup that allows us to:

  • Twist any image at the center
  • Spin any image at the center
  • Scale any image towards the center
  • Fade out any image

Here’s a download link to the .blend file, if you’d like to play around with it yourself!

Posted by

in

, ,

Leave a Reply

Your email address will not be published. Required fields are marked *