pbrt_r3/core/lightdistrib/
create_light_sample_distribution.rs1use super::lightdistrib::*;
2use super::power::*;
3use super::spatial::*;
4use super::uniform::*;
5use crate::core::error::*;
6use crate::core::scene::*;
7
8use log::*;
9use std::sync::Arc;
10
11pub fn create_light_sample_distribution(
12 name: &str,
13 scene: &Scene,
14) -> Result<Arc<dyn LightDistribution>, PbrtError> {
15 if scene.lights.is_empty() {
16 let msg = format!(
17 "Light sample distribution type \"{}\" cannot create since no light.",
18 name
19 );
20 return Err(PbrtError::error(&msg));
21 }
22 match name {
23 "uniform" => {
24 if scene.lights.len() != 1 {
25 return create_light_sample_distribution("spatial", scene);
26 } else {
27 return Ok(Arc::new(UniformLightDistribution::new(scene)));
28 }
29 }
30 "power" => {
31 return Ok(Arc::new(PowerLightDistribution::new(scene)));
32 }
33 "spatial" => {
34 let max_voxels = 64;
35 return Ok(Arc::new(SpatialLightDistribution::new(scene, max_voxels)));
36 }
37 s => {
38 warn!(
39 "Light sample distribution type \"{}\" unknown. Using \"spatial\".",
40 s
41 );
42 return create_light_sample_distribution("spatial", scene);
43 }
44 }
45}