Sub topic 7
Turning Patterns into Masks and Adjusting Contrast with Ramps
This chapter assumes you can open the Shader Editor, connect nodes, and read a Principled BSDF. You should also know what the Noise Texture and Voronoi Texture nodes output and what a Colour Ramp's stops and interpolation do. Here you will use the Colour Ramp for a different job. Instead of choosing colours, you will use it to reshape grey values into masks.
Why a ramp is a remapping tool
Noise and Voronoi produce a value between 0 and 1 for every point on a surface. The Colour Ramp node takes that value on its Fac input and looks up the colour at that position along its gradient bar. This lookup is a function: one number in, one colour out.
If the ramp runs from black to white, the function is the identity. The output equals the input, and the pattern looks the same. Moving stops, adding stops, or changing interpolation changes the function, and so changes the pattern. Three common reshaping jobs follow from this:
- Contrast: squeeze the transition into a narrower range so darks get darker and lights get lighter.
- Threshold: make everything below a value black and everything above it white.
- Range selection: keep only a band of values, such as the middle of the noise.
A mask is a grey-scale image that says how much of an effect applies at each point. White means fully applied, black means not at all, and grey means partly. Masks are what you feed into Mix factors, Roughness inputs, and Bump height.
Reading the ramp as a graph
Think of the ramp bar as a horizontal axis for the input value. The colour at each position is the output. Everything left of the first stop takes the first stop's colour, and everything right of the last stop takes the last stop's colour. This clamping behaviour is what makes thresholds work.
Adjusting contrast
Start with a Noise Texture at Scale 5 and Detail 8. Its Fac output clusters around mid-grey, roughly 0.35 to 0.65. Plugged straight into Base Color, it looks flat and washed out.
To add contrast, move the ramp's two stops toward each other. Put the black stop at 0.4 and the white stop at 0.6. Any input at or below 0.4 becomes black, any input at or above 0.6 becomes white, and the 0.2 between them is stretched across the full black-to-white range. The slope of that transition is five times steeper than before, so contrast is five times higher.
| Black stop | White stop | Effect |
|---|---|---|
| 0.0 | 1.0 | No change. Output matches input. |
| 0.4 | 0.6 | Strong contrast. Most noise values land in the range that gets stretched. |
| 0.45 | 0.55 | Very hard contrast. Nearly a threshold with a soft edge. |
| 0.5 | 0.5 | Not possible as a gradient. Stops at the same position give a hard cut. |
Moving both stops together, while keeping their gap, shifts the bias. Pushing both right makes the result darker overall, because more of the input falls into the black region. Pushing both left makes it lighter.
Thresholding with Constant interpolation
A hard-edged mask needs no gradient at all. Set the ramp's interpolation to Constant. The output then jumps between stop colours with no blending.
With two stops, black at 0.0 and white at 0.55, every input below 0.55 becomes black and every input at or above 0.55 becomes white. Moving the white stop is now a threshold slider. A higher value leaves fewer white islands. A lower value floods the surface with white.
You can get similar results with a Linear ramp whose stops are very close together, such as 0.54 and 0.56. The difference is how the edge is rendered. Constant gives a perfectly sharp, aliased edge. A close Linear pair gives a thin gradient that anti-aliases better and gives bump mapping something smooth to differentiate.
Selecting a band of values
Sometimes you want only a ring or ribbon of the pattern, such as the contour lines of a noise field. Use four stops:
- Black at 0.0.
- White at 0.45.
- White at 0.55.
- Black at 0.56.
Values below roughly 0.45 are dark, values from 0.45 to 0.55 are white, and values above 0.56 are dark again. The output is a band that follows the noise's contour at mid-height. To add a stop, Ctrl+click on the ramp bar. To delete one, select it and press the minus button.
Adding more stops lets you build several bands, each with its own colour. This is a common way to turn one noise into a layered strata look without any other nodes.
Using the Voronoi Distance to Edge output as a mask
The Voronoi Texture's Distance to Edge feature gives a value near zero along cell borders and rising toward the cell centre. That is already crack-shaped. The ramp just chooses how thick the cracks are.
With a ramp of black at 0.0 and white at 0.05, only the thin zone close to the borders is dark. Everything beyond 0.05 clamps to white. Widening the white stop to 0.1 doubles the width of the cracks. The stop position directly sets crack width in units of cell size.
Be aware that Distance to Edge values are small. A typical cell yields numbers up to about 0.5 or less, not up to 1.0. If you leave the ramp at its default 0 to 1 span, the whole pattern stays dark and cracks look huge and blurry. Move the white stop to something like 0.05 to 0.15 to bring the output into a useful range.
The same idea in Python
The next script builds a crack mask from Voronoi and routes it into both Roughness and a Bump node. Running it creates a new material named VoronoiCracks. It assumes you run it from Blender's Scripting workspace.
import bpy
mat = bpy.data.materials.new("VoronoiCracks")
mat.use_nodes = True
nodes = mat.node_tree.nodes
links = mat.node_tree.links
bsdf = nodes["Principled BSDF"]
coord = nodes.new("ShaderNodeTexCoord")
voronoi = nodes.new("ShaderNodeTexVoronoi")
voronoi.feature = 'DISTANCE_TO_EDGE'
voronoi.inputs["Scale"].default_value = 4.0
ramp = nodes.new("ShaderNodeValToRGB")
cr = ramp.color_ramp
cr.elements[0].position = 0.0
cr.elements[0].color = (0.0, 0.0, 0.0, 1.0)
cr.elements[1].position = 0.05
cr.elements[1].color = (1.0, 1.0, 1.0, 1.0)
bump = nodes.new("ShaderNodeBump")
bump.inputs["Strength"].default_value = 0.8
links.new(coord.outputs["Object"], voronoi.inputs["Vector"])
links.new(voronoi.outputs["Distance"], ramp.inputs["Fac"])
links.new(ramp.outputs["Color"], bump.inputs["Height"])
links.new(ramp.outputs["Color"], bsdf.inputs["Roughness"])
links.new(bump.outputs["Normal"], bsdf.inputs["Normal"])Reading this as a mask: the ramp output is black on the cracks and white on the cell faces. Feeding it to Roughness makes the cracks perfectly glossy (roughness 0) and the faces fully rough (roughness 1). That is often backwards for real cracks, which tend to be rougher or darker. You can invert the mask with a second ramp (white at 0.0, black at 0.05), or by swapping the two stop colours.
Inverting and combining masks
Two small habits save many nodes.
- Invert by swapping stops. Set the first stop to white and the second to black. No Invert node is needed.
- Narrow a mask without touching the pattern. Move one stop. The pattern node upstream stays the same, so you can adjust coverage and keep the same shape.
A mask often needs to feed several places. One ramp output can connect to many inputs. In the script above the single ramp output feeds both Roughness and Bump. Doing this keeps all effects aligned: cracks that darken the colour also deepen in the bump, because they come from the same data.
When two effects need different widths, use two ramps from the same Voronoi output. For example, a thin ramp (stop at 0.03) for deep cracks and a wider ramp (stop at 0.12) for a subtle stain around them.
Colour space and the Non-Color caveat
A ramp outputs colour, even when you use it as a mask. That is fine for Roughness, Mix factor, or Bump height, which accept a grey value. Blender converts colour to grey using luminance when you plug a colour socket into a float socket. For pure grey ramps, black to white, this conversion returns the same grey you set.
The trap appears when you place coloured stops in a ramp that also drives a numeric input. A brown stop becomes a luminance value, so the numeric result is not obvious. If a ramp feeds a numeric socket, keep its stops grey.
Procedural nodes do not use image colour spaces, so you do not need to set Non-Color as you would for an image texture. The caveat applies only if you bake the mask to an image later. Then the saved image must use Non-Color, or its values will be changed when it is read back.
Common mistakes
| Symptom | Cause | Fix |
|---|---|---|
| Mask is solid white or solid black | Stops sit outside the range the input actually produces | Preview the Fac output. Put the stops inside its real range. |
| Mask edge looks jagged or sparkles | Constant interpolation on a high-frequency pattern | Use two close Linear stops instead. |
| Cracks appear far too wide | Distance to Edge left at a 0 to 1 ramp | Move the white stop to 0.05 to 0.15. |
| Changing the ramp has no visible effect | Ramp output is not connected, or the viewport is not in Material Preview or Rendered mode | Check the link and the shading mode. |
| Mask is the opposite of what you wanted | Stops are in the wrong order | Swap the stop colours. |
A fast way to find the real input range is to connect the pattern's output straight to the Material Output through an Emission shader and look at it. You can also temporarily set the ramp to black at 0.0 and white at 1.0, then watch where the grey values sit.
Exercises
Exercise
A Noise Texture's Fac values mostly fall between 0.4 and 0.6. You connect it to a ramp with a black stop at 0.0 and a white stop at 1.0. The result looks flat grey. What two stop positions would give a full black-to-white contrast, and why?
Show answer
Put the black stop at 0.4 and the white stop at 0.6. Values at or below 0.4 clamp to black, values at or above 0.6 clamp to white, and the 0.2-wide band in between stretches across the whole output range. The original ramp used only a small slice of its range, so the output stayed near mid-grey.
Exercise
You want a hard-edged mask where 30 percent of a surface is covered by a Noise pattern, and you plan to use that mask to drive a Bump node. Which interpolation setup do you choose, and why?
Show answer
Use two Linear stops placed close together, for example 0.49 and 0.51, instead of Constant interpolation. The short gradient gives Bump a slope to work with and anti-aliases cleanly. Then adjust the stop positions together until about 30 percent of the surface is white. A Constant step has a slope at only one point, so it gives noisy or empty bump results.
Exercise
A Voronoi Distance to Edge output feeds a ramp with stops at 0.0 (black) and 1.0 (white). The cracks look wide and blurry. What is wrong and how do you fix it?
Show answer
Distance to Edge returns small values, mostly under about 0.5, so the 0 to 1 ramp leaves most of the surface in dark-to-mid grey. Move the white stop to about 0.05 to 0.15. This makes only the narrow zone near cell borders dark, which gives thin, sharp cracks.