Sub topic 9
Layering Patterns with Mix and Math Nodes
Assume you can navigate the Shader Editor, create a material, and connect a Noise Texture or Voronoi Texture to a Principled BSDF. This chapter uses those skills to combine several procedural patterns into one material.
A single texture often looks too uniform. Layering means combining patterns so each one controls a different part of the result. For example, one Noise Texture can create broad colour variation, while a second pattern adds small dark spots. Math nodes control numeric values, and Mix nodes blend colours or shaders.
How pattern layering works
A procedural texture produces values, colours, or vectors. You can send these outputs into other nodes before they reach the material.
A Mix node blends two values using a factor:
- A factor of
0uses the first input. - A factor of
1uses the second input. - A factor between them blends both inputs.
A Math node performs an operation on values. Useful operations include:
MULTIPLYcombines masks. Both masks must be strong for the result to be strong.ADDincreases a value by adding another pattern.SUBTRACTremoves one pattern from another.MAXIMUMkeeps the stronger value from either pattern.LESS_THANorGREATER_THANcreates a sharp threshold.
The following graph combines broad noise with a Voronoi-based spot pattern.
Use masks to control where a pattern appears
A mask is a value that describes an area. Black usually means “off” and white means “on.” A Colour Ramp can turn a soft texture into a mask by placing its colour stops close together.
For example, set the first ramp stop to position 0.45 and the second to 0.5. Values below that range become dark, and values above it become light. This creates spots or patches instead of a smooth gradient.
You can then multiply this mask by another Noise Texture. The spots will appear only where the noise also has a high value. This produces less regular results than using the Voronoi pattern by itself.
Mix colours and combine masks
Use a Mix Colour node when you want one pattern to choose between two colours. Connect the mask to its Factor input. Connect the dark and light colours to the two colour inputs.
Use a Math node when you want to combine numeric masks before using them. For instance:
- Create a broad Noise Texture.
- Create a Voronoi Texture with a cellular feature.
- Remap the Voronoi output with a narrow Colour Ramp.
- Multiply that mask with the noise value.
- Connect the result to the factor of a Mix Colour node.
The mask now controls where the second colour appears. This method works for rock, rust, mud, paint, and cracked earth.
import bpy
material = bpy.data.materials.new("LayeredProcedural")
material.use_nodes = True
nodes = material.node_tree.nodes
links = material.node_tree.links
nodes.clear()
output = nodes.new("ShaderNodeOutputMaterial")
bsdf = nodes.new("ShaderNodeBsdfPrincipled")
coord = nodes.new("ShaderNodeTexCoord")
noise = nodes.new("ShaderNodeTexNoise")
voronoi = nodes.new("ShaderNodeTexVoronoi")
ramp_base = nodes.new("ShaderNodeValToRGB")
ramp_mask = nodes.new("ShaderNodeValToRGB")
multiply = nodes.new("ShaderNodeMath")
multiply.operation = "MULTIPLY"
mix = nodes.new("ShaderNodeMixRGB")
mix.blend_type = "MIX"
noise.inputs["Scale"].default_value = 2.5
voronoi.inputs["Scale"].default_value = 8.0
ramp_base.color_ramp.elements[0].color = (0.04, 0.015, 0.005, 1)
ramp_base.color_ramp.elements[1].color = (0.45, 0.18, 0.03, 1)
ramp_mask.color_ramp.elements[0].position = 0.35
ramp_mask.color_ramp.elements[1].position = 0.5
mix.inputs[1].default_value = (0.02, 0.01, 0.005, 1)
mix.inputs[2].default_value = (0.5, 0.2, 0.03, 1)
links.new(coord.outputs["Generated"], noise.inputs["Vector"])
links.new(coord.outputs["Generated"], voronoi.inputs["Vector"])
links.new(noise.outputs["Fac"], ramp_base.inputs["Fac"])
links.new(voronoi.outputs["Distance"], ramp_mask.inputs["Fac"])
links.new(noise.outputs["Fac"], multiply.inputs[0])
links.new(ramp_mask.outputs["Color"], multiply.inputs[1])
links.new(multiply.outputs[0], mix.inputs[0])
links.new(mix.outputs[0], bsdf.inputs["Base Color"])
links.new(bsdf.outputs["BSDF"], output.inputs["Surface"])
bpy.context.view_layer.objects.active.data.materials.append(material)This script builds the graph from empty nodes. Select an object before running it. If the result is too busy, reduce the Voronoi scale or move the mask ramp stops farther apart.
Common layering errors
If the material is almost completely one colour, check the mask range. The mask may be nearly all black or all white. If the result looks washed out, an ADD operation may be pushing values above 1. Use MULTIPLY, lower the input values, or clamp the result.
If patterns look stretched, inspect the coordinate source and object scale. Apply the object's scale or use a Mapping node to correct the pattern before combining it.
Exercise
Which Math operation should you use when a second pattern should appear only where both masks are strong?
Show answer
Use MULTIPLY. The result is high only where both input masks are high.