At a glance

Crate
legaia-engine-render: winit + wgpu, a software VRAM page sampled in the fragment shader
Shared kernels
legaia-render-kernels - wgpu-free GTE maths, screen primitives, VRAM capture, emitters - linked by the browser host too
Always on
Affine UVs, flat per-primitive texture page and palette, PSX texture modulation, semi-transparency
Opt-in
Renderer::set_psx_mode gates the GTE’s register limits, vertex snap, 15-bit dither, the GPU’s 5-bit blend arithmetic and the field’s draw order only
Enhancements
Enhanced lighting, light shadows, camera-occlusion fade, volumetric fog, bloom - each off is retail
Draw lists
Battle HUD, menus and text come from engine-ui, shared with the browser host

A frame

Software VRAM 1024 x 512 halfwords Opaque scene depth write on Blend pass far to near, 4 modes Screen overlay ordering-table walk HUD, chrome, text engine-ui draw lists enhancements: identity when off Enhanced lighting moods, lamps, halos Occlusion fade screen-door discard Light shadows per-light PCF Volumetric fog not the retail pool VRAM capture drawn frame back into the page PSX mode (opt-in) GTE limits, vertex snap, 15-bit dither
Retail draws 3D primitives and screen-space packets through one ordering table; the port splits them into a scene pass and an overlay pass and joins them in one compositing target. The capture path is the direction the console gets for free: on a PlayStation the framebuffer is VRAM, so a primitive can sample pixels drawn moments earlier.

What is PlayStation about it

TraitGateWhat it reproduces
Affine UV interpolationunconditionalthe texture warp on surfaces with steep depth gradients. It is the faithful behaviour, not an effect
Flat texture page + palette per primitiveunconditionaleach triangle samples one page and one palette
Texture modulationunconditionaltexel * colour / 128 with the baked colour word - the game’s whole lighting on most paths
Semi-transparencyset_semi_blend, on by defaultthe four blend equations, per texel
5-bit blend arithmeticPSX modethe GPU’s truncating 5-bit blend: a half-and-half layer drops the half step, a quarter layer adds F>>2, and the frame reads as a 15-bit framebuffer (renderer)
GTE register limitsPSX modea corner whose eye-space X / Y or depth passes the GTE’s 16-bit IR / SZ saturation lands where RTPS wrote it, not where a plain projection puts it (renderer)
Sub-pixel vertex snapPSX modethe per-vertex shimmer on slow geometry; corners truncate onto the 320×240 grid and each scanline takes its texels at the row itself
15-bit ordered ditherPSX modethe cross-hatched gradients of a 5-bit-per-channel framebuffer
Field draw orderPSX modea nearer primitive losing to a farther one, as the ordering table paints it (below)

The play page’s PSX frame is single-sample. The page’s context has MSAA, which cannot change after creation and which WebGL cannot turn off on the canvas’s framebuffer. So a PSX frame draws into a single-sample framebuffer of its own (site/js/webgl-psx-target.js) and is copied to the canvas once; on the canvas a polygon edge would resolve to a blend of partly covered samples, which neither retail’s rasteriser nor the native renderer has. The enhanced mode keeps its MSAA.

There is no synthetic light. Retail runs no light source on the field path: shading is baked into each primitive’s colour word and the only colour operation is the depth cue. A missing colour stream defaults to white, and white reads as too bright, not unlit - the usual sign that a draw lost its colours.

Semi-transparency is two passes

Whether a texel blends is decided per texel: bit 15 of the palette entry picks blend or opaque inside one semi-transparent primitive. So the opaque pass draws everything and discards those texels, and a blend pass re-draws only the semi-transparent triangles, keeping only them.

A whole draw can be made semi-transparent too. Retail reads the top byte of an actor's colour word as primitive flags and ORs them into every packet, so one byte turns every primitive of the actor into a blended one. The port carries that byte per draw: the opaque pass treats every primitive of the draw as semi-transparent, and the blend pass re-draws the whole mesh in the forced mode. Underground Octam's corridor pillars use it (field-VM 4C D6).

ModeEquation
00.5 * B + 0.5 * F
1B + F (additive)
2B - F (subtractive)
3B + 0.25 * F

Order mirrors the ordering table at per-primitive granularity. Every blended primitive is keyed by its centroid depth and the whole list blends far to near regardless of draw boundaries; equal keys draw later-submitted-first, as a bucket of the retail table does. Untextured primitives have no per-texel gate and blend every pixel.

Enhancement passes

Each is identity when disabled: the shader helper returns its input when the uniform enable is zero, so the disabled path is pixel-identical to the faithful render.

The screen-space overlay

A screen primitive is a textured quad or a flat quad carrying an ordering-table index. The pass reproduces the retail walk - farthest bucket first, later-submitted-first inside a bucket - and draws coalesced runs by blend class. Primitives are authored in the 320x240 display space every retail emitter clamps against, and the overlay stretches over the surface.

Its consumers are the things retail draws as 2D packets into the 3D table: battle streaks and trails, the field-to-battle transition styles, billboards. The corner projection is the GTE’s own, including its reciprocal and its saturating screen coordinates, so a corner behind the camera smears the way hardware does.

Backdrops draw first. A screen primitive whose four corners sit at the far plane is one retail links into the farthest bucket - the cast colour wash and the overworld sky band. Composited after the 3D pass, a blended primitive writes no depth, so a wash drawn there would erase every additive effect over the sky. Both hosts split those backdrops off the under list and draw them in the scene pass, after the clear and before the first 3D draw.

The battle sorts by each primitive's link. A battle has one ordering table, and the bodies, the after-image ghosts, the effect parts, the draw-kind-4 nodes and the backdrop shell all go through the same per-primitive leaves, which link each primitive at its corners' mean depth. Nothing on the GPU tests depth, so a monster and the additive ring around it sort by link, not by pixel: on Dohati's Chaos Breath the ring's packets sit in buckets nearer than every packet of the body, and the ring paints over the belly even where the belly stands in front of it. In PSX mode both hosts draw every battle mesh primitive at its corners' mean depth, as they do on the field; an effect part whose colour word carries the far-corner bit sorts at its farthest corner, as a field prop does (Inferno's tunnel wall stays behind its flames that way); the ground grid keeps its far bucket, and the screen primitives (trails, streaks, cast-arm packets) still composite over the 3D frame. Clean rendering keeps per-pixel depth: a mean pops as the camera turns, which the retail frame shows and the clean frame need not.

Landing a frame back in VRAM

The renderer only ever pushed the software page to the GPU. The capture path is the missing direction: it quantises a readback to 15-bit colour and writes it into a rect of the CPU-side page, so the result is visible to every reader of that page. The field-to-battle transition needs it - the tile shatter and the curtain sample the field frame that was on screen when the encounter fired. The frame read back is the one the window presents, screen layers and enhancement passes included, less the transition’s own primitives.

Two retail nuances are stated rather than hidden: the transition’s depth-cue bank has no channel in the overlay, and retail subtracts from the display buffer each frame instead of clearing it, so its strips leave fading trails where the port’s leave black.

A cast's frames build on earlier ones

A retail battle frame's farthest bucket holds an opaque black rect, and a cast arm that arms its subtractive wash has that quad take the rect's place, so the frame's additive layers sum over the frames before it. That is why Ozma's fans read white on retail while a frame rasterised from the same packets on black is dark teal with thin red rays.

The native target is the one target that outlives its frame, so it reproduces this: while a cast's arms keep the frame, each frame loads an earlier one instead of clearing, and a capture seeds from the same one. Retail's earlier frame is the same display page two game frames back, eight vsyncs at the frame step a heavy arm runs at, so the renderer keeps a ring of eight frames; building on the last frame instead fills the buffer eight times too fast. The ring fills from the moment a cast module is resident, not from the first frame that keeps: an arm arms the wash a pass after the arm before it hands over, so its first kept frames read pages from before the arm. Started on copies of the last frame, Thunder Storm's second pass of arm 4 built on its first pass's white where retail's other page still held the dark frame before the arm. The play page does the same under PSX rasterisation (LegaiaPsxTarget in webgl-psx-target.js holds the same ring), and bloom stands the frames down on both hosts, since it reads the frame it adds to. The window's own target and the browser's canvas still clear, and there the additive arms draw dimmer than retail.

Frame profiler

LEGAIA_PROFILE=1 prints a rolling one-second timing breakdown from the native window: frame average and percentiles, draw counts, and the tick / pose / draw-list / encode / submit / present split. It is free when off - every entry point short-circuits on one cached flag. scripts/ci/frame-bench.py and frame-bench-web.mjs run it, and the browser's own counters, over a fixed scene set (frame benchmark).

Two things the benchmark drove: a rebuilt mesh writes over last frame's buffers, since a buffer dropped within two frames of its birth goes back to a pool that the next mesh of its exact size draws from; and the shadow stage draws only what each light reaches, since a draw wholly outside a lamp's frustum writes no depth into that lamp's layer.

See also

The blend tails and dither parity, the occlusion tunables, the transition emitter style by style, the battle HUD and menu chrome pipelines and the reference ports of retail’s draw-decision kernels are in docs/subsystems/renderer-port.md.

Reference Renderer Renderer: internals Shading Browser host Battle HUD Stage and camera Engine port