aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-render
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-11-01 07:26:46 +0300
committerValentin Popov <valentin@popov.link>2026-11-01 07:26:46 +0300
commit651f5e10a7e5fbaa65a9acffd76d033925291e8e (patch)
tree95bac3c256906f24f4f454d858343ff0ba59b827 /crates/fparkan-render
parent0f8b14abbf73a43402644c9acd0750bf25a79e98 (diff)
downloadfparkan-651f5e10a7e5fbaa65a9acffd76d033925291e8e.tar.xz
fparkan-651f5e10a7e5fbaa65a9acffd76d033925291e8e.zip
fix(render): match native reflection target sizes
Diffstat (limited to 'crates/fparkan-render')
-rw-r--r--crates/fparkan-render/src/water.rs29
1 files changed, 29 insertions, 0 deletions
diff --git a/crates/fparkan-render/src/water.rs b/crates/fparkan-render/src/water.rs
index 4f161cc..58a2817 100644
--- a/crates/fparkan-render/src/water.rs
+++ b/crates/fparkan-render/src/water.rs
@@ -7,6 +7,17 @@ pub const EMBM_BUMP_TILE: f32 = 100.0;
/// Native diagonal bump matrix, without luminance modulation.
pub const EMBM_COEFFICIENTS: [f32; 2] = [0.01, 0.01];
+/// Square reflection size chosen by Terrain.dll RVA 0x27FC7 from renderer dimensions.
+#[must_use]
+pub fn legacy_embm_reflection_size(extent: [u32; 2]) -> u32 {
+ let limit = extent[0].min(extent[1]).min(1024);
+ let mut side = 2;
+ while side * 2 <= limit {
+ side *= 2;
+ }
+ side
+}
+
/// Generates the signed bytes written by Terrain.dll RVA 0x2BF50 with CW 0x007F.
#[must_use]
pub fn legacy_embm_bump_map() -> Vec<[i8; 2]> {
@@ -117,6 +128,24 @@ mod tests {
use super::*;
#[test]
+ fn reflection_size_matches_native_renderer_dimension_vectors() {
+ for (extent, expected) in [
+ ([1280, 1024], 1024),
+ ([1280, 720], 512),
+ ([800, 600], 512),
+ ([640, 480], 256),
+ ([1920, 1080], 1024),
+ ([2048, 2048], 1024),
+ ([4, 7], 4),
+ ([3, 300], 2),
+ ([1, 1], 2),
+ ([700, 700], 512),
+ ] {
+ assert_eq!(legacy_embm_reflection_size(extent), expected, "{extent:?}");
+ }
+ }
+
+ #[test]
fn shifted_camera_maps_native_water_corners_and_retains_perspective_depth() {
let projection = crate::LegacyD3d7Projection {
viewport: [0, 0, 1280, 1024],