# brainrot 012: campfire Live: https://brainrot.runfridge.dev/012/ Source: https://github.com/hwhang0917/brainrot/tree/main/012 License: MIT (see LICENSE at repo root); attribution only, no warranty. Sounds: the .mp3 files come from Mixkit and Pixabay under their own licenses, not MIT (see LICENSE). ## What it is A campfire in the night woods: two crossed logs in a ring of stones, domain-warped flames, smoke, heat shimmer and rising embers, under moonlit mountain ridges, conifers, grass, tonight's real moon phase and tonight's real stars, with an occasional shooting star. The pointer holds a stick from off the bottom-right corner. Tools (bottom bar or keys 1/2/3; picking one always gives a fresh one): 1 marshmallow: hold it near the fire to toast it (tan, freckled, glossy caramel, dark brown, sooty blotches from the flames, char), it goes gooey in the heat, chars, catches fire (shake hard to blow it out), burns away, then the bare stick chars and burns down; click/tap the marshmallow to bite it (3-4 bites). 2 sparkler: light it in the fire, it fizzes and throws sparks for 67.85 s (the length of its sound), nothing puts it out. 3 flame powder: click to throw a pinch that arcs into the fire and tints the flames green/blue/violet/teal for up to 3 s. Right click lowers/raises the stick. G toggles a looping guitar tune. Sound: crackle and crickets loop (via the site's sound gate and a mute button), plus bite, packet-shake, sparkler and guitar clips. URL params: `?date=YYYY-MM-DD[THH:MM]` previews another night's sky and moon (the clock runs on from there), `?lat=` sets the latitude (default 37). ## How it was built - Rendering: pixi.js v8 with `preference: 'webgl'`. The entire scene is one GLSL fragment shader (fire.frag.ts, ~600 lines) applied as a pixi `Filter` to a full-screen black `Graphics` rect, with a custom vertex shader that passes `vUv` (the quad's own 0..1 position) because the filter's texture coordinate depends on the pooled texture size and scaled the scene off-centre. Embers, sparks, powder grains (additive) and ash flakes (normal blend) are pixi Sprites of one radial-gradient texture layered over it, capped at 120 embers / 500 particles. - Shader structure: one flicker shared by every lit surface (what sells it as one place); sky, star texture with twinkle, photographed moon (moon.webp) with a true elliptic terminator and earthshine; meteor; six overlapping ridged-noise mountain ridges (snow on the far two, lit by the moon); valley mist; three ranks of cell-placed conifers with tiers, needle clumps and fire-side rim light; undergrowth; foreshortened ground and grass; 18 stones drawn in back and front passes; logs with glowing alligator-char cracks; the flame (domain warping, white-hot heart, hot-body ramp, blue lick, powder tint streaked between the newest and previous colour); smoke; then the stick, sparkler or marshmallow (lumpy puff, bites, goo sag, browning stages, soot, char cracks, its own flame and smoke). - Coordinates: scene x in [0, aspect], y up in [0, 1], fire at (aspect/2, 0.30). main.ts FIRE_Y is 0.70 from the top (same point). Many constants are duplicated between main.ts/modules and the shader and commented "matches the shader": FIRE_Y, SPARKLER_LENGTH, STICK_BAND, MALLOW_R/MR, HAND. - Sky: stars.json is ~900 [ra, dec, mag] entries from the Yale Bright Star Catalogue down to mag 4.5. main.ts projects them with stars.ts (sidereal time, alt/az, flat projection facing south up north / north down south, horizon at y 0.2, 90° per screen height) into a RenderTexture of dots, redrawn every 20 s. Longitude is the timezone's central meridian (no geolocation prompt). Moon phase is the mean synodic cycle from a reference new moon. - Toasting model (marshmallow.ts): heat = (1 - d)^3 over an ellipse squashed vertically, reach 0.5; doneness 0 raw / 1 golden / 2 charred / 3 gone, 4 s raw to golden at the heart; soot only above heat 0.5; softening only between half-golden and charred; char ignites at heat 0.3, a lit marshmallow burns at heat >= 0.5 anywhere, stick speed >= 1.6 screen heights/s blows flames out. The sparkler catches on simulation time but burns on the wall clock (uncapped) so it stays in step with its audio. - Interaction rules from history: the tip rides 0.09 above the pointer so a finger does not cover it; the stick stops at arm's reach (1.15 screen heights); a tap more than 48 px from the stick only moves it (touch has no hover), a click on it bites; a lowered stick drops straight down out of view; picking a tool raises it and always puts a fresh one on (a lit sparkler never comes back lit). - History: started as a procedural scene shader with embers and crackle; then muted-by-default sound, crickets, shooting stars (made rarer, smaller and slanted 36°-54°), the marshmallow, sparkler, livelier fire, real moon photo and phase, real star sky, the layered mountains/forest backdrop, bites, flame powder, right-click lower; later the lib sound gate, staged toasting with soot, and the guitar (first with seat logs and a cartoon guitarist with notes, then cut back to just the sound toggle); last, the ring of stones. Vibe coded: prompted into existence with a coding agent, iterated commit by commit. ## Files - 012/index.html: page shell, inline CSS (cursor none on the canvas, grab for powder), mute, CRT and guitar (G badge) buttons, "unmute for the crackle" hint, tool bar with 1/2/3 key badges. - 012/main.ts: pixi app, custom vertex shader + Filter wiring and the UniformGroup (uTime, uMallow, uStick, uFlame, uTint/uTint2, uPhase, uMeteor...), star drawing, particles, pointer/keys/tools, stick kinematics and state stepping, WebAudio (loops, one-shots, sparkler sync, guitar fade), meteors, ticker; imports `mountCrt` (lib/crt.ts), `mountHud` (lib/hud.ts), `mountSoundGate` (lib/soundGate.ts). - 012/fire.frag.ts: the whole scene as a GLSL ES 3 fragment shader exported as a string. - 012/marshmallow.ts: pure heat/cook/soot/soften/ignite/stick-burn/sparkler/bite model and their constants. - 012/powder.ts: powder colours, tint timing, `toss` ballistic velocity to land in the fire after 0.6 s. - 012/moon.ts: `moonPhase(date)`, 0 new, 0.5 full. - 012/stars.ts: `siderealTime`, `altAz`, `project`, DEFAULT_LAT, HORIZON_Y, DEG_PER_UNIT. - 012/stars.json: star catalogue data, an array of [ra deg, dec deg, magnitude]. - 012/*.test.ts: marshmallow (heat falloff, cooking, soot, goo, ignition/blow-out, stick, sparkler, bites), moon (known new/full moons), powder (toss lands on target), stars (J2000 sidereal time, Polaris, equator rise/set, facing and culling). - 012/campfire.mp3, crickets.mp3 (loops), eat.mp3, shake.mp3 (one-shots), sparkler.mp3 (67.85 s, sets SPARKLER_SECONDS), guitar.mp3 (looped tune); 012/moon.webp (photo of the full disc, transparent around it). ## Extending it - Run: `npm install && npm run dev`, open http://localhost:5173/012/ . Tests: `npm test`. Typecheck+build: `npm run build`. - Knobs: particle, audio gain, stick and meteor constants at the top of main.ts (gains are commented with how hot each file is relative to the crackle); toasting/burn timings in marshmallow.ts; powder in powder.ts; sky geometry in stars.ts; scene layout constants (FIRE_*, RING, STONES, MOON_R, meteor) at the top of fire.frag.ts. - If you move the fire, the stick hand or the sparkler/stick lengths, change both sides (TS constant and shader const); they are kept in sync by hand. - fire.frag.ts declares `precision highp float;` itself: Pixi's default is mediump, and where mediump is a real 16-bit float (ANGLE on Vulkan, SwiftShader, phones) fbm's growing coordinates overflow, fract() returns NaN and the valley mist mixes that NaN into every pixel, so the whole scene renders black with only the sprites (logs, embers) visible. - New per-frame state for the shader: add it to the UniformGroup with an explicit type and a matching `uniform` in fire.frag.ts. Keep everything in scene units, not pixels (`uPixel` is one pixel for anti-aliasing). - Audio starts only after a gesture: `unlock()` builds the AudioContext; anything that plays must check `audio`/`master` and be re-synced in `unlock()` (see syncSparklerSound/syncGuitarSound). Buttons stop pointerdown propagation so they do not bite or throw powder. - Simulation time `dt` is capped at 0.05 s; use `wallDt` only for things that must keep pace with audio. - Debug: `?date=` and `?lat=` let you check other skies and moon phases without waiting. - Conventions: keep pure simulation in its own module with a `node --test` file beside it; match the surrounding code style; Conventional Commits `type(012): message`.