Sub topic 2
The Voronoi Texture node: features, distance metrics, randomness
This chapter assumes you can add nodes in the Shader Editor, link sockets, and read the main inputs of a Principled BSDF. You should also know that a Colour Ramp maps a value from 0 to 1 onto colour stops.
The Voronoi Texture node divides a surface into cells. Each cell contains one random feature point, and the node outputs the distance from each position to the nearest point or edge.
Feature modes
- F1: distance to the nearest feature point. Produces round, blob-like cells.
- F2: distance to the second-nearest point. Subtracting F1 from F2 highlights cell borders.
- Distance to Edge: near zero along cell borders. Use it for cracks and grout lines.
Distance metrics
- Euclidean: round cells.
- Manhattan: diamond-shaped cells.
- Chebyshev: square cells.
Randomness
Randomness at 0 places feature points on a regular grid. Values near 1 scatter them irregularly.
Colour Ramp stops and masks
A Colour Ramp holds stops, each with a position from 0 to 1 and a colour. Interpolation controls how colours blend between stops. Placing two stops close together turns a soft gradient into a sharp threshold, which creates a mask. Moving the stops apart lowers contrast.
Warping coordinates
Feeding a Noise Texture's Color output into the Voronoi Vector input bends the straight cell borders into irregular shapes.
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")
ramp.color_ramp.elements[0].position = 0.0
ramp.color_ramp.elements[1].position = 0.05
links.new(coord.outputs["Object"], voronoi.inputs["Vector"])
links.new(voronoi.outputs["Distance"], ramp.inputs["Fac"])
links.new(ramp.outputs["Color"], bsdf.inputs["Roughness"])Common errors
- Stretched patterns usually come from a non-uniform scale on the object. Apply the scale with Ctrl+A.
- Banding often means the ramp spans too few stops or too narrow a range.
Exercise
Which feature mode and ramp setting produce thin crack lines?
Show answer
Use Distance to Edge, then place two Colour Ramp stops close together near 0 (for example 0.0 and 0.05) so only the thin border zone turns white.