Sub topic 9
Solid-colour materials
A low-poly model gets most of its look from flat shapes filled with flat colour. This chapter covers how to build those colours in Blender 4.x, how to assign and reuse them, and the mistakes that make a scene look different from what you expected.
It assumes you can add primitives and enter Edit Mode, and that you know the difference between Object Mode and Edit Mode. It also assumes you have applied flat shading from the previous chapter. If you script, you should be able to run a short bpy snippet in the Scripting workspace.
The working model
A material is a data block that describes how a surface reacts to light. An object does not own a material. The object's mesh owns a list of material slots, and each slot points to a material. Each face stores an index into that list.
This gives three layers:
- The material holds the colour and surface settings.
- The slot list on the mesh says which materials are available.
- Each face's
material_indexsays which slot it uses.
Most of the errors in this chapter come from forgetting one of these layers. For example, a face can have the right index while the slot is empty. Or two objects can share a material when you meant them to have separate ones.
Two colours per material
Every material carries two colour settings that are unrelated by default.
- Base Color on the Principled BSDF node. The renderers (EEVEE and Cycles) and Material Preview use this.
- Viewport Display > Color (
diffuse_colorin Python). Solid viewport mode uses this when its colour option is set to Material.
When you create a material in the interface and change the Surface panel's Base Color, the viewport colour stays at its default grey. The model then looks grey in Solid mode and coloured in Material Preview. Set both, and the two views agree. The scripts below do this.
Creating a material in the interface
- Select the object and open the Material Properties tab (the sphere icon).
- Click New. Blender creates a material named
Materialwith a Principled BSDF node and one slot. - Rename it straight away, for example to
Leaf. Names likeMaterial.007are hard to reuse later. - Click the Base Color swatch and pick a colour.
- Expand Viewport Display and set the same colour there.
Use the viewport shading popover (the arrow beside the shading buttons) to check what Solid mode shows. Under Color, Material uses diffuse_color, while Object uses a per-object colour.
Choosing surface values
A Principled BSDF has many inputs. For flat low-poly work you only need to touch a few.
| Input | Typical value | Effect |
|---|---|---|
| Base Color | Your colour | The main surface colour |
| Roughness | 0.8 to 1.0 | High values give a matte surface with no sharp highlights |
| Metallic | 0.0 | Leave at zero, because metal looks dark without reflections |
| Specular IOR Level | 0.0 to 0.5 | Lower values reduce the shine on faces |
High roughness matters more than it seems. A low-roughness surface produces a bright highlight on each flat face, and that highlight can hide the facet's colour. The default roughness is 0.5, so raising it is usually the first adjustment.
Pick colours with restraint. A small palette of four to six hues, with a few lighter and darker variants, holds a scene together better than many unrelated colours. Avoid pure white and pure black for large surfaces, because they leave no room for the lighting to show the facets.
Colour values are linear
Blender stores Base Color in linear colour space. The colour picker's hex field converts from sRGB for you, so a hex value like #2E8B3A looks right in the picker. If you type raw numbers into a script, those numbers are linear. A script value of (0.5, 0.5, 0.5) renders as a lighter grey than you may expect, because the display transform brightens linear mid-values. Start from a picker colour and read its values if you need a precise match.
Creating and assigning a material with Python
This reproduces the interface steps. It creates the material, sets both colour fields, and assigns it to the active object.
import bpy
obj = bpy.context.active_object
mat = bpy.data.materials.new(name="Leaf")
mat.use_nodes = True
bsdf = mat.node_tree.nodes["Principled BSDF"]
bsdf.inputs["Base Color"].default_value = (0.1, 0.5, 0.15, 1.0)
mat.diffuse_color = (0.1, 0.5, 0.15, 1.0) # colour shown in the solid viewport
obj.data.materials.append(mat)The script has a flaw. Run it twice and you get Leaf and Leaf.001, and the object gets two slots. For anything you will run more than once, use a helper that reuses existing materials.
import bpy
def get_material(name, rgba, roughness=0.9):
"""Return the named material, creating it if needed."""
mat = bpy.data.materials.get(name)
if mat is None:
mat = bpy.data.materials.new(name=name)
mat.use_nodes = True
bsdf = mat.node_tree.nodes["Principled BSDF"]
bsdf.inputs["Base Color"].default_value = rgba
bsdf.inputs["Roughness"].default_value = roughness
mat.diffuse_color = rgba
return mat
def assign_single(obj, mat):
"""Give obj exactly one material in slot 0."""
if obj.data.materials:
obj.data.materials[0] = mat
else:
obj.data.materials.append(mat)
obj = bpy.context.active_object
assign_single(obj, get_material("Leaf", (0.1, 0.5, 0.15, 1.0)))Running this repeatedly updates the same Leaf material and leaves the slot count at one.
Several colours on one object
A tree trunk and its foliage can be two objects, each with its own material. That is the simplest approach. When one mesh needs two colours, for example a rock with a pale cap, give the mesh two slots and assign faces to them.
In the interface:
- In Material Properties, click + to add a second slot, then pick or create a material for it.
- Enter Edit Mode and switch to face select mode (press
3). - Select the faces for the second colour.
- Click the second slot in the list, then click Assign.
The faces you did not select keep slot 0, which is the default index. If a face shows the wrong colour, check its index first.
The same idea in Python assigns by face direction:
import bpy
rock = bpy.context.active_object
stone = get_material("Stone", (0.35, 0.34, 0.32, 1.0))
snow = get_material("Snow", (0.9, 0.92, 0.95, 1.0))
rock.data.materials.clear()
rock.data.materials.append(stone) # slot 0
rock.data.materials.append(snow) # slot 1
for poly in rock.data.polygons:
poly.material_index = 1 if poly.normal.z > 0.7 else 0
rock.data.update()This snippet calls get_material from the previous example, so run both in the same Text Editor file. The normal.z > 0.7 test picks faces that point mostly upward. Normals are in object space, so the result is only correct before you rotate the mesh in Edit Mode.
Reuse and sharing
Materials are data blocks, so many objects can point to one material. This is what you want for a forest where every tree uses Leaf. Changing the colour once updates every tree.
Two sharing behaviours cause surprises.
- Linked duplicates.
Alt+Dduplicates an object but shares its mesh. Because slots live on the mesh, the copy shares the materials too. If you later change a slot on one copy, the other copy changes as well. - Normal duplicates.
Shift+Dcopies the mesh, but the new mesh still points to the same material data blocks. Editing the colour changes every user, and there is no warning.
To give one object its own variant, click the number beside the material name. That number is the user count. Clicking it creates a single-user copy named Leaf.001, which you can rename and recolour. For a forest with slightly different greens, make two or three named variants such as Leaf, LeafDark and LeafLight. Do not make one per tree.
You can also set the slot's link to Object in its dropdown. The material is then stored on the object instead of the mesh, which allows linked duplicates to hold different colours.
Common errors
The object is grey in the viewport but coloured in renders. Only Base Color was set. Set diffuse_color too, or switch the viewport to Material Preview.
The object is white or has no colour at all. The material may have use_nodes off, so there is no Principled BSDF. In Python, mat.node_tree is None and mat.node_tree.nodes[...] raises an AttributeError. Set use_nodes = True before touching the node tree.
KeyError: 'Principled BSDF'. The node lookup uses the node's name. In non-English interfaces, or after you rename the node, the name can differ. Look it up by type instead:
import bpy
mat = bpy.data.materials["Leaf"]
bsdf = next(n for n in mat.node_tree.nodes if n.type == "BSDF_PRINCIPLED")
bsdf.inputs["Roughness"].default_value = 0.9A new material appears on every object. You clicked the browse dropdown and picked an existing material when you meant to click New, so all objects share it. Check the user count beside the name.
Faces keep their old colour after reassigning. The face-select step matters. In vertex or edge mode, Assign applies only to the faces that are fully selected. Switch to face mode and confirm the highlighted faces before you click Assign.
Facet colours look washed out or have bright streaks. Roughness is low, or a strong light is hitting the face at a mirror angle. Raise Roughness toward 1.0 and lower Specular IOR Level.
Checking your work
Before moving on, put a small palette on the scene from the earlier chapters. Use Ground for the plane, Trunk for the cylinders, Leaf for the cones, and Stone for the rocks. Switch to Material Preview and confirm that every object has a colour and that no object shows a .001 material name. Open the Blender File view in the Outliner to list all materials and spot duplicates and unused entries.
Exercise
A scene has ten trees made with Alt+D (linked duplicates), all using the material Leaf. You want one tree to be a darker green without changing the other nine. Which steps do you take, and why does editing the colour directly not work?
Show answer
Editing Leaf directly changes all ten trees, because every tree's mesh points to the same material data block. Instead, make the one tree independent. Either use Make Single User > Object & Data for that tree so it gets its own mesh, or set its slot link to Object. Then click the user count beside the material name to create a single-user copy, rename it LeafDark, and set both its Base Color and its Viewport Display colour to the darker green. The other nine trees keep using Leaf.
Exercise
A script runs without errors, but the rock appears pale grey in Solid mode while Material Preview shows the brown you set. What is the likely cause and the one-line fix?
Show answer
The script set only the Principled BSDF Base Color, and Solid mode reads the material's viewport colour. Add mat.diffuse_color = (r, g, b, 1.0) with the same values, and make sure the viewport shading Color option is set to Material.