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:
@@ -245,11 +245,13 @@ fn load_source(dir: &std::path::Path, level: usize) -> Result<(LevelFiles, [f32;
|
||||
let core_index = std::fs::read(level_dir.join("core_index.bin")).context("core_index.bin")?;
|
||||
let gs_ram = std::fs::read(level_dir.join("gs_ram.bin")).context("gs_ram.bin")?;
|
||||
let overlay = std::fs::read(level_dir.join("overlay.bin")).ok();
|
||||
let gameplay = std::fs::read(level_dir.join("gameplay.bin")).ok();
|
||||
let src = LevelSource {
|
||||
core_data: &core_data,
|
||||
core_index: &core_index,
|
||||
gs_ram: &gs_ram,
|
||||
overlay: overlay.as_deref(),
|
||||
gameplay: gameplay.as_deref(),
|
||||
};
|
||||
let (centre, _radius) = level_bounds(&src)?;
|
||||
Ok((
|
||||
@@ -258,6 +260,7 @@ fn load_source(dir: &std::path::Path, level: usize) -> Result<(LevelFiles, [f32;
|
||||
core_index,
|
||||
gs_ram,
|
||||
overlay,
|
||||
gameplay,
|
||||
},
|
||||
centre,
|
||||
))
|
||||
@@ -269,6 +272,7 @@ struct LevelFiles {
|
||||
core_index: Vec<u8>,
|
||||
gs_ram: Vec<u8>,
|
||||
overlay: Option<Vec<u8>>,
|
||||
gameplay: Option<Vec<u8>>,
|
||||
}
|
||||
|
||||
impl LevelFiles {
|
||||
@@ -278,6 +282,7 @@ impl LevelFiles {
|
||||
core_index: &self.core_index,
|
||||
gs_ram: &self.gs_ram,
|
||||
overlay: self.overlay.as_deref(),
|
||||
gameplay: self.gameplay.as_deref(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -334,6 +339,15 @@ fn report(g: &LevelGeometry) {
|
||||
for (m, n) in modes {
|
||||
eprintln!(" {m}: {n} patches");
|
||||
}
|
||||
// Say so when the level is not lit. Falling back silently to the tfrag's
|
||||
// stored colours produces a plausible but wrong picture.
|
||||
if s.lit_vertices < s.vertices {
|
||||
eprintln!(
|
||||
" lighting: {} of {} vertices shaded by LightTfrags; the rest fall back to the \
|
||||
tfrag's stored colours (no usable light bank)",
|
||||
s.lit_vertices, s.vertices
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn mode_name(p: &gc_engine::level::PatchBounds) -> &'static str {
|
||||
|
||||
Reference in New Issue
Block a user