Skip to content

armgit / gecko

Public Imported from GitHub
0

A GameCube/Wii emulator and debugger written in Rust.

map 24-bit Z by 2^24 not 2^24-1 so far plane doesnt overflow depth copy

Layle08b53d54c5fd
diff --git a/crates/gecko/src/flipper/gx/bp.rs b/crates/gecko/src/flipper/gx/bp.rs
index 4fd6312..207e87c 100644
--- a/crates/gecko/src/flipper/gx/bp.rs
+++ b/crates/gecko/src/flipper/gx/bp.rs
@@ -474,7 +474,7 @@ impl GraphicsProcessor {
let g = clear_gb.green() as f32 / 255.0;
let b = clear_gb.blue() as f32 / 255.0;
- let clear_z = PeClearZ::from_raw(self.bp_regs[BP_PE_COPY_CLEAR_Z]).z() as f32 / 16777215.0;
+ let clear_z = PeClearZ::from_raw(self.bp_regs[BP_PE_COPY_CLEAR_Z]).z() as f32 / DEPTH_24_BIT_RANGE;
tracing::debug!(
src_x,
diff --git a/crates/gecko/src/flipper/gx/constants.rs b/crates/gecko/src/flipper/gx/constants.rs
index 66909b4..a5773cb 100644
--- a/crates/gecko/src/flipper/gx/constants.rs
+++ b/crates/gecko/src/flipper/gx/constants.rs
@@ -195,3 +195,5 @@ pub const EFB_HEIGHT: u32 = 528;
// Depth max for 24-bit Z
pub const DEPTH_24_BIT_MAX: f32 = 16777215.0; // (1 << 24) - 1
+pub const DEPTH_24_BIT_RANGE: f32 = 16777216.0; // 1 << 24
+pub const MAX_EFB_DEPTH: f32 = DEPTH_24_BIT_MAX / DEPTH_24_BIT_RANGE;
diff --git a/crates/gecko/src/flipper/gx/xf.rs b/crates/gecko/src/flipper/gx/xf.rs
index b3783b6..ff5840d 100644
--- a/crates/gecko/src/flipper/gx/xf.rs
+++ b/crates/gecko/src/flipper/gx/xf.rs
@@ -45,8 +45,8 @@ impl GraphicsProcessor {
let x = x - self.cur_scissor_offset_x as f32;
let y = y - self.cur_scissor_offset_y as f32;
- let far = (offset_z / DEPTH_24_BIT_MAX).clamp(0.0, 1.0);
- let near = (far - scale_z / DEPTH_24_BIT_MAX).clamp(0.0, 1.0);
+ let far = (offset_z / DEPTH_24_BIT_RANGE).clamp(0.0, MAX_EFB_DEPTH);
+ let near = ((offset_z - scale_z) / DEPTH_24_BIT_RANGE).clamp(0.0, MAX_EFB_DEPTH);
self.cur_viewport = draw::Viewport {
x,