colours.js  ·  chunk-core.js  ·  baked-core.js  ·  attr-core.js  ·  interactive companion

Colour Fields

The DAG holds shape and nothing else. A node's id says which voxels are there, and two places with the same voxels are the same node, whatever colour they are. So colour lives beside the DAG, as a field: a function from a point to a colour, asked by the chunk job once for every cube it's about to draw. This page follows a colour from the world's name for it to the pixel, one step a section, with the real code running.

32
bits a word, 18 of them colour
1
word per shown cube
10 + 1
named kinds, and baked
≤ 8
samples a coarse word
≤ 126
words read, a baked mean
7 + 1
ids and a revision: a stamp
name descriptor { kind, … } in the snapshot: data, never a function §4, §9 field colourOf (x, y, z, level) → r | g << 8 | b << 16 §2 wrap createOneLog blocks and drops in one list, eight int32 an op §7 sceneField the latest op solid in the cell, else the field §8 scene.mean over a baked world: its own mean wherever no op owns §12 reduce cellAttr lod 0: one sample · coarse: the count-weighted mean §5 field.mean baked: the exact mean of a rank range §6 pack attrOf8 8-bit floats → 6 bits a channel, rounded once §3 carry attrs a word per record · a run per brick on the ray path §10 decode GLSL_ATTR attrRGB(w) / 63, then a universe's tint, light and fog §10 save flatten the edited world as a plain baked one, six bits §12
01

The whole road

Three things are easy to mix up, so here they are once, apart:

The job is where a field becomes words. For each cube a chunk will draw, cellAttr asks the field and packs the answer. Everything before that is about getting the right field to the job. Everything after is about carrying words to a pixel.

main thread
the worldstore, root, D, and W.colour: a descriptorstream-viewer.html, buildWorld▸
worldSnapshotkeys, counts, poses, colour: the descriptor rides alongstream-core.js §4▸
the pool posts itstructured clone, once a world, to every workerstream-pool.js▾
worker
createJobRunnercolourOf(desc, { store, counts, D }) → the fieldstream-core.js, chunk-worker.js▸
a tail arrivesthe log's new ops, blocks and drops, wrap the fieldrun.tail, createOneTable, sceneField▸
the jobfor every shown cell: cellAttr → a wordfastChunk (job-core.js), held to expandChunk▸
the resultrecords and attrs, same order, transferred back4 + 4 bytes a cube▾
main, then GPU
installone buffer: records, then words. Or a ray page's runs, into the heapstream-viewer.html, install▸
vertex shaderaAttr, one per instance, passed on flatrasterVS▸
fragment shaderattrColour(w) = 6-bit channels / 63, then shadeOutGLSL_ATTR, GLSL_SHADE

Pick a voxel below and the right-hand column walks it down that road with real values. Every number comes from the functions the viewer runs.

One voxel's journey

Click a voxel in the slice.

Only shown voxels get a word (Q13). A voxel with all six neighbours filled has no face to draw, so it has no record, and the job never asks the field about it. Click deep inside a solid to see that: the field has a value there, but nothing carries it. That's why a word's place is its record's place: attrs[i] belongs to records[i], and there is no other index.

02

What a field is

The whole contract is one line, :

colour(x, y, z, level)  →  r | g << 8 | b << 16      // 8-bit channels, one integer, no allocation
colour.mean(level, x, y, z, out)  →  out[0..2]        // optional: only a baked field has it (§6)

"Everywhere" asks the field at every voxel centre of the slice and dims the answers where there's no voxel. Nothing in the engine draws those: they're what a coarse sample can land on.

Look at the kit and the lattice in "everywhere": between the pieces the field is flat grey. Look at terrain: its bands carry on up into the sky. Both are the same promise kept two ways. A coarse sample that lands in air gets something sensible, and its weight decides how much that matters.

03

The word

There are two packings, and they're easy to confuse because both put red in the low byte:

whatlayoutmade byread by
a field's answer8 bits a channel: r | g << 8 | b << 16rgb8the job (cellAttr), files' baked words
an attribute word6 bits a channel, in the high 6 bits of each colour byte: shifts 2, 10, 18packAttr, attrOf8attrRGB (JS) and GLSL_ATTR (shader), only

A word read as four RGBA8 bytes is a colour you can look at: each colour byte is the 6-bit value times 4. That's on purpose (Q14): an image codec that predicts per channel sees one channel per byte. The 14 bits left over (the low 2 of each colour byte, and all of the fourth byte) are reserved: written 0, ignored on read, so every word made today stays valid when something is put there.

red, bits 2–7green, bits 10–15 blue, bits 18–23reserved, written 0

All 256 values of a channel, and the 64 they land on

04

Named fields: a name, not a function

A world doesn't ship its colours. It ships a name for them, and turns the name back into a function wherever one is needed. That works because every one of these worlds is generated: the same descriptor that built the shape can rebuild the colour.

kindwhat the descriptor holdswhat the field does with a pointbuilt on each side from
shapename, Dmaps it to (−1, 1)³ and calls the shape's own colour: bands, strata, biomes nothing: the shapes are code
rowDa cosine palette along a diagonal, times a ±12% jitter per 4³ block a 1,024-entry palette table
scatterthe layout, and a table: 6 int32 a specimeninside a specimen's box and off the ground: its position in the specimen's own unturned frame, as RGB. Else the ground's colour the table (it travels in the descriptor)
latticethe grid, and the same tablethe same gamut colour per specimen, grey between boxes the table
kitthe kit's own descriptor, with colourLevelwalks the plan down to the level-c entry holding the point, un-turning as it goes, and returns the position in that entry's frame the plan, rebuilt from the descriptor (a few ms)
cavesD, seed, Gsea, pool water or lava if the voxel is one; the surface ramp on a column's top three voxels; rock strata elsewhere the plan, rebuilt (~0.6 s at D = 12)
clayD, lump, shape, groundground below the centre plane (with a 16-voxel checker), clay above, a small jitter per voxel nothing
dungeonD, seed, floors, and a table: the collapse's tile code for each 16³ cellthe tile's material at the point (wall, flagstone, step, pillar, water, lava…), tinted by floor from warm sandstone at the top to cold stone below, a small jitter a voxel the table, so a worker needn't run the collapse again
cityD, seedthe material of the 8³ tile at the point, and the palette of the building it belongs to: facades, glass, roofs, rooms, roads, water the plan, rebuilt (10–90 ms; a floor plan is made the first time it's read). No table: a D = 12 city is 20 million tiles
maththe layout, and a table: each object's shape, size and yawin an object's box, the gamut of its own frame, once or repeat times an axis; else the hills' colour the table
bakedskin, words, bitslooks the voxel's word up by its rank in the skin (§6)the words themselves: this one is data, not a name
null—no field: jobs emit no words, and the viewer draws in gamut mode—

Its descriptor: all that crosses to a worker


        
05

From field to word: cellAttr

One function turns a field into a word, and it has three branches ():

if (colour.mean)   // a baked field: ask it for the cell's mean, at every lod, lod 0 included (§6)
if (lod === 0)     // a voxel: one sample at its centre, colour(x + 0.5, y + 0.5, z + 0.5, 0)
else               // a coarse cell: the walk below, then ÷ the cell's voxel count, then to6 once

A coarse cell's colour should be the mean colour of every voxel under it. Taken exactly that's 8lod samples a cell: 512 at lod 3, which a job can't pay. So the walk goes down meanDepth levels (1 in the engine) and stops. Each sub-cell at that floor counts as its voxel count × the field at its centre. Click a cell to see its sub-cells laid out.

The cell you clicked, sub-cell by sub-cell

Click a cell.
sub-cell cornersidecountweightsample atthere isfield says

The layer shows every occupied cell; a job asks only for the ones that show a face. The table is this page's copy of meanUnder with each step kept, and it's checked against the real cellAttr on every click. The "unweighted" figure is the page's, to show what the weights do.

06

Baked fields: words by rank

An imported asset has no formula for its colour. Its colours come from a texture, sampled once when the mesh is voxelized. So a baked field is data: an array of words, and a way to find a voxel's word in it ().

Below is a 64³ ball whose skin is baked from the sphere's named colours, so you can compare the two. The strip on the right is the whole words array, 64 words a row, so each row is one block.

skin: has a wordinside: no word the cell askedthe ancestor it climbed to
Hover a cell of the slice.

The words, in rank order (one block a row)

whole blocks: two reads of the block sumsscanned, a word at a time
07

Edits: ids can't see colour

Edit mode places coloured blocks. The shape change goes into the DAG. The colour can't, so it goes into a table beside the field, and the field the job uses becomes a wrapper. In four lines ():

editedField = (base, table) => (x, y, z, level) => {
  const c = table.lookup(x, y, z);          // the latest block over this point, or −1
  return c >= 0 ? c : base(x, y, z, level);   // else the world's own field
};

That's the whole idea, and the plainest way to see it. The engine doesn't call it any more. Since 2026-11-12 blocks and drops go into one log (), and a worker follows it with , which folds the same block table into §8's scene field. Only that field keeps a baked world's mean (§12). For blocks alone over a named world the two are one function, and the stage checks that on every click.

The world below is real clay on flat ground, in a real store, with the real one log and a follower made from its deltas, as a worker's is. Click the slice to place or break. Then press the trap, which is the reason this whole section exists.

The one log: eight int32 an op

#opblockcolourthe eight wordsroot afternote
08

Scenes: a field over placements

Dropping a world into a world is the same problem at a larger scale. bakeScene unions the child's voxels into the parent's DAG, and after that the DAG can't say whose voxel is whose. A knight dropped where the kit was already solid leaves the kit's node exactly as it was, yet that voxel is the knight's now. So a scene's colour is a field over its placements (). Asked for the centre of a level-l cell, it does three things:

Blocks share the log (). A drop is an op in §7's one log, eight words like a block, and a voxel takes the colour of the latest op that made it solid, whichever kind it was. So the owner is the later of two answers: the latest block over the cell's centre (§7's table) and the latest placement solid in the cell (the test above). Here the tool can be a block too: drop the ball, put a block through it, then drop the torus over both.

The one log: blocks and drops, eight int32 each

#opatturnscaleTpaintroot after

Click to drop or to place: the page centres the child's cube on the click, in the slice's plane. (The viewer's dropAt puts it against the face you hit, scene-log.md §4.) The picture is the field's answer for each occupied level-l cell of the layer, which is what the coarse walk's floor asks it. The slice cuts through the middle of what you drop, so it shows insides the viewer never draws. A baked ball's inside voxels have no word: the blocky colours in its middle are §6's fallback, each the mean of the nearest ancestor cell with skin. Its rim is its own words.

09

Across threads

Chunk jobs run in workers, and a worker shares nothing with the page. So everything a field needs has to be posted, and it has to arrive before the job that uses it.

what crosseswhenwhat's in it for colourthe other side does
the snapshotonce a world, to every workersnap.colour: the descriptor. A baked one carries its words, cloned like the keyscolourOf(snap.colour, { store, counts, D }), over its own view of the keys
a tailonce an edit, before any job names its rootops: the one log's ops the table hasn't seen, 8 int32 each (a block or a drop), plus new worlds' descriptorsone.sync, then the field is wrapped
a jobper chunknothing: it names a chunk, a rule and a rootfastChunk with the field it holds right now
a resultper chunk, backattrs, a Uint32Array beside records, transferred (moved, not copied)the page uploads it (§10)
Starts when this section is first on screen.

This starts the viewer's own chunk-worker.js, posts it a snapshot and one job the way stream-pool.js does, and compares what comes back with the same chunk expanded here by expandChunk with this page's own copy of the field.

10

To the GPU, twice

The viewer has two ways to draw a chunk, and each carries words its own way.

Raster: a word per instance

A records chunk is one buffer: all the records, then all the words. Two integer attributes read it, one from byte 0 and one from byte 4n, each with divisor 1, so every instanced cube gets its record and its word. The vertex shader passes the word on flat, since a cube is one colour.

Ray: a run per brick, in a heap

A traced chunk has no instances. A ray hits a cell and needs that cell's word. Each 8³ brick with shown cells gets a run: 16 words of shown-mask (512 bits, Morton order), then one word per shown cell. A hit's word is at the cell's rank among the set bits, a popcount.

One brick's shown mask: 16 words × 32 bits

The cell you clicked

Click a lit bit.

Then the word is lit

Both passes share , so a voxel looks the same drawn either way. The word's colour is multiplied by a fixed two-light shade that depends only on which face it is, then mixed toward the background by distance. There's no gamma step: the 6-bit channel over 63 goes to the canvas as it is.

In a universe there's one step before the light (2026-11-19, universe-plan Q8). From far off the worlds run together, so the raster's fragment shader mixes each world's colour toward a tint for its kind (the kit warm, the city blue, a file violet), moved a little by the world's key so two kits differ. None at lods 0 and 1, where a world is seen close and its own colours matter, then 0.15 a lod up to 0.45 (). It's a uniform a world, never a word: the chunks and their bytes are the plain world's. A plain world never sets it.

The arithmetic here is this page's copy of shadeOut, on the cell clicked above (or a default clay colour). The tint is the real tintOf and tintAt; the mix is the shader's one line, mix(base, uTint.rgb, uTint.a).

The viewer's colour modes

modemenu namewhat colours the cubeneeds words?
8attributethe word: everything on this pageyes
3gamutthe fragment's position over the world's side, as RGB, computed in the shaderno
0lodone colour per lodno
1posethe 8³ brick's Oh pose, from the recordno
2chunkone colour per chunkno
4plainflat grey, shadedno
6pathraster warm, ray coolno
5, 7, 9, 10(tests)depth, draw index, the raw word, the stencil mask9 does

A world with no colour opens in gamut, one with colour in attribute, until you pick a mode (). Attribute mode with no field drew a shape-only file almost black, and that read as broken. Gamut here is a different thing from §4's gamut fields: the mode colours by where a fragment is in the world, per pixel; the fields colour by where a voxel is in its own piece, per word.

11

In a file

A .vdag file outlives the code that wrote it, and that's a problem for a name: the file says "the terrain's colours", and the code that reads it might define those differently by then. So a file stores the descriptor and a print of what it meant when written.

filebytesread back withstatuswhat the viewer says
Runs when this section is first on screen.

Real writeVdag and readVdag, in memory. "A field that changed" hands the reader a colourOf whose field returns one constant, as file.test.js does.

12

A baked world, edited and saved

Until 2026-11-27 a baked world couldn't be edited: a file opened as a view. Two things were in the way, and both are on this page already. §6: a baked field is only right through its mean, because a point reads one voxel and an inside voxel has no word. §7: a chunk cached before an edit is kept if its stamp and colour revision say nothing moved. Put together, the second asks something hard of the first. A chunk no op painted keeps the bytes the base made before the first op, so every chunk made after it (a lod switch, a chunk scrolling in, a restarted worker) has to make those same bytes. The scene field over a baked base keeps a mean, and it's held to one rule, === ():

// for every cell no op touches, at every lod, the scene's mean is the base's mean
scene.mean = (l, x, y, z, out) => {
  const c = ownerOf(/* the cell's centre */, l, /* whole: */ true);
  if (c === OWN_BLOCK) return the block's colour;
  if (c === OWN_BASE || !c.colour) return base.mean(l, x, y, z, out);   // the base's own, untouched
  return the child's colour for this cell;
};

Below is a 128³ ball baked the way §6's is, a row of 2³ blocks in the air over it, and a named torus dropped into its side. The picture is what the job draws: cellAttr for every occupied cell of the layer at the chosen lod, which for this field is its mean.

The chunks: does an unpainted one keep its bytes?

lodchunkrevisionwordsagainst the base's field

Click to act at the slice. A block goes where you click, a drop centres the torus there. "Against the base's field" expands the chunk twice over the same edited shape, once with the scene field and once with the base's own, and compares every word: a chunk the paint index never touched has to match exactly.

13

What colour costs

Since the job got faster, colour is most of a coloured job. The walk of the DAG is cheap now; what's left is calling the field once per lod-0 record and up to 8 times per coarse one. The numbers below are measured, each with where it came from. Then measure this machine.

whatmeasuredwhere
a job, with colour against without (meanDepth 1)+6% to +200%. Cheap jobs double; jobs dominated by the walk barely noticeattrs-findings.md §2
meanDepth 22–10× a plain job. It buys accuracy only at lod 4, so the default stays 1attrs-findings.md §2
the kit's job, warmabout 1.5 ms of walk and 12–13 ms of words: 0.6 µs a word even with the frame cachejob-speed-log.md
a baked word at lod 00.13–0.29 µs with the path memo (0.35–0.47 before); a named one, 0.08–0.10glb-colour-log.md §6
a baked job against a named one, lods 1–40.59–0.93×: cheaper, and exact where the walk isn'tglb-colour-log.md §6
a baked field's block sums0.375 bytes a word; built in 11–30 ms at D = 10, in each workerglb-colour-log.md §2, §7
six bits against eight, in the filefiles 1.4–1.8× smaller; a quarter of coarse words move one step; no lod-0 word movesglb-colour-log.md §5
the scene field over the kit's×1.0–1.3 with one placement, ×1.15–1.5 with sixteenscene-log.md §2.2
an edit's tailunder 1 KB a click, against 79 MB for a whole D = 12 caves snapshotstream-core.js §4b
lodchunksrecordsno colourmeanDepth 0meanDepth 1meanDepth 2µs a word, depth 1
Press the button. It takes a second or two, on the main thread.

Real fastChunk (the job), one cache a column, rule any at lod 0 and shadow above, one run on the main thread of whatever machine this is. Read the ratios, not the milliseconds. At lod 0 every depth is one sample, so those columns differ only by noise. At lod 1, depths 1 and 2 are the same walk: the floor is level 0 either way.

Two things would cut colour's cost without changing a word, and one that looks like it would doesn't. Field-specific work helps, like the kit's frame cache. So does asking fewer points: meanDepth 0 asks 1 instead of up to 8, and attrs-findings.md measured what that loses (at lod 3 only 31–34% of the rows' words come within a step). Caching a word per DAG node doesn't work at all: a word is a function of position, and the same node sits at many positions. That's this page's first sentence again.

14

The rules, and where to read

Each of these has a test behind it, and all but A″ are a sentence in CLAUDE.md. They're the finer points in the form you'd trip over them.

rulewhyheld by
a word's layout is decided in one placeattr-core.js packs, GLSL_ATTR decodes; change both togetherchunk.test.js: every word through the shader, exactly
colour fields are named, or baked and shippeda worker can't receive a function; a baked field is data in the snapshotbaked-core.test.js: a snapshot cloned through the runner
a word reads only inside its own chunk's boxor "same stamp, same bytes" is false and the cache is silently wrongstream-core.test.js, on every chunk
a stamp has a colour revisionids can't see colour: red, break, bluestream-core.test.js: break-and-recolour
blocks and drops go through one log"the latest op wins" needs one list ordering both kindsone-log.test.js: blocks only against the old block log, drops only against the old scene log, mixed histories against a dense twin
a follower follows the log by epoch and count, from op 0undo then a different op leaves the same count; an op's number is its place in the log, never in the deltaone-log.test.js: the mixed trap (undo a drop, then place a block)
a follower that loses an op or a world throwsa table quietly short draws a wrong colour until something repaints that chunkone-log.test.js: gaps throw, worlds never start over
fields get the sample's levelor a coarse cell of a placed child reads one voxelscene-field.test.js, both sides
a scene over a baked base keeps the base's mean wherever no op touchesa chunk no op painted keeps the bytes the base made before the first opscene-field.test.js, === at every lod; stream-core.test.js's saved-world suites
a block owns a coarse cell by any voxel in it (A″)over a baked base nothing samples sub-cells, so a block missing the centre vanishededit-core.test.js: latestIn against a backward scan of the ops
a save is the session at lod 0a file is a plain baked world, so its skin's words are the ones the job drewflatten-core.test.js: record for record and word for word, before and after six bits, saved twice
what expandChunk emits, fastChunk emitsthe fast job is the real one; the slow one is the oraclejob-core.test.js, byte for byte, with colour
a reserved bit's field brings its own reductiona mean is right for colour and wrong for a labelattrs.test.js needs an oracle for it
a tail goes on the port its jobs useor a job reads a table from its futurestream-core.test.js: tails against a fresh snapshot; edit.test.js, a worker killed part way
a file's baked print that doesn't match is damagea named colour can drift; a file's own words can'tvdag-core.test.js: every lie a file can tell

Reading order for the code

Line numbers are looked up as the page loads, so they're right for the files you're serving. Click one to copy file:line.

#wherewhat to read for
1 The whole file is 42 lines: the word, to6, and the field's packing beside it.
2The header lists every descriptor; colourOf is the switch.
3The comment is the design: the mean, meanDepth, the mean hook, the sample's level. Then meanUnder and cellAttr, under 30 lines.
4 Where the job calls it: once per record, once per tail record, in both jobs.
5 Block sums, the rank walk with its memo, and the fallback. Read the header first.
6 The table's lookup and latestIn; the one log's header (the colour rule, paint, the epoch), then createOneTable.
7Stamps, "ids can't see colour", and createPaint.
8 The owner, the child's cell, what's exact, a baked parent's mean and A″, blocks in the same world, the stamp rule, the cost. Then ownerOf, which both roads ask.
9 How the descriptor rides the snapshot, where the field is made and wrapped, and why ordering makes tails right.
10 The worker, which is short, and the pool keeping every tail.
11 Runs, the heap, and the two twins.
12 Two lines of decode, and the shade both passes share.
13 The print, the five statuses, six bits.
14The save: the steps, why the mean road takes a word of its own, what a file holds and what it doesn't.
15 The ten decisions behind the word, the baked design, and the scene field's cost.

What this page leaves out