From 470949acad7b624ff3dd9d566339a0aa8fbf2852 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Thu, 3 Dec 2026 14:30:45 +0400 Subject: feat(render): apply native robot shadow quality presets --- crates/fparkan-fx/src/shadow.rs | 95 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 91 insertions(+), 4 deletions(-) (limited to 'crates/fparkan-fx') diff --git a/crates/fparkan-fx/src/shadow.rs b/crates/fparkan-fx/src/shadow.rs index fb0e6ccc..cc400c53 100644 --- a/crates/fparkan-fx/src/shadow.rs +++ b/crates/fparkan-fx/src/shadow.rs @@ -111,6 +111,51 @@ impl Default for ShadowLodSettings { } } +/// Projected robot shadow settings selected by the GOG render presets. +#[derive(Clone, Copy, Debug, PartialEq)] +pub struct RobotShadowQuality { + /// Whether robot silhouettes enter the projected shadow pass. + pub enabled: bool, + /// Screen-size multiplier used to select the shadow LOD. + pub detail: f32, + /// Number of blur passes on a newly rasterized silhouette. + pub smooth_passes: u32, + refresh_mask: u32, +} + +impl RobotShadowQuality { + /// Resolves the values passed from `RENDER_QUALITY` to Terrain.dll. + pub const fn from_render_quality(quality: Option) -> Self { + match quality { + Some(0) => Self { + enabled: false, + detail: 1.0, + smooth_passes: 1, + refresh_mask: 1, + }, + // CShade expands the stored selector 2 to the two-bit mask 3. + Some(1) => Self { + enabled: true, + detail: 0.5, + smooth_passes: 0, + refresh_mask: 3, + }, + _ => Self { + enabled: true, + detail: 1.0, + smooth_passes: 1, + refresh_mask: 1, + }, + } + } +} + +impl Default for RobotShadowQuality { + fn default() -> Self { + Self::from_render_quality(None) + } +} + #[derive(Clone, Copy, Debug, PartialEq)] struct ShadowCacheSlot { caster: u32, @@ -131,6 +176,7 @@ pub struct ShadowPageCache { atlas_rgba8: Vec, frame_index: Option, rng: NativeRng, + robot_quality: RobotShadowQuality, /// Slots claimed while building the current frame. A slot already used /// by an earlier candidate must not be evicted again by a later one. frame_used: [bool; SHADOW_PAGE_COUNT], @@ -144,12 +190,26 @@ impl Default for ShadowPageCache { frame_index: None, // shortcut: native process-wide allocation order is not connected in preview. rng: NativeRng::new(1), + robot_quality: RobotShadowQuality::default(), frame_used: [false; SHADOW_PAGE_COUNT], } } } impl ShadowPageCache { + /// Creates an empty page cache with the selected robot shadow cadence. + pub fn with_robot_quality(robot_quality: RobotShadowQuality) -> Self { + Self { + robot_quality, + ..Self::default() + } + } + + /// The robot shadow settings attached to this mission's page cache. + pub fn robot_quality(&self) -> RobotShadowQuality { + self.robot_quality + } + /// Builds a frame while preserving page ownership across calls. /// Use the same index to redraw the current frame after a resize. pub fn build( @@ -269,10 +329,11 @@ impl ShadowPageCache { fn reused_projection(&self, index: usize, native_kind: u32) -> Option { let slot = self.slots[index]?; - // RobShdwRefreshMask=1: retain the assigned phase until the page is evicted. - (native_kind == 4 && u64::from(slot.refresh_phase & 1) != (self.frame_index? & 1)) - .then_some(slot.projection) - .flatten() + let mask = self.robot_quality.refresh_mask; + (native_kind == 4 + && u64::from(slot.refresh_phase & mask) != (self.frame_index? & u64::from(mask))) + .then_some(slot.projection) + .flatten() } } @@ -1716,6 +1777,32 @@ mod tests { } } + #[test] + fn medium_robot_shadows_keep_three_frames_between_refreshes() { + let quality = RobotShadowQuality::from_render_quality(Some(1)); + assert_eq!(quality.detail, 0.5); + assert_eq!(quality.smooth_passes, 0); + assert!(!RobotShadowQuality::from_render_quality(Some(0)).enabled); + let mut cache = ShadowPageCache::with_robot_quality(quality); + let slot = cache.assign(7, 1).unwrap(); + let projection = make_projection( + &caster(7, 2.0, 4, Vec::new()), + LightContribution { + direction: [0.0, 0.0, 1.0], + strength: 1.0, + }, + 1.0, + ) + .unwrap(); + let entry = cache.slots[slot].as_mut().unwrap(); + entry.refresh_phase = 17356; + entry.projection = Some(projection); + for frame in 0..8 { + cache.frame_index = Some(frame); + assert_eq!(cache.reused_projection(slot, 4).is_some(), frame % 4 != 0); + } + } + #[test] fn robot_page_holds_shape_and_basis_between_refreshes_but_tracks_translation() { let mut robot = caster( -- cgit v1.2.3