Update LightArray to work with current code.
It's useful for checking correctness.
This commit is contained in:
parent
011405e131
commit
927a86c1fc
|
@ -1,40 +1,45 @@
|
||||||
|
use mem_arena::MemArena;
|
||||||
|
|
||||||
use bbox::BBox;
|
use bbox::BBox;
|
||||||
use math::{Vector, Point, Normal};
|
use math::{Vector, Point, Normal};
|
||||||
use shading::surface_closure::SurfaceClosure;
|
use shading::surface_closure::SurfaceClosure;
|
||||||
|
|
||||||
use super::LightAccel;
|
use super::LightAccel;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Copy, Clone)]
|
||||||
pub struct LightArray {
|
pub struct LightArray<'a> {
|
||||||
indices: Vec<usize>,
|
indices: &'a [usize],
|
||||||
aprx_energy: f32,
|
aprx_energy: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LightArray {
|
impl<'a> LightArray<'a> {
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub fn new<'a, T, F>(things: &mut [T], q: F) -> LightArray
|
pub fn from_objects<'b, T, F>(
|
||||||
|
arena: &'a MemArena,
|
||||||
|
objects: &mut [T],
|
||||||
|
info_getter: F,
|
||||||
|
) -> LightArray<'a>
|
||||||
where
|
where
|
||||||
F: 'a + Fn(&T) -> Option<(&'a [BBox], f32)>,
|
F: 'b + Fn(&T) -> (&'b [BBox], f32),
|
||||||
{
|
{
|
||||||
let mut indices = Vec::new();
|
let mut indices = Vec::new();
|
||||||
let mut aprx_energy = 0.0;
|
let mut aprx_energy = 0.0;
|
||||||
for (i, thing) in things.iter().enumerate() {
|
for (i, thing) in objects.iter().enumerate() {
|
||||||
if let Some((_, power)) = q(thing) {
|
let (_, power) = info_getter(thing);
|
||||||
if power > 0.0 {
|
if power > 0.0 {
|
||||||
indices.push(i);
|
indices.push(i);
|
||||||
aprx_energy += power;
|
aprx_energy += power;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LightArray {
|
LightArray {
|
||||||
indices: indices,
|
indices: arena.copy_slice(&indices),
|
||||||
aprx_energy: aprx_energy,
|
aprx_energy: aprx_energy,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LightAccel for LightArray {
|
impl<'a> LightAccel for LightArray<'a> {
|
||||||
fn select(
|
fn select(
|
||||||
&self,
|
&self,
|
||||||
inc: Vector,
|
inc: Vector,
|
||||||
|
|
|
@ -11,6 +11,7 @@ use shading::surface_closure::SurfaceClosure;
|
||||||
|
|
||||||
pub use self::bvh::{BVH, BVHNode};
|
pub use self::bvh::{BVH, BVHNode};
|
||||||
pub use self::light_tree::LightTree;
|
pub use self::light_tree::LightTree;
|
||||||
|
pub use self::light_array::LightArray;
|
||||||
|
|
||||||
// Track BVH traversal time
|
// Track BVH traversal time
|
||||||
thread_local! {
|
thread_local! {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user