Implement the PS2 float model and the LightTfrags pass
Two pieces, and the first is the reason the second can be trusted. ps2.rs is the EE's FPU on raw u32 bit patterns. It is not f32: there are no denormals (exponent 0 *is* zero), no NaN and no infinity (exponent 255 is an ordinary value, so MAX reads back in Rust as NaN -- a test asserts exactly that, because it is the sharpest available statement of why this module exists), every result truncates toward zero, the adder discards the small operand's bits more than one below the large one's LSB and returns the large operand unchanged across a 25-bit exponent gap, and rsqrt is sqrt-then-divide with truncation between the steps rather than one rounded operation. The lighting pass accumulates all of these across every vertex of every patch, so this is a visible difference rather than a rounding curiosity. tfrag_light.rs is the pass itself: PEXT5 base colour, the select word picking one light set or blending two by bits 8..15 / 256, blended directions re-normalised where unblended ones are not, and base + A.rgb*max(dA, dA*wA) + B.rgb*max(dB, dB*wB). Lighting indexes positions, not vertex-info entries, since a common entry and a LOD entry can share a position. TfragLight gains a `select` field for the u16 at +6. It was briefly reconstructed with an unsafe pointer cast over the struct, which is exactly the sort of thing that breaks silently the moment a field is reordered; it is now a plainly parsed field. The pass does not run yet. The light bank framing the reference uses -- a u32 offset at +0x04, an i32 count there -- gives offset 0xa0d and a count of 698810368 on RAC2 level 0, so RAC2's gameplay extent is not laid out that way. The renderer now counts the vertices it actually lit and prints it, because falling back silently to the stored colours produces a plausible but wrong picture: lighting: 0 of 80274 vertices shaded by LightTfrags; the rest fall back to the tfrag's stored colours (no usable light bank) That line is the current honest state, and the frame has not changed as a result. Where RAC2 keeps its light bank is the open question.
This commit is contained in:
+14
-6
@@ -42,12 +42,20 @@ early, while they are still cheap to retire.
|
||||
level 5 `0xcca30`); it is located by matching the whole 256-entry curve.
|
||||
Normals are negated as stored and get the same axis swap as positions.
|
||||
The pipeline now also writes `overlay.bin`.
|
||||
- [ ] **tfrag lighting pass.** The light bank from `gameplay` is framed and
|
||||
parsed; the per-vertex evaluation is not written yet. It is
|
||||
`base + A*max(dA, dA*wA) + B*max(dB, dB*wB)` and has to run in the PS2
|
||||
float model. Until then the renderer stays unlit by default;
|
||||
`GC_ENGINE_LIT=1` substitutes a host directional light for inspection,
|
||||
which is not the game's lighting.
|
||||
- [x] **The PS2 float model.** `gc-engine::ps2` is the EE's FPU on raw bits: no
|
||||
denormals, no NaN or infinity, truncation toward zero, the adder's
|
||||
operand alignment, and `rsqrt` as sqrt-then-divide. `MAX` reads back in
|
||||
Rust as NaN, which is the sharpest available statement of why this is
|
||||
not `f32`.
|
||||
- [x] **The `LightTfrags` pass** is written and unit-tested against the PS2
|
||||
model: PEXT5 base colour, `select` set blending, re-normalised blended
|
||||
directions, and `base + A*max(dA, dA*wA) + B*max(dB, dB*wB)`.
|
||||
- [ ] **The level light bank does not parse on RAC2.** The reference's framing
|
||||
(u32 offset at +0x04, i32 count there) yields offset `0xa0d` and a
|
||||
nonsense count on level 0. The renderer now reports how many vertices it
|
||||
actually lit, which is currently 0 of 80,274 -- so the frame falls back
|
||||
to the stored colours and says so rather than looking plausibly lit.
|
||||
Detail in `plan/level-assets.md`.
|
||||
- [ ] Then the GS register set and the guard-band clip test.
|
||||
|
||||
The disc being the exact build the reference projects pin is the single
|
||||
|
||||
Reference in New Issue
Block a user