aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-fx/src
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-12-03 13:30:45 +0300
committerValentin Popov <valentin@popov.link>2026-12-03 13:30:45 +0300
commit470949acad7b624ff3dd9d566339a0aa8fbf2852 (patch)
treea4f8ce74477660e09dd2a9bc59ca972e332fa7f4 /crates/fparkan-fx/src
parente8e717a222ddb116eac019a45d243263b2361ef4 (diff)
downloadfparkan-470949acad7b624ff3dd9d566339a0aa8fbf2852.tar.xz
fparkan-470949acad7b624ff3dd9d566339a0aa8fbf2852.zip
feat(render): apply native robot shadow quality presets
Diffstat (limited to 'crates/fparkan-fx/src')
-rw-r--r--crates/fparkan-fx/src/shadow.rs95
1 files changed, 91 insertions, 4 deletions
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<i32>) -> 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<u8>,
frame_index: Option<u64>,
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<ShadowProjection> {
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()
}
}
@@ -1717,6 +1778,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(
7,