Stepped Gradients in Substance Designer

  • Tuesday, Apr 14, 2020
  • 4 minutes read
teaser image for Stepped Gradients in Substance Designer

I found myself in an increasing need for stepped gradients inside Substance Designer lately, so I evaluated a few methods I could think of for creating them.

You might use them, for example, to build a Color ID map for use in a Multi-Material Blend node.

Method 1: Using a transform node

Using a combination of low-res gradient and transform node with <i>Filtering</i> set to <i>'Nearest'</i>.

Transform Node Method

You start by placing a Gradient Linear 1 and setting its Output Size to Absolute. Lower the Width and/or Height to the number of steps you want to have in the gradient. Unfortunately, doing it this way will bind the number of steps to a power of 2.

Now connect a Transform Node and set its Output Size to either Absolute or Relative to Parent. The important part is to set the Filtering to Nearest to actually get the stepping. You can throw in a Levels or Auto Levels node to make sure the gradient goes from black to white. If you want to add color I recommend placing the Gradient Map before the transform node, so it needs to calculate fewer pixels.

Method 2: Quantize Grayscale

Using a combination a <i>Curve Node</i> and <i>Quantize</i>.

Quantize Node Method

Instead of using a Transform node, you can use the Quantize Grayscale node. This allows you to choose the number of steps freely. But beware, the width of the individual steps can vary! Lowering the resolution of the input gradient is purely for performance. Just remember to choose a higher Output Size for the Quantize Grayscale node. And to top it off, you can influence the width of the individual steps with a Curve node in-between. But it’s not that intuitive to find the right curve to do what you want.
A downside is that the Quantize Grayscale node is considerably slower than the other methods.

Method 3: Pixel Processor

There I was, not satisfied with the transform node method because of the lack of control over the number of steps. And I wasn’t happy with the inaccuracies of the quantization method either. So, on to the next gem!

I hadn’t been doing anything with the Pixel Processor node yet, so this little task was the perfect opportunity to get started. Usually, I start solving these problems by sitting down with a pen and a piece of paper. After a bit of juggling around with the components of the equation I came up with this:

$$v =\frac{\lfloor x*n \rfloor}{n-1}$$

Where \(x\) is the U-position in UV-space and \(n\) is the desired number of steps. \(v\) is your grayscale value. I just added \(n\) as an integer input to the Pixel Processor.

This is fast, precise and you can freely choose the number of steps.

Pixel Processor Method

The graph is a wee bit more complicated than the equation because I added checks for sane values. Surprisingly enough, when \(n\) is 1, the division by 0 doesn’t crash the system. Maybe it’s because of floating-point imprecision. Or maybe the developers didn’t trust me to do the right thing, mathematically speaking.
But now I had it! The freedom of choosing the number of steps continuously with precise output.

You can set #n by either connecting a Value Processor, an Input Value node, or set it up as one of the graph’s parameters and get it in the Pixel Processor’s function.

Bonus: Stepped Cirular Gradient

The Pixel Processor method is superior to the Quantize method, which gives varying widths.

Stepped Circular Gradient

The difference in precision is especially visible when converting the stepped gradients to circular gradients using the Cartesian to Polar Grayscale node.

That’s it! I’m going to step down now.

Creative Commons License
This article is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.
View All Posts


No comments yet. Your comment may be the first.

Leave a comment...

Your e-mail address is used for your Gravatar image only, if applicable. Your address will not be shared or displayed and is encrypted when saved.