base-node (.bn)

Mini moon

A moon two metres across, with about 3,400 craters, from 60 cm wide down to a few centimetres. The craters are scattered on the sphere and dug along its normals, each one measured in the plane of its own normal: the same graph would put them on any surface.

A thin crescent of a cratered moon, lit from behind on the right, on a black background
Where we are going. Five steps, then the phases.

Before you start

This tutorial stands on its own: everything it uses is explained here. It shares two pieces with Lunar ground, the shape of a crater and the dust material. That tutorial builds them more slowly, step by step, on a flat square, if you want to go further.

Every block below is a complete .bn file, its code beside the nodes it builds. You need Blender 5 and the Base Node add-on. Two ways to try a step:

The pictures are rendered from these exact files by render.py, under a sun 75° round the moon from the camera.

1. A sphere of even triangles

Craters must look the same everywhere on the moon, so the surface needs vertices spread evenly. A UV sphere does not have that: its rings of vertices crowd together at the poles. An IcoSphere starts from an icosahedron, 20 equal triangles, and cuts every triangle in four at each subdivision. At 8 subdivisions it has 163,842 vertices, about 7 mm apart on a sphere of radius 1.

step1_sphere.bn: mini_moon

A smooth white sphere, its left part in the dark
Step 1. A smooth sphere. SetShadeSmooth hides the triangles.

2. Where the craters go

A quick way to scatter craters on a flat ground is a Voronoi texture: one crater per cell. On a curved surface, a Voronoi in 3D would cut its cells through the sphere at random depths, and give partial craters. Here we place the crater centres, the sites, on the surface itself, as points.

step2_sites.bn: crater_sites, mini_moon

To see them, this step's mini_moon draws each site as a disc of 1.5 radii, the ground its crater will cover. AlignRotationToVector turns each disc to the stored normal, and the scale gives it its size. Marker is a material that glows, so the discs show on the night side too.

The sphere with nine orange discs lying on it, none touching another
Step 2. The 9 sites of the largest layer, each disc as wide as its crater. No two discs touch.

3. A crater in the plane of its normal

Every vertex of the sphere now asks the sites which one is nearest, and takes its height from that crater alone. First, the shape that height follows.

The shape of a crater

Cut a crater through its centre and you get a curve: a bowl, often with a flat floor, and a raised rim that slopes down to the plain. crater_profile describes this curve once, for a crater of radius 1, with x the distance from the centre counted in radii: x = 0 at the centre, x = 1 on the rim. Any crater is this curve, stretched to its radius.

Graph of height against x: a dashed parabola for the bowl, a dashed horizontal line at -0.6 for the floor, a dashed curve for the rim, and the crater's profile as a thick line made from the three
The profile of crater_profile with its default inputs, and the three curves it is made of.
  1. The bowl, x * x - 1.0: −1 at the centre, 0 at x = 1, above 0 further out.
  2. The floor. A maximum with floor_depth (−0.6) cuts the bottom of the bowl flat.
  3. The rim: outside is x − 1.5, or 0 past x = 1.5. Its square, times rim_steepness, is 0.2 at x = 1 and 0 from x = 1.5 on.
  4. A minimum of the floored bowl and the rim gives the crater: inside, the bowl is lower; past the rim, the rim is; past 1.5, the plain at 0.

The Math node's Smooth Maximum and Smooth Minimum round the creases where two curves meet, over a width of smoothness. Past 1.5 radii the height is exactly 0: that is what the three radii between sites of step 2 rely on.

step3_craters.bn: crater_profile

Which crater, how far

step3_craters.bn: crater_layer, mini_moon

  1. The nearest site. SampleNearest gives its index. SampleIndex then reads, at that index, the site's position, its normal, its radius and its age. The values stored in step 2 are read back here by name.
  2. The distance across the crater. v goes from the centre to the vertex. Its part along the normal, n * (v ⋅ n), is how far the vertex lies below the plane the crater sits on. Taking it away leaves across, the distance measured in that plane. A crater measured this way stays round on any surface, even when the surface curves away under it.
  3. The profile. x is that distance in radii, bent by a noise between 1.0 and 1.3 so the rim is not a perfect circle. The factor never goes below 1: it only pulls the rim in, so no crater grows past its disc of step 2. The noise follows p / radius: its bumps scale with the crater, a few per rim. Then crater_profile gives the height, times the radius (a large crater is deeper) and depth; old craters, by their age, keep down to 30 % of it.
  4. Along the normal. SetPosition moves each vertex by Normal() * height: down into the bowl, up on the rim, always across the surface, never along a fixed axis.

Between two sites, a vertex switches from one crater to the other where it is equally far from both. There it is 1.5 radii or more from each, outside both discs: both give a height of 0, or nearly, since the sphere curves a little between the discs, and the switch does not show.

The sphere with a few large craters; on the left edge, two pale crater rims stand out of the dark
Step 3. The largest layer only. On the left, two rims on the night side stand high enough to catch the sun: the summits are lit before the plain around them.

4. Craters of every size

A moon has a few large craters and a great many small ones, on top of the large ones. A repeat zone runs its body layers times and carries values from one run to the next: the height summed so far, and the size of the next layer, halved each time. The sphere stays the same; each layer scatters its own sites on it, with its own seed (iteration), and adds its craters to the sum. Since a crater's depth follows its radius, the small ones are also shallower.

step4_layers.bn: mini_moon

LayersizeCrater radiusSites
10.315 to 30 cm9
20.157.5 to 15 cm38
30.0753.8 to 7.5 cm155
40.03751.9 to 3.8 cm630
50.0190.9 to 1.9 cm2,540

Each layer has about four times the sites of the one before: half the distance between them, on the same area. The last layer is at the limit of the sphere: a crater 9 mm in radius spans a vertex or two. A sixth layer would need a ninth subdivision, four times the vertices.

The sphere covered with craters of five sizes
Step 4. Five layers, about 3,400 craters. Small ones fall in the large ones, and on their rims.

Try: set layers to 1, then to 3, to watch the moon fill. Set largest to 0.6: fewer, larger basins.

5. Dust, and an order to keep

Two things are left for the material: the colour, and relief smaller than the vertices. It needs one value from the geometry. Fresh craters on the Moon are brighter: the dust they threw out has not yet been darkened by the solar wind and micrometeorites. So crater_layer now also returns young, (1 − age)², full within half a radius of the centre and gone at 1.5 radii, and the repeat zone keeps the youngest crater of all layers with max.

step5_dust.bn: mini_moon

Look at the order at the end. A vertex moves along its normal, in all three axes: computed after the move, its nearest site and its distance to it would change, and young would no longer match the crater dug there. So both values are computed on the sphere as it was and stored on its vertices first, under a name; SetPosition then reads the stored height by name. It also computes the craters once: the stored value is read, the repeat zone does not run a second time.

The dust

step5_dust.bn: Regolith

step5_dust.bn: pits

pits is a crater for the shader: a Voronoi texture gives each point its distance to the centre of its cell, and the bowl alone, min(x * x - 1.0, 0.0), is dug in half of the cells. At 40 and 110 cells per metre, the pits are 4 to 9 mm, then 1.4 to 3.2 mm, in radius: smaller than the vertices, which are 7 mm apart. A shader tree has no Compare node, so Math with operation: LESS_THAN gives the 1 or 0 that picks the cells. On the sphere, the 3D cells are cut by the surface at every depth, which makes the pits more varied still.

The finished moon, grey and grainy, half lit
Step 5. The finished moon: grey dust, lighter around the young craters, grainy and pitted close up.

Phases

A moon lit by one sun and nothing else shows its phases as the sun goes round it. The same moon, three positions of the sun:

The full moon: flat light, craters seen by their lighter rims
Full, sun 8° from the camera. No shadow: the craters show only by the brightness of the young ones.
The quarter moon: half lit, long shadows along the line between day and night
Quarter, sun at 90°. Along the line between day and night the sun is grazing, and the relief is strongest.
A crescent: a thin lit edge on the right
Crescent, sun at 135°, behind the moon. Only a thin edge is lit; the rims on it cut the curve.

The sun is a Sun lamp of strength 6 and angle 0.5°, the world is black, and the render is Cycles, 96 samples, denoised. Without a world light, the night side is fully black.

Take it to Blender

The finished moon, in one file. Drag the card onto empty space in Blender's 3D Viewport and keep Instantiate the Example: a new object carries mini_moon. A click on the card downloads the file.

The steps before it, to start again from any of them:

The files, with the script that renders this page's pictures, are in examples/tutorials/mini_moon/.