Sky and far scenery draw: light sets 2 and 3, dome colour, the st02 glow

Decoded from PDUWP.exe (our reading of the machine code; addresses as leads), the stage files and renders of our build at one spot on st02 (Highway). Class handles are the RTTI names.

The sky object (pdMapSky, vtable 0x14048ca48, draw 0x1401c87f0)

The battle stage setup (0x140204e60, at 0x1402053be..0x1402053da) hands the stage ALR to the sky object twice: as a global (0x14052dda8) with sub-model index 1 (0x14052dda0), and as the object’s own model (+0x40) with sub-model index 2 (+0x48). The object’s draw method then draws both outside the normal stage walk, each under its own light set:

Step What Light set Placement
1 stage model 1 (when the global is set) 3 (0x1401c8845) identity rotation, moved to the object’s position (+0x4C..+0x54; zeroed by the init 0x1401c87c0, so the origin)
2 stage model 2 (skipped when render flag bit 0x8000 of 0x14052fff4 is set) 2 (0x1401c8b1b) identity rotation, moved to the camera position (eye = −Rᵀ·t of the view matrix at 0x1405a5ca0, all three axes)
3 back to light set 0 (0x1401c8b79)

What that does to the clouds (SBTSCLOUD3)

The cloud colour is t0 · min(sat(N·L · light) + sat(N·P · point + sky), 1) with the selected set’s constants. The cloud dome’s normals point inward and down (mean N.y −0.88), so set 0’s downward light gives N·L < 0 on most of it and the clouds came out as t0 · sky(set 0). With set 2 the light travels up, N·L is 0.6..1 over the whole layer, and the sky colour is set 2’s:

Stage set 0 result (ours today) set 2 result (the game)
st02 t0 × (0.34, 0.40, 0.42) t0 × min(N·L·(0.18, 0.38, 0.16) + (0.71, 0.73, 0.71), 1) ≈ t0 × (0.85, 1.0, 0.83)
st03 t0 × (0.49, 0.51, 0.53) t0 × min(N·L·(0.43, 0.22, 0.59) + (0.33, 0.41, 0.78), 1) ≈ t0 × (0.68, 0.59, 1.0)

(skycol 11-15, corrected) Point light 0 of set 2 is not black: st02 has colour (113, 94, 0) and range 9e8, st03 (225, 255, 220) and range 1e8, and it saturates the point term over most of the dome (“Sky colour: set 2’s point light” below; the table above leaves it out). Without it st03’s clouds get 1.2–1.9 × brighter and bluer, st02’s about 2.5 × brighter and golden instead of grey-green. This is the “lit dome” the skyfix5 note could not find for the brighter xemu capture of st03: the constants at draw time are set 2’s (H for the set selection in the PC code; M that the Xbox does the same, by the footage of st02 and st03 and the identical .dat scripts; the Xbox draw code is not traced).

The dome’s vertex colour (SC, vertex format 0x09)

SC multiplies its texture by the vertex colour (the vertex shader passes COLOR0 through). Format 0x09 is 20 bytes: position 3 × f32, UV 2 × s16, colour 4 × u8 at +16 (grey on every dome checked, alpha 255). pdconv does not write it, so Godot draws white. Values:

Stage, dome Material Vertex colour
st02 outer dome (golden texture, 290 vertices, radius 12 400) flags 0x10001 (no blend: opaque), blend word 0x1100 unused grey 95..185 of 255: 136 on 139 vertices, 185 on the horizon ring (36), 95 / 110 in one sector (73); mean 0.52
st02 inner dome (black texture with a few bright texels, 339 vertices, radius 6 300) flags 0x10011 (blend on), one / one 255
st22 dome flags 0x10001 (opaque) 86..255, mean 0.55
st07 domes 0x10011, one / one 255

The outer st02 dome is therefore about half as bright as its texture (texture mean (0.69, 0.54, 0.36) → about (0.36, 0.28, 0.19)), and opaque (over the black clear colour our additive draw gives the same result, but the order must be dome first).

Why our st02 sky clips (measured, our build bf52b1e, 1280 × 720, Xbox look)

Camera at the st02 spawn, looking up 25°, four headings; sky = top 40 % of the frame; luma = (0.3, 0.6, 0.1). The glow chain was also computed on the CPU from the frame without glow; it reproduces the rendered result within 0.014 mean on two headings (0.058 on the third), so the chain itself is drawn as decoded.

Step Decoded Ours Verdict
Dome before glow texture × vertex grey (≈ 0.53) texture × 1: dome-only sky mean (0.75, 0.60, 0.41), luma median 0.63 wrong: no vertex colour
Clouds before glow t0 × set 2 (≈ t0) t0 × set 0’s sky: cloud-only mean (0.14, 0.11, 0.05) wrong: light set
Sum before glow — mean (0.88, 0.72, 0.46), luma p5 / 50 / 95 = 0.58 / 0.75 / 0.87; 16 % of sky pixels already have a channel ≥ 0.98 too bright and too flat
Glow scale s script 0x2003: 0.71, eased from 0.5 0.710 (log) right
Bright pass keeps luma > 0.5 / 0.71 = 0.704 67 % of the sky passes (median luma 0.75 sits just over the threshold) follows from the input
Composite + blurred tile × 1.0, saturated sky mean (0.98, 0.95, 0.78), 90 % of sky pixels clipped in a channel; glow adds 0.16 averaged over the whole frame follows from the input
Colour space textures sampled raw, 8-bit targets, every pass saturates dome-only pixels equal the texture’s values (no gamma step), 8-bit, saturating right

The cause is the input, not the glow: a dome twice too bright puts most of the sky just above the bright-pass threshold, and the glow then adds the sky onto itself.

Model of the corrected sky (same frames: dome-only render × 0.53 + the cloud-only render under --light-set=2, then the decoded glow chain on the CPU; --light-set=2 made the cloud-only render 2.1–2.5 × brighter on two headings, 1.15 × on a third, not looked into):

Heading Today, with glow Model, PC (no fog), with glow Model with set 2’s fog on the clouds (× 0.55), with glow
+x sky mean (0.98, 0.95, 0.78), luma median 0.98, 90 % clipped (0.85, 0.75, 0.47), median 0.79, luma p5 0.37, 47 % clipped (0.58, 0.47, 0.28), median 0.49, none clipped, no glow
−x (0.84, 0.81, 0.65), median 0.97, 72 % (0.69, 0.62, 0.40), median 0.62, 36 % (0.51, 0.42, 0.26), median 0.44, none

The modelled sky has the footage’s look: dark brown cloud bodies against bright golden gaps, instead of a flat yellow-white. Sky patches of the Xbox frames in the comparison clip read (0.55, 0.44, 0.26) at 159 s (close to the fogged model) and (0.89, 0.75, 0.42) at 111 s (close to the unfogged model with glow), so the Xbox lies between the two models; how strongly its cloud pass is fogged is the open part (L: the fog register is read by the cloud combiner, the set 2 fog values are decoded, the Xbox render state at that draw is not traced). On the PC (no fog) the sky keeps bright bloomed cores where the cloud texture is brightest: that is the decoded PC result, less white and far more contrasty than today.

Not a cause: sRGB / linear handling, HDR, the glow scale, the tap tables.

Stage light values of st02 (script, set 0 / 2 / 3; vectors in script order)

Set Used for Light direction Light Sky Ground Fog
0 stage, objects (−0.907, −0.419, −0.021) (231, 195, 130) (86, 101, 108) (35, 35, 35) exp, density 0.00144, colour (33, 34, 27)
2 sky (−0.014, 0.995, 0.097) (45, 97, 40) (181, 187, 180) 0 exp, 0.00008, black
3 far scenery (−0.877, −0.453, −0.158) (135, 126, 100) (120, 120, 120) (130, 130, 130) exp, 0.00136, colour (13, 19, 18)

Glow: 0x2003(0.71, 0); shadow colour 0x2001: black. On the PC no pixel shader reads the fog, so the per-set fog matters only for the Xbox look: there the far city (2 000..4 000 units away) is fully in set 3’s dark fog colour, the near-black skyline of the Xbox footage, and the cloud layer takes set 2’s weak black fog (factor e^(−0.00008·d): 0.71 overhead at 4 350 units, 0.40 at the rim), SC domes none. Our Xbox look fogs model 1 with set 0’s values and colour.

The sand storm is on a clock that runs from boot

The storm intensity (“Stage ambient effects”) is computed in the vkSAND constant upload (0x1402342e9) from the float counter 0x14057f398. That counter has two writers only: device setup zeroes it (0x1402927ae) and the 30 Hz game tick 0x1401c7630 adds 1.0 (0x1401c77fc; wraps at 4 000 000). The tick runs in menus as well, and nothing resets the counter at a stage load. So the storm does not depend on the mission, an option or a random draw: it is a slow wave on the time since the game was started.

Implementation notes for the rebuild

  1. Converter: write COLOR_0 for vertex format 0x09 (u8 × 4 at +16, through a struct for the 20-byte vertex) and draw sc as texture × vertex colour. Expect on st02: dome-only sky mean about (0.39, 0.31, 0.21) instead of (0.75, 0.60, 0.41); st22’s dome 0.55 × today’s.
  2. Draw the sky model (model 2: sc, sbtscloud2/3) with light set 2 (light, direction, sky colour, point light 0), not set 0. Expect st02’s cloud-only render about 2.5 × brighter and golden; st03’s sky brighter and bluer (re-check the st03 capture numbers of skyfix5).
  3. Draw model 1 (far scenery) with light set 3; in the Xbox look fog it with set 3’s fog and fog the cloud layers with set 2’s fog (SC stays unfogged).
  4. Sky model follows the camera position (all three axes); model 1 stays at the origin.
  5. sc materials: blend only when flag bit 4 is set (st02’s outer dome and st22’s dome are opaque; draw them before the additive layers).
  6. Storm clock: one process-wide tick counter that starts with the game (30 per second, menus included), not a per-stage clock; the cloud scroll and capsule scroll use the same counter.
  7. Glow: no change to the chain. After 1 and 2, expect at the st02 spawn (looking up 25°, heading +x / −x): PC look sky mean about (0.85, 0.75, 0.47) / (0.69, 0.62, 0.40) with glow instead of (0.98, 0.95, 0.78) / (0.84, 0.81, 0.65), luma p5 0.37 instead of 0.68 (dark cloud bodies), bright-pass share of the sky 32 % / 26 % instead of 67 % / 53 %. Xbox look with the clouds in set 2’s fog: about (0.58, 0.47, 0.28) / (0.51, 0.42, 0.26) and almost no glow on the sky.

Built (skyglow 11-13): 1 (all 19 stages reconverted), 2, 3, 4 and 6 (PdClock, PdSky, PdData.model_light_set); 5 and 7 unchanged. The sky is drawn without point lights (p0 = 0), since set 2’s point light 0 is read as black here; st02’s light.json lists a coloured one, not reconciled (PLACEHOLDERS “Sky light set”). (skycol 11-15: reconciled, the light is real and the sky needs it; next section.) Measured at the st02 spawn, heading +x, PC look with glow: (0.82, 0.74, 0.49), luma p5 0.30, 51 % clipped, bright-pass share 58 %; −x (0.71, 0.64, 0.42).