diff --git a/src/parse/psy.rs b/src/parse/psy.rs index 1b3b529..564711e 100644 --- a/src/parse/psy.rs +++ b/src/parse/psy.rs @@ -13,6 +13,7 @@ use math::Matrix4x4; use camera::Camera; use renderer::Renderer; use scene::Scene; +use color::{XYZ, rec709e_to_xyz}; #[derive(Copy, Clone, Debug)] pub enum PsyParseError { @@ -264,10 +265,9 @@ fn parse_camera(tree: &DataTree) -> Result { -fn parse_world(tree: &DataTree) -> Result<(f32, f32, f32), PsyParseError> { +fn parse_world(tree: &DataTree) -> Result { if tree.is_internal() { - let mut found_background_color = false; - let mut background_color = (0.0, 0.0, 0.0); + let background_color; // Parse background shader let bgs = { @@ -296,8 +296,9 @@ fn parse_world(tree: &DataTree) -> Result<(f32, f32, f32), PsyParseError> { ws_f32, ws_f32))(contents.trim() .as_bytes()) { - found_background_color = true; - background_color = color; + // TODO: proper color space management, not just assuming + // rec.709. + background_color = XYZ::from_tuple(rec709e_to_xyz(color)); } else { return Err(PsyParseError::UnknownError); } diff --git a/src/renderer.rs b/src/renderer.rs index 61a0366..302e30f 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -306,8 +306,8 @@ impl LightPath { } } else { // Didn't hit anything, so background color - let xyz = XYZ::new(0.0, 0.0, 0.0); - self.color += xyz.to_spectral_sample(self.wavelength); + self.color += scene.background_color.to_spectral_sample(self.wavelength) * + self.light_attenuation; return false; } } diff --git a/src/scene.rs b/src/scene.rs index ba43ef1..4968fba 100644 --- a/src/scene.rs +++ b/src/scene.rs @@ -1,11 +1,12 @@ use camera::Camera; use assembly::Assembly; +use color::XYZ; #[derive(Debug)] pub struct Scene { pub name: Option, - pub background_color: (f32, f32, f32), + pub background_color: XYZ, pub camera: Camera, pub root: Assembly, }