Early light filter

This commit is contained in:
Joshua Barretto 2022-07-16 15:54:12 +01:00
parent cda6c031b8
commit 79ad06ab60
2 changed files with 13 additions and 9 deletions

View File

@ -6,7 +6,7 @@ use crate::{
mesh::{
greedy::{GreedyMesh, SpriteAtlasAllocator},
segment::generate_mesh_base_vol_sprite,
terrain::{generate_mesh, SUNLIGHT_INV},
terrain::{generate_mesh, SUNLIGHT, SUNLIGHT_INV},
},
render::{
pipelines::{self, ColLights},
@ -777,13 +777,18 @@ impl<V: RectRasterableVol> Terrain<V> {
.get(&chunk_pos)
.into_iter()
.flat_map(|c| c.blocks_of_interest.lights.iter())
.map(move |(lpos, level)| {
(
Vec3::<i32>::from(
chunk_pos * TerrainChunk::RECT_SIZE.map(|e| e as i32),
) + *lpos,
level,
)
.filter_map(move |(lpos, level)| {
if (*lpos - wpos_chunk).map(|e| e.abs()).reduce_min() < SUNLIGHT as i32 + 2
{
Some((
Vec3::<i32>::from(
chunk_pos * TerrainChunk::RECT_SIZE.map(|e| e as i32),
) + *lpos,
level,
))
} else {
None
}
})
})
.fold(

View File

@ -184,7 +184,6 @@ impl BlocksOfInterest {
// TODO: Come up with a better way to prune many light sources: grouping them
// into larger lights with k-means clustering, perhaps?
const MAX_MINOR_LIGHTS: usize = 64;
let minor_light_count = minor_lights.len();
lights.extend(
minor_lights
.choose_multiple(&mut rng, MAX_MINOR_LIGHTS)