aboutsummaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-12-01 09:19:19 +0300
committerValentin Popov <valentin@popov.link>2026-12-01 09:19:19 +0300
commit4e3681dfa367c97349df74e7b94970492d4cae2b (patch)
tree62b70908ce738ac89cb33d1095aff40d0b0a6e89 /apps
parent0b8829022bdf49a9b9a4ecf974c10f764aa31b9f (diff)
downloadfparkan-4e3681dfa367c97349df74e7b94970492d4cae2b.tar.xz
fparkan-4e3681dfa367c97349df74e7b94970492d4cae2b.zip
fix(render): use visible building stages for sun glare
Diffstat (limited to 'apps')
-rw-r--r--apps/fparkan-game/src/main.rs3
-rw-r--r--apps/fparkan-game/src/sun_visibility.rs48
2 files changed, 46 insertions, 5 deletions
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<usize, ActiveMaterialState>,
pub hidden: &'a HashSet<usize>,
+ pub inactive_building_ranges: &'a HashSet<usize>,
pub boarded_hero: Option<usize>,
}
@@ -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));
+ }
}