optimize light selection
This commit is contained in:
parent
1a30887a7d
commit
7a58ba9733
6 changed files with 62 additions and 13 deletions
src/scene
|
@ -969,12 +969,13 @@ impl EmptyVolume {
|
|||
quads
|
||||
}
|
||||
|
||||
pub fn select_lights(&self, lights: LightsIter, light_number: u32) -> Vec<u32> {
|
||||
let center = self.position + Vector3{x: self.size_x / 2, y: self.size_y / 2, z: self.size_z / 2};
|
||||
pub fn select_lights(&self, lights: LightsIter, light_number: u32, min_light_weight: f32) -> Vec<u32> {
|
||||
let mut weighted_indices = vec![];
|
||||
for light in lights {
|
||||
let weight = light.borrow().weighted_distance(center);
|
||||
weighted_indices.push((weight, light.borrow().get_memory_start()));
|
||||
for light in lights {
|
||||
let weight = light.borrow().weighted_distance(self.position + self.tree_offset * self.tree_size, Vector3{x: self.size_x, y: self.size_y, z: self.size_z});
|
||||
if weight >= min_light_weight {
|
||||
weighted_indices.push((weight, light.borrow().get_memory_start()));
|
||||
}
|
||||
}
|
||||
weighted_indices.sort_by(|a, b| a.0.partial_cmp(&b.0).unwrap());
|
||||
|
||||
|
@ -1213,7 +1214,7 @@ impl Memorizable for EmptyVolume {
|
|||
v[mem_index] = self.size_z as u32;
|
||||
mem_index += 1;
|
||||
//Todo: insert lights
|
||||
let selected_lights = self.select_lights(scene.get_light_iter(), data.num_lights_per_volume);
|
||||
let selected_lights = self.select_lights(scene.get_light_iter(), data.num_lights_per_volume, data.min_light_weight);
|
||||
for light in selected_lights {
|
||||
v[mem_index] = light;
|
||||
mem_index += 1;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue