Teaching a Diffusion Model to Read a G-Buffer
If you’ve read Noatun: six days under water or the earlier ocean posts on this log, you already know how much blood goes into making water look believable the classical way. Spectral wave cascades, inverse FFTs, history-buffered foam, hand-tuned refraction, caustic projections, fog curves, lens-edge shading hacks — hundreds of shader passes fighting over the last twenty percent of how light behaves underwater. Every time you want a slightly richer surface, a deeper shaft of light, or a softer caustic dance across sand, you pay for it in shader complexity, art time, and frame budget.
This week I ran a follow-up experiment on Noatun and asked a question that has been sitting at the back of my head for a year:
What if the game engine stops trying to shade the world, and only tells a neural model what is actually there?
Not a prompt-driven fever dream. Not a “world model” hallucinating corridors as you press W. A strict division of labour: the engine owns where everything is; a video diffusion model owns how it looks.
Here is the showreel from our first full Gate 2 evaluation — five completely unseen camera paths, synthesized purely from depth, unlit base colour, and object class IDs, with zero start-frame reference:
Full Gate 2 breakdown reel (watch in 1440p on YouTube): a 15-second Engine ↔ Neural split-wipe showcase, the G-buffer conditioning pipeline, all five held-out comparisons against zero-shot Wan2.2-Fun-5B-Control, G-buffer ablation tests, and guidance-scale tuning.
Look closely at the opening split-wipe. The shark glides across the divider line and the neural renderer tracks the exact silhouette, the exact rock overhangs, the pink corals tucked into the crevices, the kelp fronds swaying behind it — with zero start frame, across five chained 81-frame windows, without drifting into someone else’s reef. In a few spots the caustics and water haze even feel slightly softer and more organic than the rasterized reference.
This post is what we built to get there, what still breaks, and why I think this architecture hints at a genuinely new era for how games and virtual worlds get rendered.
The contract: truth in the engine, light in the weights
Pure end-to-end “world models” — neural networks that take controller inputs and predict the next frame directly — make extraordinary Twitter demos and terrible games. A real game needs truth. Collision meshes that don’t shift when you look away. Save files. Deterministic replays. Visibility checks. Creatures that remember where they were three minutes ago. An economy or physics solver that stays exact down to the last millimetre.
Classical engines are already brilliant at truth. Even a modest Bevy scene can simulate hundreds of thousands of kelp blades, articulated sharks, deterministic camera paths, and exact spatial queries in a couple of milliseconds. What is brutally expensive in classical engines isn’t knowing where a rock is — it’s simulating the infinite tail of light transport once rays hit that rock through twenty metres of sunlit, particle-heavy ocean water.
So we split the pipeline down the middle, borrowing the core idea from NVIDIA’s DiffusionRenderer and Matrix-Game 4.0:
- What the engine keeps forever: physics, collision, creature AI, camera paths, visibility, world state — emitted each frame as a cheap, deterministic G-buffer stack (depth, unlit albedo, semantic class IDs).
- What the neural model is allowed to invent: caustics, volumetric light shafts, turbidity, backscatter, micro-surface texture, colour absorption with depth, subtle organic motion.
- What the neural model must never invent: geometry, object identity, walls that aren’t there, or open water where solid reef sits.
Instead of jumping straight to real-time distillation (which would have cost over $1,500 and a month of runtime engineering before we even knew if the conditioning worked), we ran the experiment in strict gates: prove the offline conditioning contract first on an open-weights Apache-2.0 video model (Wan2.2-Fun-5B-Control), inside a $50 cloud budget, judged by side-by-side movies and an automated metrics harness on strictly held-out camera paths.
Why depth alone isn’t enough
Step one was the honest baseline: feed Wan2.2-Fun-5B-Control our exact log-normalized depth maps and a single neutral underwater caption, zero-shot, no training.
The result was instructive and immediately disqualifying as a renderer. On single stills it looked lush — and completely wrong. Given only depth, a pretrained video model falls back on its internet prior of “underwater documentary”: it paints generic green-blue brain corals onto rocky walls, replaces pink sea fans and tube sponges with flat aquarium sand, turns sharks bright teal-yellow, drifts in palette over time, and quietly erases solid near-field geometry into smooth open water (1.80% pooled invented water across the five held-out clips, spiking to 4.69% on close-up sponges).
Clip 5 (held-out, 15 seconds, 5 chained windows). Top-left: Noatun engine reference. Top-right: fine-tuned G-buffer model. Bottom-left: zero-shot depth-only baseline inventing brain corals and neon sand. Bottom-right: the exact Depth, Unlit Albedo, and Semantic Class inputs feeding the network in lockstep.
Depth tells a model where surfaces sit in space, not what they are made of. Without material and semantic identity, the network has no choice but to guess — and a guessing renderer breaks the contract.
Opening the patch embedding (148 → 256 channels)
To let the network actually read Noatun’s world without throwing away Wan2.2-Fun-5B-Control’s pretrained temporal and optical priors, we extended the diffusion transformer’s input patch embedding from 148 to 256 channels using zero-initialized extra input columns alongside a Rank-64 LoRA:
- 148 original channels: noisy video latents, VAE-encoded log depth, mask, and optional start-frame latent.
- +48 channels — Unlit Albedo: pure base surface colour with zero lighting, zero fog, and zero caustics, encoded through the Wan2.2 VAE.
- +48 channels — Semantic Class Palette: 14 world classes (open water, surface, sand, terrain rock, boulders, coral, sponge, kelp, ground plants, fish, sharks/large fauna, stone features) encoded through the VAE.
- +12 channels — Exact Latent Class Fractions: computed directly per
16×16×4latent cell, bypassing the VAE altogether.
That last 12-channel lane came directly out of measuring before training. Before spending a single dollar on cloud GPUs, we ran a VAE round-trip check on our laptop and discovered that the Wan2.2 VAE preserves large rocks and sand cleanly, but smudges away 60–73% of small fish and up to half of ground plants in the palette video. Passing exact per-cell class fractions straight into latent space gave the transformer crisp semantic sight of small moving fauna and flora that the VAE would otherwise blur out.
What the network sees versus what it paints (held-out Clip 2). Top-left: log depth. Top-right: unlit albedo with no lighting, shadows, or water absorption. Bottom-left: semantic class map. Bottom-right: the fine-tuned neural render synthesizing volumetric shafts, water attenuation, shadows, and sand caustics from scratch.
A few training decisions turned out to matter just as much as the channel layout:
- 70% start-frame dropout. Most video control models secretly lean on the first RGB frame to carry colour and identity forward. Dropping the start frame in 70% of training steps forced the network to synthesize the entire look purely from G-buffers — which also broke the compounding colour drift you get when chaining long shots off each window’s previous output.
- Independent modality dropout (10% each) on depth, albedo, class, class fractions, and text (dropping captions to the negative prompt so classifier-free guidance stays calibrated).
- One fixed, boring caption for every clip — zero style adjectives like “photorealistic” or “documentary” — turning the prompt into a constant anchor while the G-buffers carry 100% of the scene semantics.
- Strict held-out discipline. Five camera paths (
c1–c5, 845 frames total, including a 15-second 5-window reef swim) were locked out of training from day one and evaluated with a frozen automated harness (LPIPS, low-passΔE00colour drift, depth-edge recallκ@2, invented open water, and window-seam jump ratios).
We trained on a single cloud GPU (A100) to checkpoint 2,750, then ran all 25 Gate 2 evaluation and sweep renders on an L4. Total compute from first training step to final Gate 2 movies: ~45 Colab compute units. No cluster. No giant budget. Just a disciplined loop.
Proof that it isn’t a parlour trick
Whenever you extend a pretrained diffusion model with extra input channels, there’s a classic failure mode: the LoRA memorizes the dataset’s colour grade from depth alone and quietly ignores your shiny new G-buffers.
So we built a blunt diagnostic right into Gate 2: take the exact same checkpoint (step 2,750), the exact same random seed, and the exact same depth map, and zero out the 108 extra G-buffer channels at inference.
Ablation on held-out Clip 4 (same checkpoint, same seed, same depth). Left: all G-buffers active. Right: Albedo, Class, and Class Fractions zeroed out. Frame MAE jumps by 67.8 levels (latent relative L2 = 1.07); the sponges and background corals collapse straight back into anonymous grey-green rock.
On the deep shark pass (c3), zeroing those 108 channels collapses depth-edge recall κ@2 by 76% (0.806 → 0.191) and sends invented open water skyrocketing 126× (0.1% → 12.6%). The network isn’t hallucinating a plausible reef from depth — it is actively reading the unlit albedo and class buffers pixel by pixel to decide what every surface is.
What still breaks (the honest list)
Side-by-sides or it didn’t happen — and watching the movies immediately surfaced three real limitations that matter for what comes next:
- Unlit buffers don’t know how deep or dark a scene is. Camera depth is relative to the viewer, and albedo is unlit. On a dark, murky deep-water pass (
c3), the model has no signal telling it the ambient sun is dim, so it drifts upward toward the training set’s average brightness (and on the close-up lavender sponge inc4, under-applies the cool blue-cyan underwater absorption, shifting it pink). The fix is obvious and clean: add a compact coarse lighting / world-depth cue so the network knows ambient illumination as well as geometry. - CFG 1.0 leaves temporal shimmer. Our first batch of long shots ran at
CFG 1.0, which kept geometry tight but left elevated frame-to-frame micro-shimmer (2.29×engine median pooled;4.12×on the dark shark pass). Running a 10-point guidance and LoRA-strength sweep immediately paid off: moving tostrength 0.8, CFG 6.0drops temporal shimmer from4.02× → 2.90×and pulls the dark scene’s contrast closer to the engine (ΔE00 23.32 → 20.97) while holdingκ@2 = 0.810and0.4%invented water. - A fine-tuned model can at most match its training targets. Right now, the neural output looks remarkably close to Noatun’s own Bevy renderer — because Noatun’s own Bevy renderer was the training target. That wasn’t an oversight; this gate’s sole job was proving the G-buffer contract holds with zero drifting and zero hallucinated geometry. Now that the contract holds, the visual ceiling is no longer the network — it’s whatever targets we choose to train it on.
Guidance and LoRA-strength sweep on Clip 3. Raising CFG from 1.0 to 6.0 at strength 0.8 cuts frame-to-frame shimmer from 4.02× down to 2.90× and tightens dark-water contrast while keeping geometry recall above 0.81.
The numbers
Pooled across all 5 held-out sequences (845 frames), rendered with zero start-frame conditioning at 864×480, 24 fps, 40 steps:
| Metric | Zero-Shot (Depth Only) | Fine-Tuned (G-Buffer LoRA) | Change |
|---|---|---|---|
| Invented open water (pooled) | 1.80% |
0.26% |
7× reduction (c4: 4.69% → 0.00%) |
| Perceptual LPIPS (lower = closer) | 0.602 |
0.456 |
−24% |
Low-pass colour drift (ΔE00) |
22.60 |
17.74 |
−22% (c5 last 1 s: 25.79 → 7.14) |
| Window seam jump ratio (mean, 8 seams) | 5.20× |
3.15× |
−39% (c5: 5.3× → 2.2×) |
| Shared-frame window MAE (mean) | 28.6 |
25.6 |
−10% |
Depth-edge recall κ@2 (c3 / c4) |
0.350 / 0.403 |
0.642 / 0.828 |
huge lock on hard rock & sponge silhouettes |
Ablation (c3, zeroing extra 108 ch) |
— | κ@2: 0.806 → 0.191 |
−76% recall, 126× more invented water |
| Base model & adapter | Wan2.2-Fun-5B-Control |
Rank-64 LoRA + 148→256 patch embed |
Step 2,750, Apache-2.0 |
| Total cloud compute (train + 25 eval renders) | — | ~45 Colab units | Single A100 / L4 |
Where this goes — and why neural rendering feels different now
Step back from the underwater sharks for a minute and look at what actually just happened.
With a single consumer-accessible open video model, a couple of hundred lines of PyTorch to widen the patch embedding, and a weekend’s worth of single-GPU compute, a deterministic Bevy engine emitted unlit flat colours, depth, and integer object IDs — and a diffusion model faithfully synthesized a moving, lit, refracted, caustic-dappled 3D world out of them across completely unseen camera trajectories.
That unlocks three shifts that I think are going to reshape interactive graphics over the next five years:
1. The target-swap multiplier — art direction as a weight file. Once the G-buffer contract holds, your runtime engine only ever has to render cheap, flat, deterministic geometry — the kind of pass that runs in two milliseconds on a laptop GPU. Your training targets, however, can be anything you can render offline or capture in the real world: path-traced reference scenes taking ten seconds per frame in Blender or Cycles; cinema-grade volumetric fluid and caustic simulations; hand-painted gouache frames; or real 4K ocean documentary footage aligned via depth and segmentation. Swap the LoRA weight file and the exact same game — same hitboxes, same physics, same save file — can become photoreal path-traced ocean, 1970s Jacques Cousteau 16mm film stock, or a painterly Studio Ghibli reef. Lighting and material style decouple from runtime shader complexity.
2. The bridge from offline movies to real-time 60 fps is already under construction. Our prototype right now is offline: 40 denoising steps over 81-frame chunks, deliberately skipping distillation until we proved the visual contract. But look at where the open literature already stands today — causal autoregressive video diffusion transformers, 1-to-4-step trajectory distillation (CausVid, Self-Forcing, Matrix-Game 4.0), and tiny fast latent decoders (TAEHV) are already demonstrating 480p streaming at 30–60 fps around ~100 ms latency on a single high-end consumer GPU. Combine that algorithmic curve with FP4 tensor cores, unified high-bandwidth memory, and KV-cached video attention over the next two hardware cycles, and real-time neural shading stops being a research paper and becomes a graphics setting in the menu.
3. Classical game engines aren’t being replaced — they’re being liberated. For thirty years, the gap between a solo developer and a AAA studio was never imagination or game mechanics; it was the brute-force cost of authoring photorealistic textures, high-poly assets, and bespoke global illumination shaders. Pure pixel-predicting AI world models try to throw the engine away — and throw away determinism, gameplay precision, and authorial control along with it.
The hybrid path keeps everything we love about software engineering — deterministic Rust physics, reproducible seeds, clean ECS architectures, exact collision — and hands the impossibly expensive tail of light transport to a learned renderer that already understands how water scatters sunlight and how caustics dance on sand.
That is a future where a one-person studio can spend ninety percent of its time building worlds that feel right to play, and still put pixels on screen that used to take a lighting department of fifty.
Next: adding a coarse lighting cue so deep dark dives stay dark, re-rendering our long shots at CFG 6.0 to kill the shimmer — and then swapping the training targets from real-time Bevy frames to something far beyond what a rasterizer can do in 16 milliseconds.