Sub topic 6
The Colour Ramp Node: Stops, Interpolation, and Colour Output
This chapter assumes you can work in the Shader Editor and connect nodes. It also assumes you know the Principled BSDF inputs and have met the Noise and Voronoi Texture nodes. Here you will learn how the Colour Ramp node turns a single number into a colour, how its stops and interpolation modes shape that result, and how to read its outputs without surprises.
What the node does
Noise and Voronoi textures produce grey values between 0 and 1. A grey value alone makes a dull material. The Colour Ramp node (internally ShaderNodeValToRGB, "Value to RGB") is a lookup table. It takes a number on its Fac input and returns the colour stored at that position along a strip.
The strip is defined by stops. A stop is a marker with a position from 0 to 1, a colour, and an alpha value. A new node starts with two stops: black at 0.0 and white at 1.0. Because of those defaults, a fresh ramp passes a grey input through unchanged.
The node has one input and two outputs:
| Socket | Direction | Meaning |
|---|---|---|
| Fac | Input | The value to look up, clamped to the range 0 to 1 |
| Color | Output | The interpolated colour at that position |
| Alpha | Output | The interpolated alpha at that position |
Working with stops
Each stop has three properties you can edit. In the UI you select a stop, then change its Pos field and its colour swatch. In Python the stops live in ramp.color_ramp.elements.
- Position decides where along the 0 to 1 range the stop sits.
- Colour is the RGBA value the ramp outputs exactly at that position.
- Alpha is stored in the colour's fourth component and appears on the Alpha output.
You add a stop with Ctrl+click on the strip, or with the + button. You remove one with the − button. A ramp can hold up to 32 stops.
Three behaviours are worth knowing:
- Values outside the stops are held flat. If your first stop is at 0.35, every input below 0.35 returns that stop's colour. The same holds above the last stop. This flat region is what makes ramps useful for thresholding, covered in the next chapter.
- Stops are always sorted by position. Dragging one past its neighbour swaps their order. In Python, element 0 is always the leftmost stop.
- Stops can share a position. Two stops at the same position make a hard step instead of a gradient.
Why the stop positions matter for noise
A Noise Texture rarely uses the full 0 to 1 range. Its values cluster around 0.5, and a high Detail setting makes the clustering tighter. If you leave the ramp stops at 0 and 1, you see only a narrow slice of the ramp, and the result looks flat and washed out.
The fix is to move the stops inward so they bracket the range the noise actually uses. The first code example in this tutorial puts stops at 0.35 and 0.65, which stretches the middle of the noise across the full colour range. Moving two stops closer together raises contrast. Moving them apart lowers it.
Interpolation modes
The interpolation setting decides how the ramp fills the space between two stops.
| Mode | Behaviour | Typical use |
|---|---|---|
| Linear | Straight blend between neighbouring stops | General-purpose default |
| Ease | Smooth start and end on each segment | Soft transitions without visible creases |
| B-Spline | Smooth curve that does not pass exactly through every stop | Very soft gradients |
| Cardinal | Smooth curve that passes through every stop, and can overshoot | Smooth gradients with exact stop colours |
| Constant | No blending, each stop holds until the next one | Banded, posterised, or layered looks |
Linear shows a visible crease at each stop, where the slope of the gradient changes. Ease and the spline modes hide those creases. B-Spline and Cardinal can also produce colours slightly outside the range of your stops, because the curve overshoots. In RGB mode the node clamps these overshoots to valid values, but the gradient can still look unexpectedly dark or bright near a stop.
Constant interpolation is the only mode that gives hard edges. It is the right choice when you want distinct bands, such as strata in rock or a cell-shaded look. It is also the cause of accidental banding, covered below.
Colour modes and hue interpolation
Above the stops, the node has a colour mode setting: RGB, HSV, or HSL. It controls the colour space used when blending between two stops.
In RGB mode, blending red and green passes through a muddy brown, because the red channel falls while the green channel rises. In HSV or HSL mode, the blend moves through the hue wheel, so red to green passes through orange and yellow.
When you choose HSV or HSL, a hue interpolation option appears, because hue is a circle and there are two ways round it:
- Near takes the shorter way round.
- Far takes the longer way round.
- Clockwise and Counter-Clockwise force a direction.
Use RGB for natural materials such as soil, bark, or skin, where the muddy mid-tones are realistic. Use HSV for rainbow-style gradients and stylised effects.
Colour output and colour spaces
Colours you pick in the ramp swatch are scene-linear values, the same space Blender renders in. The colour picker shows a hex value in sRGB, so a hex code and the RGB numbers in a script are different representations of the same colour. When you set colours from Python, you provide linear values. A linear value of 0.5 looks brighter on screen than a mid grey, because the display applies a gamma curve.
This matters in two ways:
- A ramp that goes from linear 0.0 to 1.0 does not look like an even visual gradient. Mid tones appear lighter than you might expect.
- If you use the ramp output as data, such as Roughness or Bump height, the values are used as numbers, with no gamma applied. That is the correct behaviour for data.
Connecting the Color output to a float input
The Color output carries three channels. When you plug it into a single-number input such as Roughness, Blender converts it to one value by taking the colour's luminance, a weighted average of the channels. For a grey ramp, that is the grey value itself. For a coloured ramp, the result depends on the weights: green counts for the most, and blue for the least. If a coloured ramp gives unexpected roughness, check the luminance of each stop.
The Alpha output
The Alpha output returns the interpolated alpha of the stops. Most beginners ignore it, but it is a handy second channel. You can give a ramp opaque white stops for the colour and use alpha to carry a separate mask. Remember that the ramp's alpha does not make the surface transparent by itself. It is only a number you route somewhere, for example into a Mix Shader's Fac.
Building a ramp in Python
The script below builds a three-stop ramp from noise, using constant interpolation so each band is visible. It sets the first and last stops, then inserts the middle stop with elements.new(). The order matters, because inserting a stop at a position between the two existing ones keeps the indexes predictable.
import bpy
def build_ramp(ramp_node, stops, interpolation="LINEAR"):
"""Configure a Colour Ramp node.
stops is a list of (position, (r, g, b, a)) tuples sorted by position,
with at least two entries. Colours are scene-linear values.
"""
cr = ramp_node.color_ramp
cr.interpolation = interpolation
first, last = stops[0], stops[-1]
cr.elements[0].position = first[0]
cr.elements[0].color = first[1]
cr.elements[1].position = last[0]
cr.elements[1].color = last[1]
for position, color in stops[1:-1]:
element = cr.elements.new(position)
element.color = color
return cr
mat = bpy.data.materials.new("BandedNoise")
mat.use_nodes = True
nodes = mat.node_tree.nodes
links = mat.node_tree.links
bsdf = nodes["Principled BSDF"]
noise = nodes.new("ShaderNodeTexNoise")
noise.inputs["Scale"].default_value = 5.0
noise.inputs["Detail"].default_value = 4.0
ramp = nodes.new("ShaderNodeValToRGB")
build_ramp(
ramp,
[
(0.30, (0.05, 0.03, 0.02, 1.0)),
(0.50, (0.30, 0.18, 0.10, 1.0)),
(0.70, (0.65, 0.50, 0.35, 1.0)),
],
interpolation="CONSTANT",
)
links.new(noise.outputs["Fac"], ramp.inputs["Fac"])
links.new(ramp.outputs["Color"], bsdf.inputs["Base Color"])
obj = bpy.context.active_object
if obj is not None and obj.type == "MESH":
obj.data.materials.append(mat)Run it from the Scripting workspace with a mesh selected. Change "CONSTANT" to "LINEAR" or "EASE" and run it again to compare. If you rerun the script without deleting the old material, Blender names the new one BandedNoise.001. That is normal, and the earlier material stays in the file.
The valid interpolation strings are 'EASE', 'CARDINAL', 'LINEAR', 'B_SPLINE', and 'CONSTANT'. To change colour mode, set cr.color_mode to 'RGB', 'HSV', or 'HSL'. Then set cr.hue_interpolation to 'NEAR', 'FAR', 'CW', or 'CCW'.
Common problems
Banding you did not ask for
Visible steps in a smooth gradient usually mean the interpolation is set to Constant. Check the dropdown first. If interpolation is smooth, the banding may come from the input. A texture with very low Detail, or a low-resolution preview, can show stepped values in the viewport that disappear in a final render.
A flat or washed-out result
The stops probably sit outside the range the input produces. Narrow the gap between them and move them toward the middle, as described earlier.
Colours that look wrong in the middle of a gradient
In RGB mode, mid-tones between two saturated colours become dull. Switch to HSV or add an extra stop in the middle with the colour you want.
A hard edge where a smooth one was expected
Two stops at nearly the same position make a sharp step. Zoom into the strip, or read the Pos values, to find stops that are too close together.
Exercise
A Noise Texture feeds a Colour Ramp with stops at 0.0 (black) and 1.0 (white), and the result looks like a faint grey haze. You want strong contrast between dark and light patches, and a hard edge between them. What two changes do you make to the ramp?
Show answer
Move the two stops inward so they bracket the range the noise actually uses, for example to about 0.4 and 0.6, which raises contrast. Then set interpolation to Constant, or move the two stops very close together, so the transition becomes a hard edge instead of a gradient.
Exercise
You connect a ramp that goes from saturated red to saturated green into Base Color, and the middle of the gradient looks a dull brown. You want it to pass through orange and yellow. Which setting do you change, and to what?
Show answer
Change the colour mode from RGB to HSV (or HSL). Blending then moves through the hue wheel instead of averaging the red and green channels. If it takes the wrong way round the wheel, adjust the hue interpolation, for example to Near or Far.