Effect lights on characters (light02 → light pool → character point light)
Leads are exe addresses (PDUWP.exe 1.3.25854.2); the math below is a description, not code.
- The light02 element update (0x14010c990) writes one record into the engine light pool each tick (pool base 0x1405a6a40, 0x70 bytes per record, effect records from index 0x80). The record holds the colour as bytes / 255 (+0x00..+0x08), the world position (+0x30..+0x38), the range (+0x64) and the kind (+0x68, 2 = point).
- Once per player, the scan at 0x1402998f0 (called from 0x140299be0) walks the pool for point records that pass the record’s mask (+0x6c) and have a positive range. It scores each one as range divided by the squared distance to the player in game units. The best score starts at -1.0 (0x1402f82e0), and the two highest are kept in per-player slots.
- Before a character is drawn, 0x140199e70
points the character shader’s point-light
constants cP0/cP1 at those two records. The
shader adds colour × range × max(dot(P − p, n) /
|P − p|³, 0) for each light. Our character
shader already had this term for cP0
(
p0_col,p0_pos). - The stage is drawn with light set 0. Its point light 0 is the most recently allocated effect light while that record is live (bofcmp 11-13, section “The straight fire shot, the rebuild against the game”; the earlier line here said the stage never receives effect lights, which was wrong).
- Record life (bof2): each tick in its window the element rewrites its record and sets the record’s life count to int(end + 1) ticks and its fade count to 0 (0x14010cdc2). Past the window’s end it frees the record at once (0x14010cee4); before the start it writes nothing. Once per tick the pool update (0x14019a240) walks the effect records: with a fade count it multiplies the colour (not the range) by 0.625 (0x1402f7d4c) and counts down; else with a life count it counts down and, reaching 0, starts a fade count of 15; with neither it frees the record. So a light whose effect is destroyed inside its window (the forming effect replaced at the release, the flight effect at the hit) keeps lighting for int(end + 1) ticks at full colour, then 15 fading ticks.
- The scan skips records whose mask (+0x6c) shares a bit with the caller’s mask (1 in battle); effect records are allocated with mask 0, the channels’ own records below with mask 1.
- Channels (0x140299be0, per player two 16-byte channels at 0x140596670 + 0x40·player, each with its own pool record 0x60 + 2·player + i; reset off at 0x140199a96): with fewer than two lights offered, the outputs are the offered records themselves. With two, a channel whose light is no longer offered and that is on or fading in starts fading out; each offered light no channel follows takes the first channel that is off and starts fading in. Per tick a fading-in channel moves its colour and range by (target − now) / n and a fading-out one by −now / n, n counting down from the fade length (then on / off); an on channel follows only its light’s position (its colour and range stay where the fade-in ended). The outputs are the two channel records, in channel order.
- Fade length and binding: the battle scene setup (0x140204a0b) calls 0x140199ce0 with 0, which clears bit 0x10 of 0x140530034; with it clear, 0x140199db0 runs one channel update with fade length 3 and mask 1, and the binder 0x140199e70 points only cP0 at output 0 (a fixed pool record at 0x1405a8720 when there is none); cP1 is not fed effect lights in battle. (With the bit set: two channel sets, fade length 9, masks 5 and 3, cP0 and cP1.)
- Ours:
PdEffect.live_lights/PdEffect.pool_step/PdEffect.best_lights,PdCharacter._take_effect_light/_step_light_channels.