6
$\begingroup$

I'm very new at shaders, so in order to learn what they're capable of I wanted to try and create an effect that is a fair distance away from anything you can do with a single principled BSDF node. I don't quite now how to express this in 3D, so I coded a 2D animation:

a cubic wipe pattern

basically the idea is to draw a series of squares along a line and have them grow each frame until the part of the "screen" behind them is filled with their color. in effect it is a fancy color wipe.

my question is, is there a way to apply this kind of effect to faces using a shader? if so, how would I go about that?

$\endgroup$
2
  • $\begingroup$ Do you specifically want to use a shader? Or can you use other techniques? $\endgroup$ – atomicbezierslinger Jan 20 at 8:59
  • $\begingroup$ With the objective of making the tree as simple as possible for the job you want done.. do you want this, 1 square per face? Or a 2D UV texture? When you say 3D, could you give an idea of the way you would like the effect to be spread across a 3D surface? $\endgroup$ – Robin Betts Jan 20 at 10:01
4
$\begingroup$

I feel like the easiest way to think of this is to have a grid of square gradients and when you use a greater than, you can change the size of the square. Think of it as changing the height that you cut through a pyramid, at the top the cross section would be small but at the bottom, it'll be large.

To make your grid of squares we can do a little bit of vector maths. I'll be using the UV coordinates as this will let you unwrap your cube so each face gets the whole effect. I am scaling the UV coordinates 20x so that we get 20 squares and then breaking it into a grid with Fraction. I then centre each space by subtracting 0.5 and use absolute to make each space symmetrical. This is the easiest way to get a square grid. I then separateXYZ and use a maximum node in order to get our little pyramids for each square.

Making the square grid

If we add a math node set to Less Than at the end, you'll see the threshold will change the size of all the squares. To make this wipe down like your animation, we need the threshold value to be a gradient.

Branch off from the Scale node and add a separateXYZ followed by a math node set to snap. Take the Y socket into the math node and set the increment to 1 (this is to match the fraction node which also repeats at 1).

Gradient

We now have a gradient and that we can manipulate to control the animation. To change the position of the gradient, add a math node set to subtract, and then follow that with another math node, set to multiply. The multiply will act as the falloff control. Use a small number like 0.1 for now. If we plug this into the threshold of the Less Than node, you'll see the square gradient how you want. You can change the subtract value to move the transition up and down.

Gradient Squares

Finally, to animate the sequence, we need to bring the frame number into the shader. Add a value node and type #frame into the value field. This will create a driver that takes the frame number. We want to have a loop so we're going to add a math node set to modulo. We need to use the loop length twice so add another value node that we can use and plug this into the bottom of the modulo. Set the loop length value to something like 80. Follow the modulo with a map range and plug the modulo into the first value and the loop length value node into the From Max socket. Set the from Min socket to 1. Our To Min and To Max socket slightly depends on a few things such as what scale value we've used and what the falloff is set to and the loop length so the settings for a scale of 20 and falloff of 0.1 are: To Min: 20 To Max: -5 Plug this map range into the bottom of the subtract node to control the position of the wipe.

Final nodes

$\endgroup$
1
  • 1
    $\begingroup$ I'm still working my way through this, but it's very helpful! I'm new to visualizing how UV coordinates work so this exercise is proving quite educational in that regard :) $\endgroup$ – PopKernel Jan 21 at 0:19
2
$\begingroup$

My basic theory was that if we could do it once we could scale it up and give it any number of controls, and if it's based on UVs then it should be able to be applied to anything.

I have just a plane here, I've separated out the UV coordinates and set up some Math -> Compare nodes with a Value node that we can drag back and forth to fill up the square. The square is completely filled at .5, so we're using a Math node to normalize this value between 0 and 1. This is important for later.

enter image description here

So now we can divide up our coordinate space with a Vector Math node set to Modulo, but this actually creates a dependency between the value we divide our plane by, and the values coming out of our separate XYZ node.

enter image description here

We can solve for this by using one value node to drive the whole operation. We divide by this value to do the Modulo operation, and multiply the values from our Separate node to bring back up to the 0 - 1.0 range. At the end our node graph looks like this.

enter image description here

We can make changes to either of these value nodes and see that they are working, the square expands from the center of each box. We also see that whatever maps we send into these Epsilon values are what creates the visual pattern.

enter image description here

Since we've been careful to normalize for values between 0 and 1, we can use the output from almost any of the procedural textures. I've made a few examples here. I recommend trying these inputs and sliders but the possibilities are endless.

enter image description here

The subtract node does exactly what you asked for in the question, I think.

enter image description here

enter image description here

enter image description here

Here's the .blend file.

$\endgroup$
2
  • $\begingroup$ thank you, this is incredibly useful! if I could mark both answers thus far as correct, I would have ;_; $\endgroup$ – PopKernel Jan 21 at 0:17
  • $\begingroup$ It was a well formed question, and a good exercise for me, so I thank you for that. $\endgroup$ – Allen Simpson Jan 21 at 0:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.