From 4e3681dfa367c97349df74e7b94970492d4cae2b Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Tue, 1 Dec 2026 10:19:19 +0400 Subject: fix(render): use visible building stages for sun glare --- apps/fparkan-game/src/main.rs | 3 ++- apps/fparkan-game/src/sun_visibility.rs | 48 ++++++++++++++++++++++++++++++--- 2 files changed, 46 insertions(+), 5 deletions(-) (limited to 'apps/fparkan-game/src') diff --git a/apps/fparkan-game/src/main.rs b/apps/fparkan-game/src/main.rs index 0c5facec..b0afe9be 100644 --- a/apps/fparkan-game/src/main.rs +++ b/apps/fparkan-game/src/main.rs @@ -8566,7 +8566,7 @@ fn static_preview_mesh_and_materials( }); } if root_sun_eligible { - sun_occlusion_range_indices.extend(range_start..range_start + base_range_count); + sun_occlusion_range_indices.extend(range_start..mesh.draw_ranges.len()); } mesh_components += 1; } @@ -11909,6 +11909,7 @@ impl StaticVulkanApp { materials: &self.materials, active: &frame.material_update.active_materials, hidden: &self.removed_mission_roots, + inactive_building_ranges: &inactive_building_ranges, boarded_hero: self.boarded_hero_index, }, )?; diff --git a/apps/fparkan-game/src/sun_visibility.rs b/apps/fparkan-game/src/sun_visibility.rs index b66094f4..8df3e75e 100644 --- a/apps/fparkan-game/src/sun_visibility.rs +++ b/apps/fparkan-game/src/sun_visibility.rs @@ -9,6 +9,7 @@ pub(super) struct SunOcclusionMaterials<'a> { pub materials: &'a [VulkanStaticMaterial], pub active: &'a HashMap, pub hidden: &'a HashSet, + pub inactive_building_ranges: &'a HashSet, pub boarded_hero: Option, } @@ -87,10 +88,12 @@ fn world_mesh_sun_occluded( continue; }; let material = world.as_ref().and_then(|world| { - if range.owner_scope.checked_sub(1).is_some_and(|owner| { - world.hidden.contains(&(owner as usize)) - || world.boarded_hero == Some(owner as usize) - }) { + if world.inactive_building_ranges.contains(&range_index) + || range.owner_scope.checked_sub(1).is_some_and(|owner| { + world.hidden.contains(&(owner as usize)) + || world.boarded_hero == Some(owner as usize) + }) + { return None; } let active = world.active.get(&range_index); @@ -267,6 +270,7 @@ mod tests { materials: &materials, active: &HashMap::new(), hidden, + inactive_building_ranges: &HashSet::new(), boarded_hero: None, }), ) @@ -277,4 +281,40 @@ mod tests { assert!(!blocked(0.75, &hidden)); assert!(!blocked(0.25, &removed)); } + + #[test] + fn only_the_visible_building_stage_blocks_the_sun() { + let mut mesh = VulkanStaticMesh::smoke_triangle(); + mesh.vertices = [0.0, 2.0] + .into_iter() + .flat_map(|y| [[5.0, y, 0.0], [5.0, y + 1.0, 0.0], [5.0, y, 1.0]]) + .map(|position| environment_vertex(position, [1.0; 3], [0.0; 2])) + .collect(); + mesh.indices = vec![0, 1, 2, 3, 4, 5]; + let mut damaged = mesh.draw_ranges[0]; + damaged.first_index = 3; + mesh.draw_ranges.push(damaged); + let mut materials = Vec::new(); + crate::append_shadow_material(&mut materials).unwrap(); + let blocked = |y, inactive| { + world_mesh_sun_occluded( + &mesh, + &[0, 1], + [0.0, y, 0.1], + [10.0, 0.0, 0.0], + Some(SunOcclusionMaterials { + materials: &materials, + active: &HashMap::new(), + hidden: &HashSet::new(), + inactive_building_ranges: &HashSet::from([inactive]), + boarded_hero: None, + }), + ) + }; + + assert!(blocked(0.25, 1)); + assert!(!blocked(0.25, 0)); + assert!(!blocked(2.25, 1)); + assert!(blocked(2.25, 0)); + } } -- cgit v1.2.3