Declarative text format for procedural node graphs. Writes and reads back node trees as typed functions across Python, Rust (wasm32), and Blender. To install the Blender add-on, see Install.
// Hydraulic erosion after the virtual pipe model of Mei, Decaudin & Hu (2007):
// rain, flow through 8 pipes per cell, sediment carried with the water, thermal slide.
geometry graph erode(terrain: Geometry, iterations: Int = 50 in 0.., rain: Float = 0.01 in 0.0.., ...) -> Geometry {
"Erodes a square Grid: rain, flow through pipes, sediment"
... // the whole simulation in one Repeat zone
}
geometry graph "eroded hills"(
size: Float = 4.0 in 0.1..,
resolution: Int = 128 in 2..,
height: Float = 1.2 in 0.0..,
iterations: Int = 50 in 0..
) -> Geometry {
"A noise terrain on a Grid, eroded"
hills = NoiseTexture(vector: Position(), scale: 0.6, detail: 6.0, roughness: 0.55).factor
return Grid(size_x: size, size_y: size, vertices_x: resolution, vertices_y: resolution)
|> SetPosition(offset: CombineXYZ(z: (hills - 0.5) * height * 2.0))
|> erode(iterations: iterations)
|> SetShadeSmooth()
}
// Gray-Scott reaction-diffusion after Pearson (1993), on a Grid with wrapped borders:
// a 9-point Laplacian read with Sample Index, one explicit step per iteration.
geometry graph "reaction diffusion"(grid: Geometry, preset: Menu = Coral, iterations: Int = 3000 in 0.., ...) -> Geometry {
"Grows a Gray-Scott pattern on a square Grid, `iterations` steps at once"
... // presets in a Menu Switch, the steps in a Repeat zone (a Simulation zone in "growing reaction diffusion")
}
geometry graph "reaction diffusion tile"(
resolution: Int = 256 in 3..,
preset: Menu = Coral,
iterations: Int = 3000 in 0..
) -> Geometry {
"A 4 x 4 Grid grown with a Gray-Scott pattern"
return Grid(size_x: 4.0, size_y: 4.0, vertices_x: resolution, vertices_y: resolution)
|> reaction_diffusion(preset: preset, iterations: iterations)
|> SetShadeSmooth()
}
// Differential growth of a closed curve, after Anders Hoff's differential-line and Nervous System:
// a spring to the neighbours along the curve, repulsion from the points near it, alignment,
// then the edges longer than `max length` cut with Subdivide Curve.
geometry graph "differential growth"(curve: Geometry, iterations: Int = 400 in 0.., ...) -> Geometry {
"Grows a closed curve in the XY plane, `iterations` steps at once"
... // the steps in a Repeat zone (a Simulation zone in "growing differential growth")
}
geometry graph "differential growth coral"(
size: Float = 0.4 in 0.01..,
iterations: Int = 400 in 0..,
"max length": Float = 0.02 in 0.0001..,
seed: Int = 0,
thickness: Float = 0.006 in 0.0..
) -> Geometry {
"A circle grown into a coral outline, drawn as a tube of `thickness`"
grown = growth_seed(size, max_length, 0.3, seed)
|> differential_growth(iterations: iterations, max_length: max_length, radius: max_length * 2.5)
return CurveToMesh(grown, profile_curve: CurveCircle(resolution: 8, radius: thickness))
|> SetShadeSmooth()
}
// Tuples choose the type: no input_type and no data_type is written for the switches below.
// A 3-tuple makes a Vector Switch, a 4-tuple a Color IndexSwitch and a Color Mix.
geometry graph "tuple tiles"(count: Int = 14 in 2.., phase: Float = 0.0 in 0.0..1.0) -> Geometry {
"A board of tiles: their colours and sizes are tuples"
p = Position()
// A checker of cells, by the index of each point of the Grid
cell = mod(Index(), count) + floor(Index() / count)
r = length(CombineXYZ(x: p.x, y: p.y))
// Four colours, a 4-tuple each: a Color IndexSwitch
tint = IndexSwitch(
mod(cell, 4.0),
(1.0, 0.3, 0.04, 1.0),
(0.02, 0.5, 0.75, 1.0),
(1.0, 0.72, 0.06, 1.0),
(0.75, 0.06, 0.24, 1.0))
// Darker towards the rim: a Color Mix
shade = Mix(factor: Clamp(value: r * 0.42 - 0.1), a: tint, b: (0.04, 0.05, 0.08, 1.0))
// Tall in the middle, flat around: a Vector Switch
size = r < 1.15 ? (0.2, 0.2, 0.5) : (0.24, 0.24, 0.08)
lift = sin(phase * 6.283185 - r * 2.6) * 0.12
return Grid(size_x: 3.9, size_y: 3.9, vertices_x: count, vertices_y: count)
|> StoreNamedAttribute[FLOAT_COLOR](name: "tint", value: shade)
|> SetPosition(offset: CombineXYZ(z: lift))
|> InstanceOnPoints(instance: Cube(size: (1.0, 1.0, 1.0)), scale: size)
|> RealizeInstances()
|> SetMaterial(material: TupleTiles)
}
A target is what one destination accepts: one file per target in targets/*.json,
none defined from another. The language speaks Blender; a destination that is not Blender declares translators from Blender's target.
A text needs no target: the tool tells which ones accept it, and // @target blender gltf at its head is a promise the editor holds it to.
Specification.
| Target | Accepts | For |
|---|---|---|
blender |
Every node of Blender, for each kind of tree: a geometry graph the Geometry Nodes, a shader graph the shader nodes, a compositor graph the compositor's. In every version of Blender this version of Base Node promises |
Blender, every module of the standard library |
blender@5.3 |
The same, in one version of Blender: its catalog, as that Blender reports it. An LTS says so in its name (blender@5.2-lts) |
A text that uses a node of one version |
blender gltf |
A variant, after the target or one of its versions: the shader nodes Blender's glTF exporter turns into a material | Unity, Godot, Unreal, anything that reads glTF |
blender eevee, blender cycles |
Variants, experimental: the shader nodes Blender says each render engine takes | A material for one engine |
blender@latest and blender@lts name a version on a command line (base-node check --target blender@latest);
a text does not promise them: what they name changes with each release of Blender.
<bn-view>)
The examples above are drawn by <bn-view>: base-node compiled to wasm
(web/) shows a .bn text read-only, its code beside its node graph, with
a copy button, an enlarge button, and a tag per backend that runs it (Blender Geometry Nodes, Shader,
Compositor) and the targets it fits. Demo.
<script type="module" src="view/bn-view.js"></script>
<bn-view src="relief.bn"></bn-view>
<bn-view view="nodes" height="480"><script type="text/bn">
geometry graph g() -> Geometry { return MeshCube() }
</script></bn-view>
python/)Zero-dependency packages: base-node, the core (lexer, parser, canonical formatter, the CLI), from base-node-language, and base-node-blender, Blender's nodes (typechecker, target checker, its commands of the CLI).
# Install from GitHub
pip install "base-node @ git+https://github.com/marcgardent/base-node-language.git#subdirectory=python" \
"base-node-blender @ git+https://github.com/marcgardent/base-node-for-blender.git#subdirectory=python"
# CLI
base-node fmt file.bn
base-node check file.bn
import base_node as bn
import base_node_blender as blender
ast = bn.parse(source)
code = bn.format_source(source)
issues = blender.check_target(ast, "blender gltf")
License: MIT OR Apache-2.0
rust/)wasm32-unknown-unknown compatible crates: base-node, the core, from base-node-language, with byte-for-byte identical canonical formatting, and base-node-blender, with the embedded JSON targets.
# Cargo.toml
[dependencies]
base-node = { git = "https://github.com/marcgardent/base-node-language.git" }
base-node-blender = { git = "https://github.com/marcgardent/base-node-for-blender.git" }
use base_node::{parse, format_source};
use base_node_blender::{check_target, infer};
let f = parse(src, "a.bn")?;
let code = format_source(src, "a.bn")?;
let issues = check_target(&f, "blender gltf");
let fits = infer(&f).fits;
License: MIT OR Apache-2.0
stdlib/)| Module | Trees | Graphs | Contents |
|---|---|---|---|
math.bn |
geometry, compositor |
47 | Inigo Quilez curves, easing, bounce, elastic, fbm, Fibonacci, R2 low-discrepancy sequence, analytic SDFs |
sdf2d.bn |
geometry, compositor |
17 | 2D segment, rounded box, rhombus, equilateral triangle, hexagon, regular polygon, star, arc, sector, cross, chamfer booleans, polar/grid repetition, isolines |
curves2d.bn |
geometry |
7 | 2D curve morphing, parallel offset contour, fractal contour noise, sine wave contour, tapered ribbon, 2D arrow, 2D ring |
patterns2d.bn |
geometry |
5 | Hexagonal honeycomb grid, equilateral triangular grid, Vogel phyllotaxis spiral, R2 stratified jitter points, 2D hatching |
planar2d.bn |
geometry |
4 | Planar map of overlapping curves: faces, split at intersections, shape builder pick, outer boundary contour |
fillet2d.bn |
geometry |
4 | Fillet of a corner and of a polygon, chamfer of a polygon, fillet as Bezier handles |
mask2d.bn |
compositor |
9 | Compositor masks drawn by the SDFs of math and sdf2d: circle, box, polygon, star, outline, letterbox |
merge.bn |
compositor |
32 | The Merge operations of compositing on premultiplied images: over, under, in, out, atop, xor, stencil, mask, plus, screen, multiply, difference…; premult, unpremult, keymix |
grade.bn |
compositor |
20 | The colour tools of compositing: grade, color correct by shadows / midtones / highlights, saturation, hue shift, exposure, soft clip, log2lin / lin2log |
stmap.bn |
compositor |
12 | Image remapping by STMaps, as Nuke's STMap: UV ramp, STMap apply, tile, mirror, reformat by fit / fill / distort, each as its STMap and its image |
qc.bn |
compositor |
24 | Quality control after Nuke: test patterns (SMPTE colour bars, colour wheel, ramp, radial, rectangle, grid, checkerboard, constant) and checks (false colour by stops, clip check, NaN and infinity check, zebra, alpha check, difference as heat) |