High-res edition, Nov 2026 · as built

Tessera

A Wee book about a voxel fantasy console for the browser: what it is, how a frame gets made, what a cart looks like inside, and how to write your first one.

A tessera is one tile of a mosaic. In Tessera every voxel is a tile. This edition describes the high-res console as it is built: a 256 × 256 × 128 world drawn at 768 × 432. For the deep dive into each part, read Tessera High-Res, explained.

The mark assembles tile by tile, like a mosaic. The real boot screen lays a bigger mark in amber, teal and slate; see it play.

The puppy-island beach, painted once at load into a 480 × 270 canvas and scaled up with chunky pixels, in the spirit of Tessera's own 768 × 432 picture. Its colours come from the guide's first draft palette. This is an illustration, not the real renderer.

01What Tessera is

Tessera is a general-purpose fantasy console: a pretend games machine with fixed, small limits that lives in a web page. Instead of a flat screen of pixels it has a box of 3D voxels, and you program it in Lua. The limits are the point. A fixed world, 255 colours and four sound channels keep carts quick to make and easy to share.

The first cart is a port of Puppy Coast: Hat Chase, the three.js game, and it plays at 60 fps on a desktop GPU and on a phone. Chapter 9 shows how that game maps onto Tessera piece by piece.

Volume256 × 256 × 128x east, y north, z up
Voxels8,388,608each one byte
Memory2 × 8 MiBa map layer and a draw layer
Colours255 + emptyper-cart palette; index 0 empty
Picture768 × 432internal, upscaled with chunky pixels
Logic30 Hzfixed _update; _draw every frame
LanguageLua 5.4real Lua, via WebAssembly
Players46 buttons + 2 axes; keys, pads, touch
Sound4 channelssquare, triangle, saw, noise
Carts.tess · .tess.pngtext file, or a picture with the cart inside
Picture cart64 KiBcompressed cart capacity
Text5 × 7 fontHUD on its own 768 × 432 layer
Figure 1. The machine on one card. These are the limits the console enforces.

02A box of tiles

The whole display is one block of voxels, 256 wide, 256 deep and 128 tall. Tessera puts z up, so x and y are positions on the ground (x east, y north) and z is height. Each voxel holds one byte: 0 means empty, and 1 to 255 pick a colour from the palette.

Hat Chase lighthouse: top at z = 800256641921281281926425600326496128x: 256 voxels (east)y: 256 voxels (north, away)z: 128 voxels (up)(0,0,0)1 voxel = 1 bytevalue 23 (0x17) = palette index0 = empty256 × 256 × 128= 8,388,608 voxels× 1 byte = 8 MiBper layer (map, draw)
Figure 2. The display volume drawn to scale. Every voxel is one byte holding a palette index, so one layer of the world is exactly 8 MiB, and Tessera keeps two layers. The origin sits at the front-left corner: x runs east, y runs north, away from the camera, and z runs up. For scale, the coral column is the Hat Chase lighthouse, computed from the game's own terrain code and doubled like the rest of the port: it reaches z = 80 of 128. The beach itself sits in the bottom 28 layers. Byte order: offset = x + 256·y + 65,536·z (idx() in src/core/vram.js), which matches how a 3D texture is laid out.
one layer: 8 bytes in a row00x=4000x=414Cx=424Cx=43A8x=44A8x=4517x=4600x=47palette (256 × RGB) 0empty: rays pass through 76#E2CEA7168#33A3DB 23#CC2424what the ray sees
Figure 3. The volume stores numbers, not colours. The renderer looks each byte up in the 256-entry palette (sent to the GPU as a small texture), so changing pal(76, …) recolours every sand voxel at once without touching the 8 MiB layers. Index 0 is always empty.

The palette

Each cart can define its own 255 colours. A cart that defines none gets the default Tessera palette, laid out as a 16 × 16 grid so you can find colours by row and column.

0123456789ABCDEF00 greys1: #0a0a0a2: #1b1b1b3: #2c2c2c4: #3d3d3d5: #4e4e4e6: #5f5f5f7: #7070708: #8181819: #92929210: #a3a3a311: #b4b4b412: #c5c5c513: #d5d5d514: #e6e6e615: #f7f7f710 red16: #11080817: #27111118: #3f181819: #581d1d20: #73212121: #8f242422: #ad252523: #cc242424: #db333325: #da525226: #db707027: #de8c8c28: #e2a7a729: #e7c0c030: #eed8d831: #f7eeee20 vermilion32: #110a0833: #27151134: #3f1e1835: #58271d36: #732f2137: #8f362438: #ad3b2539: #cc402440: #db4f3341: #da695242: #db827043: #de9a8c44: #e2b1a745: #e7c7c046: #eedbd847: #f7efee30 orange48: #110c0849: #271a1150: #3f281851: #58361d52: #73432153: #8f502454: #ad5d2555: #cc6a2456: #db793357: #da8b5258: #db9d7059: #deae8c60: #e2bfa761: #e7d0c062: #eee1d863: #f7f2ee40 amber64: #110e0865: #27201166: #3f321867: #58441d68: #73582169: #8f6b2470: #ad7f2571: #cc942472: #dba33373: #daad5274: #dbb87075: #dec38c76: #e2cea777: #e7dac078: #eee7d879: #f7f4ee50 yellow80: #11100881: #27251182: #3f3c1883: #58531d84: #736c2185: #8f862486: #ada12587: #ccbe2488: #dbcd3389: #dacf5290: #dbd27091: #ded78c92: #e2dda793: #e7e4c094: #eeecd895: #f7f6ee60 lime96: #0e110897: #20271198: #323f1899: #44581d100: #587321101: #6b8f24102: #7fad25103: #94cc24104: #a3db33105: #adda52106: #b8db70107: #c3de8c108: #cee2a7109: #dae7c0110: #e7eed8111: #f4f7ee70 green112: #08110a113: #112715114: #183f1e115: #1d5827116: #21732f117: #248f36118: #25ad3b119: #24cc40120: #33db4f121: #52da69122: #70db82123: #8cde9a124: #a7e2b1125: #c0e7c7126: #d8eedb127: #eef7ef80 teal128: #081110129: #112724130: #183f38131: #1d584e132: #217365133: #248f7d134: #25ad96135: #24ccb0136: #33dbbf137: #52dac4138: #70dbc9139: #8cded0140: #a7e2d8141: #c0e7e1142: #d8eeea143: #eef7f590 cyan144: #081011145: #112527146: #183c3f147: #1d5358148: #216c73149: #24868f150: #25a1ad151: #24becc152: #33cddb153: #52cfda154: #70d2db155: #8cd7de156: #a7dde2157: #c0e4e7158: #d8ecee159: #eef6f7A0 sky160: #080e11161: #112027162: #18323f163: #1d4458164: #215873165: #246b8f166: #257fad167: #2494cc168: #33a3db169: #52adda170: #70b8db171: #8cc3de172: #a7cee2173: #c0dae7174: #d8e7ee175: #eef4f7B0 azure176: #080b11177: #111827178: #18253f179: #1d3158180: #213c73181: #24478f182: #2552ad183: #245ccc184: #336bdb185: #5280da186: #7094db187: #8ca7de188: #a7bbe2189: #c0cde7190: #d8dfee191: #eef1f7C0 blue192: #090811193: #131127194: #1b183f195: #221d58196: #282173197: #2d248f198: #3025ad199: #3224cc200: #4133db201: #5e52da202: #7970db203: #938cde204: #aca7e2205: #c3c0e7206: #dad8ee207: #efeef7D0 violet208: #0d0811209: #1e1127210: #2f183f211: #401d58212: #512173213: #62248f214: #7425ad215: #8624cc216: #9533db217: #a252da218: #af70db219: #bc8cde220: #c9a7e2221: #d7c0e7222: #e5d8ee223: #f3eef7E0 magenta224: #110810225: #271125226: #3f183c227: #581d53228: #73216c229: #8f2486230: #ad25a1231: #cc24be232: #db33cd233: #da52cf234: #db70d2235: #de8cd7236: #e2a7dd237: #e7c0e4238: #eed8ec239: #f7eef6F0 rose240: #11080c241: #27111a242: #3f1828243: #581d36244: #732143245: #8f2450246: #ad255d247: #cc246a248: #db3379249: #da528b250: #db709d251: #de8cae252: #e2a7bf253: #e7c0d0254: #eed8e1255: #f7eef2used in this guide23 red hat76 sand168 seaindex = 16 × row + columndark → light, left → right
Figure 4. The default Tessera palette (src/core/palette.js), used by any cart that defines no palette of its own. Read an index as row and column in hex: sand is 0x4C (row 4 amber, column C), sea is 0xA8. Because every hue row runs dark to light in the same 16 steps, shading something darker is just "subtract one".

03One frame

Tessera keeps two layers. The map layer is the world that stays put: terrain, buildings, the lighthouse. You build it once in _init. The draw layer is everything that moves: characters, the sea, sparkles. It lives in its own layer, which cls() empties at the start of every frame, and is redrawn on top of the map.

MAP layer8 MiB, persistsbetween framesDRAW layer8 MiB, emptiedby cls()GPU raymarchertwo R8UI 3D texturesdraws 768 × 432Screennearest-neighbourupscale2D overlay768 × 432 HUDprint · rect · spr2d_init (once)mset · mbox · mmodel_draw (every frame)box · sphere · modelwrites oncewrites each frameuMap: only changed 16³ bricksuDrawchanged bricks768 × 432per-frame datapalette 256 × RGBcamera · sun · sky · foguOverlaydrawn on top
Figure 5. Two layers, two textures, one shader. The map layer (blue) is built once and kept; the draw layer (coral) is emptied by cls() and refilled by _draw, so moving things never need erasing. Each layer is cut into 2,048 bricks of 16 × 16 × 16 voxels, and the renderer uploads only the bricks that changed since the last frame (src/render/renderer.js). In the shader a non-empty draw voxel wins; otherwise the ray sees the map voxel. The HUD is a third texture the same shader lays on top. Memory and uploads has the details.

Timing

A cart has three functions. _init runs once when the cart loads. _update runs exactly 30 times a second and should hold the game rules. _draw runs once for every frame the screen shows and should only draw.

_updatefixed 30 Hz_draw60 Hz screen_draw120 Hz screen#1#2#3#40102030405060708090100110120130milliseconds0 ms33.3 ms66.7 ms100 ms133.3 ms
Figure 6. Game logic ticks at a fixed 30 Hz (blue, every 33.3 ms) whatever the screen does, so a cart plays at the same speed everywhere. _draw (coral) runs once per displayed frame: twice per update at 60 Hz, four times at 120 Hz. Shading shows which update each draw follows.

04Making the picture

Tessera does not turn voxels into triangles. A WebGL2 fragment shader shoots one ray per pixel of a fixed 768 × 432 picture into the two 3D textures and walks it voxel by voxel with a DDA (a digital differential analyser: step to whichever cell edge is nearer, x or y or z, and check that cell). The camera is orthographic, so every ray points the same way, about 35° down, just like the Hat Chase camera today. The small picture is then scaled up with nearest-neighbour sampling, which gives the chunky look.

screen:one ray per pixel1234567891011121314151617181920✕in shadowlittoward the sunx →36 cells of one slice
Figure 7. One vertical slice, computed by actually running the DDA in the generator script. 13 parallel rays (orthographic: every pixel looks the same way, 35° down) step from cell edge to cell edge; tinted cells are the ones visited, outlined cells are hits. The ray hitting column 16 sends its shadow ray toward the sun and meets the tall column after 14 cells: in shadow. The highlighted ray visits 20 cells (numbered) before hitting column 11; its shadow ray leaves the volume without hitting anything: lit. Work per pixel depends on distance travelled, not on how many voxels changed this frame.

Shading, in four cheap steps

  • Face light: top, side and front faces get fixed brightness levels, so shapes read clearly.
  • Sun shadow: one extra ray toward the sun, as in Figure 7.
  • Ambient occlusion: peek at a few neighbouring voxels and darken corners a little.
  • Fog (optional): fade distant voxels toward a colour set by fog(c, density).
  • Frame reuse: when nothing changed since the last frame, the renderer shows the last picture again instead of raymarching.

On top sits a 768 × 432 2D overlay for HUD text and icons in a built-in 5 × 7 pixel font. The overlay is drawn after the raymarch, so text is always crisp and never hidden behind voxels.

05Inside the machine

The console is written in JavaScript, split into small modules under src/. Only shell/ touches the page; the rest is tested on its own.

ModuleJobNote
core/core.jsthe machine: the ports above; every load starts a fresh machineno DOM: unit-tested in Node
core/api.js · core/lua.jsthe Lua API; the wasmoon host with a 2 s watchdog and cart line numbers on errorsa cart error shows the Tessera error screen; the console never crashes
core/vram.jsthe two layers, 16³ brick tracking, primitives (box, sphere, line, models)only changed bricks are marked for upload
render/renderer.js · shaders.jsWebGL2 raymarcher over two R8UI 3D texturesreuses the last picture when nothing changed
render/overlay.js · font.js768 × 432 HUD in a 5 × 7 pixel fontdrawn after the raymarch
io/input.jskeyboard, standard gamepads and touch → the input arrayarrows/WASD, Z/Space, X/E, M mute
io/audio.js4-channel synth: square, triangle, saw, noise; envelopes; pitch slidesplays the sound event queue
cart/tess.js · png.js · pngfile.jsparse and write .tess; encode and decode .tess.pngpure functions
shell/boot screen, cart picker, pause menu, error screen, code editor (F4), stats (F3)the only part that owns the page

Build: Vite with vite-plugin-singlefile inlines everything, including the Lua WebAssembly, into one tessera.html that works offline.

Built to be swapped

The core sits behind a "machine level" boundary. Only plain data crosses it: cart text in, button states in, and out come the two 8 MiB layers, the palette, camera numbers, HUD commands and sound events. Nothing on the outside knows which language the core is written in.

Host page: stays the sameMachine core: swappablemachine boundary: plain data onlyshell/loader.jscart sourcestring (.tess text)io/input.jsinputFloat32Array(33): 4 × (6 btn + 2 axes)render/renderer.jsmap + draw layers2 × Uint8Array, 8 MiB eachrender/renderer.jspaletteUint8Array(768): 256 × RGBrender/renderer.jsviewFloat32Array(16): camera, sun, fogrender/overlay.jsoverlaylist of print/rect/spr2dio/audio.jssoundsqueue of sfx/tone eventsshell/main.jsstoragedset / dget valuesBuilt: JavaScript corecore.js · api.jsvram.js: the two layerslua.jswasmoon: Lua 5.4 wasmevery API call crosses JS ↔ wasmlayers live in JS Uint8ArraysLater: Rust core, one .wasmRust machine + C Lua 5.4compiled into the same moduleAPI calls are direct calls inside wasmlayers = zero-copy views into wasm memoryswap behind the same ports
Figure 8. What crosses the machine boundary. Everything on the left (shell, renderer, input, audio) talks to the core only through these eight ports, each carrying plain data. That is why the JavaScript core can later be replaced by a Rust core with Lua built into the same .wasm later. The ports are the TesseraCore object in src/core/core.js; slot 32 of the input array carries the mute key.
Now: Lua in wasm, machine in JScart: box(...)Lua VM (wasm)callbridgeconvert argscrossvram.jsfill loop in JSwritesUint8ArrayJS memoryLater: Lua and machine in one wasmcart: box(...)Lua VM (wasm)direct callRust box()same modulewriteslinear memory8 MiB layersreadsrendererzero-copy view
Figure 9. The expensive part is not filling voxels, it is each Lua-to-host call. One box() crosses the bridge once and fills thousands of voxels on the host side, which is why the API favours big calls. A cart that calls vset 10,000 times per frame crosses 10,000 times. With Lua and the machine in the same .wasm, the crossing (coral) disappears. Measured on this console, fast argument passing brought a typical seven-argument call to about 3 µs (Lua calls and speed); a benchmark decides when the Rust core is worth building.

In code, the boundary is small enough to write on one card:

// The machine boundary: the object createCore() returns (src/core/core.js).
// A later Rust core fills the same ports.
const core = await createCore();

core.load(cartText);   // fresh machine, parse, run the Lua: {ok} or {ok: false, error}
core.init();           // runs _init once
core.tick();           // one 30 Hz tick: runs _update
core.draw();           // runs _draw into the draw layer

core.input;      // Float32Array(33): 4 players x (6 buttons + 2 axes), then mute
core.map;        // Uint8Array, 256*256*128 = 8,388,608 bytes
core.drawLayer;  // Uint8Array, same size, emptied by cls()
core.palette;    // Uint8Array(768): 256 x RGB
core.view;       // Float32Array(16): camera, zoom, yaw, sun, sky, fog
core.overlay;    // HUD commands for this frame
core.sounds;     // sfx / tone events since the shell last took them
core.storage;    // dset / dget values
core.error;      // {line, message} for the Tessera error screen, or null

In a later Rust version, the layers would be views straight into WebAssembly memory, so nothing is copied before upload.

06Carts

A cart is everything a game needs in one file: its name, colours, voxel models, sounds and code. It comes in two forms that hold the same thing.

tessera cart v1__meta__title=Hat Chaseauthor=Stephen Wilson__pal__1 1b1b202 2c2c34__models__hat 10x10x12 pivot=4,4,01d 1d 1c 1c 1d 1d 1c 1c 1d 1d1d 1d 1c 1c 1d 1d 1c 1c 1d 1d1c 1c 1d 1d 1c 1c 1d 1d 1c 1c1c 1c 1d 1d 1c 1c 1d 1d 1c 1c1c 1c 1c 1c 1d 1d 1c 1c 1d 1d1c 1c 1c 1c 1d 1d 1c 1c 1d 1d … 4 more rows, then slices z=1 … z=11__sfx__0 square 880>440 0.15 0.5__lua__function _init()  build_world() -- the map layerend__meta__after the first line, which namesthe format: key=value lines__pal__index + RGB hex per line;leave out for the default palette__models__header: name, w×d×h, frames, pivotthen each z slice, bottom first:10 rows of 10 two-hex-digit indices.. = emptythis is the real Hat Chase hatfrom carts/hatchase.tess__sfx__n wave f0>f1 dur vol (an example)__lua__the program, Lua 5.4
Figure 10. A .tess cart is plain text, so it diffs cleanly in git and can be read in any editor (or in Tessera's own code editor, F4). The model shown is the real hat from the built carts/hatchase.tess: 10 wide, 10 deep, 12 tall, its colours indices into the cart's own __pal__. The __sfx__ line is an example: Hat Chase makes its sounds with tone(). The port converted every source model at twice the detail, so each original cube became 2 × 2 × 2 voxels.
one label pixel (RGBA, 8 bits each)one byte of compressed cart101101100xB6, split intofour 2-bit pairsR110110000xD8110110100xDAG001101000x34001101110x37B001111000x3C001111010x3DA111111110xFF111111100xFEbeforeafter: looks the same256 × 256 pixels= 65,536 pixels × 1 byte= 64 KiB of compressed cartPNG file: data survivesre-saved as JPEG: data lost(lossy, changes low bits)
Figure 11. A picture cart is a 256×256 PNG whose image is the cart's label (a screenshot). The compressed cart text hides in the two lowest bits of every channel, one byte per pixel, which shifts each colour by at most 3 out of 255. The PNG can be shared like any picture; re-encoding it to JPEG destroys the data. A small header (TESS, version, length and a CRC-32) tells the reader where the data ends and whether it survived. Hat Chase compresses to 28.6 KiB, well inside the 64 KiB.

07The API

Every function a cart can call, grouped by job (src/core/api.js). Square brackets mark optional arguments. Coordinates are voxels (x, y across, z up) for the 3D calls and pixels for the HUD. Buttons: 0 left, 1 right, 2 up, 3 down, 4 A (Z or Space), 5 B (X or E), and the same on a standard gamepad.

Map layer persists between frames

mset(x,y,z,c)
set one map voxel
mget(x,y,z)
read one map voxel
mclear([c])
empty (or fill) the whole map
mbox(x0,y0,z0, x1,y1,z1, c)
fill a box on the map
mmodel(id,x,y,z,[rot],[flip])
stamp a model into the map
mheight(x,y)
top of the map column at x,y

Draw layer cleared every frame

cls()
start the frame: empty the draw layer
vset(x,y,z,c) · vget(x,y,z)
set / read one voxel this frame
box(x0,y0,z0, x1,y1,z1, c,[hollow])
solid or hollow box
sphere(x,y,z,r,c)
filled ball
line3d(…)
a line of voxels
model(id,x,y,z,[rot],[flip],[frame])
draw a model (animation frame)
particle(x,y,z,c,[life])
short-lived speck

Models

msize(id)
a model's size
mvox(id,[frame])
a model's voxels, as a table
newmodel(id,w,d,h,[frames])
make an empty model
mpset(id,x,y,z,c,[frame])
set a voxel inside a model

Palette

pal(i,r,g,b)
set colour i (1–255)
palt()
reset to the cart's palette
pswap(a,b)
swap two colours

Camera and light

camera(x,y,z,[zoom],[yaw])
where the view looks
sun(dx,dy,dz,[strength])
sun direction for light and shadow
sky(top,bottom)
background gradient
fog(c,density)
distance fog

HUD (2D overlay) 768 × 432 pixels

print(s,x,y,c,[outline],[scale])
5 × 7 pixel-font text
rect(…) · rectfill(…)
rectangles
circfill(…)
filled circle
spr2d(…)
2D icon
textw(s)
width of s in pixels
project(x,y,z) → sx,sy
voxel position to screen pixel

Input up to 4 players

btn(b,[p])
is button b held
btnp(b,[p])
did b just go down
axis(n,[p])
stick axis n, −1..1

Collision & Space fast host physics queries

raycast3d(x0,y0,z0, dx,dy,dz, [max_d], [layer])
3D DDA raycast: hit, x, y, z, nx, ny, nz, c, dist
check_box(x0,y0,z0, x1,y1,z1, [layer])
test if AABB contains any voxel: hit, x, y, z, c
sweep_box(x0,y0,z0, x1,y1,z1, dx,dy,dz, [max_d])
sweep AABB along vector: hit, dist, x, y, z, nx, ny, nz, c
sweep_down(x,y,z, [w], [d], [max_drop])
drop footprint down: hit, ground_z, dist, x, y, z, c
vheight(x,y, [w], [d], [layer])
highest solid voxel in footprint (−1 if empty)

Sound & Music 4 channels

sfx(n,[ch])
play sound n from __sfx__
tone(wave,f0,f1,dur,vol,[ch])
one pitch slide
mute()
toggle sound; M key too
music(id,[fade],[mask])
start a __music__ song
music_stop([fade]) · music_pos() · music_vol([v])
stop, query row, or set volume

Misc

t()
seconds since start
rnd(n)
random 0..n
flr(x) · mid(a,b,c)
floor · middle value
noise3(x,y,z)
smooth 3D noise
stat(n)
0 fps · 1 update ms · 2 draw ms · 3 composite ms · 4 last input
dset(i,v) · dget(i)
save slots
printh(s)
print to the host console
quality([q])
graphics: "hq" (smooth, native-res) or "standard"; returns what is in use
Figure 12. The API on one page. Map calls start with m and last; draw calls are redone every frame.

08Your first cart

Six steps from an empty cart to a hat you can steer, with sound and a save. Each step adds a little to the last. The pictures are sketches of what you should see; paste a step into the code editor (F4) to see the real thing.

  1. Step 1Hello, box

    Every cart is Lua 5.4. Tessera calls _draw once per displayed frame. Clear, draw one box, print one line.

    function _draw()
      cls()                                 -- empty the draw layer
      box(120,120,0, 135,135,15, 76)        -- a 16-voxel sand cube
      print("hello, tessera", 8, 8, 15)     -- HUD text, white
    end
    hello, tessera

    You should see: A sand-coloured cube in the middle of the floor, and white pixel text in the top-left corner.

  2. Step 2Make it bounce

    t() is the time in seconds. Lua has no +=, and maths lives in math.

    function _draw()
      cls()
      local z = 16 + math.abs(math.sin(t() * 3)) * 80
      sphere(128,128,z, 16, 23)                -- radius 16, red
      print("boing", 8, 8, 15)
    end
    boing

    You should see: A red ball bouncing up and down about once a second. Nothing needs erasing: cls() empties the draw layer every frame.

  3. Step 3Build a world once

    Things that never move go on the map layer in _init. It stays put; cls() only empties the draw layer on top of it.

    function _init()
      mbox(0,196,0, 255,255,0, 168)      -- sea to the north (high y)
      mbox(0,0,0,   255,195,1, 76)       -- sand, 2 voxels deep
      for x = 226,243 do                 -- one striped hut
        local c = (x // 2 % 2 == 0) and 23 or 15
        mbox(x,140,2, x,159,24, c)
      end
    end
    
    function _draw()
      cls()                              -- the map stays
    end
    map built once

    You should see: A beach: a strip of sea at the back, sand everywhere else, and one red-and-white striped hut.

  4. Step 4Move the hat

    Read buttons in _update (30 times a second) and draw in _draw. Buttons 0–3 are left, right, up, down; up is north, which is +y.

    hx, hy = 128, 96
    
    function _update()
      if btn(0) then hx = hx - 2 end
      if btn(1) then hx = hx + 2 end
      if btn(2) then hy = hy + 2 end     -- up = north = +y
      if btn(3) then hy = hy - 2 end
    end
    
    function _draw()
      cls()
      model("hat", hx, hy, mheight(hx, hy))
      camera(hx, hy, 0)                  -- follow the hat
    end
    ◀ ▶ ▲ ▼ move the hat

    You should see: The red hat sits on the sand. Arrow keys or WASD (or a drag on a touch screen) slide it around and the camera follows. (Add your _init from step 3 and a hat model in the cart's __models__.)

  5. Step 5Make a sound

    btnp is true only on the tick a button goes down. tone plays a quick pitch slide.

    function _update()
      -- ... movement from step 4 ...
      if btnp(4) then                    -- A: Z or Space
        tone("square", 880, 440, 0.15, 0.5)
      end
      if btnp(5) then sfx(0) end         -- B: sound 0 from __sfx__
    end
    A pressed: boop!880 → 440 Hz in 0.15 s (drawn 20× slower)

    You should see: Press Z or Space for a short falling “boop”. X or E plays sound 0 from the cart. M mutes.

  6. Step 6Save your cart

    Open the pause menu to export a .tess.png picture cart with a screenshot on the front, or keep the .tess text file. Drag either one onto Tessera to load it, or open ?cart= with a bundled cart's name.

    -- high scores survive between plays:
    function _init()
      best = dget(0)                     -- save slot 0
    end
    function win(score)
      if score > best then best = score; dset(0, best) end
    end
    hat.tesstexthat.tess.pngpicture

    You should see: Two files: hat.tess (readable text, good for git) and hat.tess.png (a picture you can share). Both load the same cart.

Starting outside the browser with npm

You can scaffold, develop, pack, and export a cart from your own editor without cloning the engine repo using the public npm packages @stephenwil/create-tessera and @stephenwil/tessera:

npm create @stephenwil/tessera@latest my-game
cd my-game
npm install
npm run dev    # live-reload console at http://localhost:3000
npm run check  # validate manifest and Lua structure
npm run pack   # emit dist/my-game.tess and dist/my-game.tess.png
npm run build  # export standalone offline dist/my-game.html

# Or list and start from any playable showcase cart
npx @stephenwil/tessera@latest samples
npx @stephenwil/tessera@latest pull bramblecourt --project my-arena
npm create @stephenwil/tessera@latest my-arena -- --template bramblecourt

Building carts with AI agents (MCP)

AI coding agents with terminal access can run the npm CLI directly. For tool-driven clients (Claude Desktop, Cursor, T3 Code), connect the built-in Model Context Protocol (MCP) server (npx -y @stephenwil/tessera@latest mcp or npx -y @stephenwil/tessera-mcp@latest) to expose 8 structured tools for scaffolding, syntax checking, MagicaVoxel palette budgeting, picture-cart packing, HTML export, and live API reference lookup.

09Porting Hat Chase

Hat Chase already had the Tessera shape: a 128 × 128 beach, voxel models made of coloured cubes, an orthographic camera and small synth sounds. The port moved each part to the matching Tessera feature, then doubled everything for the high-res world. The cart's source lives in the private tessera-hatchase repo; this repo keeps the built carts/hatchase.tess.

025664192128128192642560sea: redrawn every framelighthouse on the headlandrock poolsstriped beach hutssanddunesx (east) →N ↑ (y grows north)
Figure 13. The Hat Chase beach from above, computed by running the game's own terrain rules from world.js (the same rules world.lua runs in the cart) and colouring each column with a default-palette index. In Tessera everything here except the sea goes on the map layer once, in _init. North (the sea) is at the top, at high y: the built port sets y = 127 − old z, then doubles every axis, so each source column becomes 2 × 2 voxels and each height doubles.
three.js (Hat Chase)y is upxy (up)z (south)Tesseraz is up, y is northxz (up)y (north)rotate(x, y, z) → (x, −z, y)then × 2 for high res
Figure 14. Porting turns the axes: Tessera keeps x, uses the old y (up) as z, and the old z (south, towards the camera) negated as y, so y points north. That is a rotation, not a mirror, so left stays left and turning directions keep their sense: Betsy's white left front paw stays on her left. The built port writes it as y = 127 − old z, then doubles every axis.
PartHat Chase (three.js)In Tessera
Terrainworld.js builds column segments into one InstancedMeshworld.lua runs the same rules and fills the map layer once in _init, every box doubled
Voxel models[x, y, z, "#hex"] lists in models.js__models__, re-converted from the source at 2 × detail; hex colours become the cart's __pal__
Leg animationleg groups rotated by Math.sin each framemodel frames (Betsy has frames=6), chosen with model(…, frame)
Turningdogs rotate to any angledogs are drawn at quarter turns: odd angles fatten thin parts of a model
Animated seaupdateWater rewrites 128 × 52 instances per frameredrawn into the draw layer every frame; only its changed bricks are uploaded
Follow cameraOrthographicCamera, offset (0, 72, 100): about 36° downcamera(x,y,z,[zoom],[yaw]); the raymarcher is orthographic at ~35°
ShadowsPCF shadow map, 2048 × 2048one shadow ray per pixel toward sun()
Round moodsmidday, afternoon, sunset light colourssun(), sky() and pal()
HUDDOM elements (banner, shells, stars)overlay: print, rectfill, spr2d
PopupsDOM text placed over the 3D sceneproject(x,y,z) gives the pixel, then print
Paw prints, sandparticle meshesparticle(x,y,z,c,[life])
SoundWebAudio tone() and noise()tone() on the 4-channel synth (noise is a wave)
Controlsarrows/WASD run, Space special, E sniff; drag to run on touchbuttons 0–3, A (Z/Space), B (X/E), gamepad, and the shell's touch controls
Rounds, stars, shellsJavaScript state in main.jsplain Lua tables; no fail state, as now
Character rules the port keeps
  • Only Betsy's left front paw is white. The axis change is a rotation, so her left stays her left.
  • Never state Betsy's or Sunday's age.
  • No golden scallop shell.

10Built and next

Built

  • Name Tessera; carts .tess and .tess.png (export from the pause menu, drag-drop to load)
  • 256 × 256 × 128 volume, 1 byte per voxel, map and draw layers of 8 MiB each
  • Per-cart palette of 255 colours, 0 empty, default palette as fallback
  • WebGL2 orthographic DDA raymarcher at 768 × 432 (plus quality("hq")), brick skipping, brick uploads, frame reuse, and a 5 × 7 font overlay
  • Fixed 30 Hz _update; _draw every displayed frame
  • Lua 5.4 via wasmoon, with a watchdog, cart line numbers on errors, and host-side collision probes (raycast3d, check_box, sweep_box, sweep_down, vheight)
  • Keyboard, gamepad (menus too) and touch; 4-channel synth; mute
  • Code editor (F4) with Lua colouring and jump-to-error; voxel model editor (F5); stats overlay (F3)
  • Public npm developer kit (@stephenwil/create-tessera, @stephenwil/tessera CLI) and MCP server (@stephenwil/tessera-mcp) for AI coding agents
  • Hat Chase, 60 fps on a desktop GPU and a phone, plus more carts in carts/

Next

  • Music tracker authoring polish for the __music__ section and pattern player
  • Zero-allocation 3D math primitives (vec3, quat)
  • Headless tick simulator / frame capture MCP tool for AI visual inspection
  • Rust core with Lua in the same .wasm: when a benchmark says it is worth it
  • Still open: model() rotation at odd angles fattens thin models; touch needs a real-tablet check