Actually use the background color from the scene file.

This commit is contained in:
Nathan Vegdahl 2016-07-16 13:54:41 -07:00
parent 8cd445813a
commit 5bc97f69b8
3 changed files with 10 additions and 8 deletions

View File

@ -13,6 +13,7 @@ use math::Matrix4x4;
use camera::Camera; use camera::Camera;
use renderer::Renderer; use renderer::Renderer;
use scene::Scene; use scene::Scene;
use color::{XYZ, rec709e_to_xyz};
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug)]
pub enum PsyParseError { pub enum PsyParseError {
@ -264,10 +265,9 @@ fn parse_camera(tree: &DataTree) -> Result<Camera, PsyParseError> {
fn parse_world(tree: &DataTree) -> Result<(f32, f32, f32), PsyParseError> { fn parse_world(tree: &DataTree) -> Result<XYZ, PsyParseError> {
if tree.is_internal() { if tree.is_internal() {
let mut found_background_color = false; let background_color;
let mut background_color = (0.0, 0.0, 0.0);
// Parse background shader // Parse background shader
let bgs = { let bgs = {
@ -296,8 +296,9 @@ fn parse_world(tree: &DataTree) -> Result<(f32, f32, f32), PsyParseError> {
ws_f32, ws_f32,
ws_f32))(contents.trim() ws_f32))(contents.trim()
.as_bytes()) { .as_bytes()) {
found_background_color = true; // TODO: proper color space management, not just assuming
background_color = color; // rec.709.
background_color = XYZ::from_tuple(rec709e_to_xyz(color));
} else { } else {
return Err(PsyParseError::UnknownError); return Err(PsyParseError::UnknownError);
} }

View File

@ -306,8 +306,8 @@ impl LightPath {
} }
} else { } else {
// Didn't hit anything, so background color // Didn't hit anything, so background color
let xyz = XYZ::new(0.0, 0.0, 0.0); self.color += scene.background_color.to_spectral_sample(self.wavelength) *
self.color += xyz.to_spectral_sample(self.wavelength); self.light_attenuation;
return false; return false;
} }
} }

View File

@ -1,11 +1,12 @@
use camera::Camera; use camera::Camera;
use assembly::Assembly; use assembly::Assembly;
use color::XYZ;
#[derive(Debug)] #[derive(Debug)]
pub struct Scene { pub struct Scene {
pub name: Option<String>, pub name: Option<String>,
pub background_color: (f32, f32, f32), pub background_color: XYZ,
pub camera: Camera, pub camera: Camera,
pub root: Assembly, pub root: Assembly,
} }