library: render: scene: add background color
This commit is contained in:
parent
c2fd001430
commit
08063b5aa3
|
@ -21,6 +21,7 @@ pub struct Scene {
|
||||||
lights: LightAggregate,
|
lights: LightAggregate,
|
||||||
objects: Vec<Object>,
|
objects: Vec<Object>,
|
||||||
bvh: BVH,
|
bvh: BVH,
|
||||||
|
background: LinearColor,
|
||||||
aliasing_limit: u32,
|
aliasing_limit: u32,
|
||||||
reflection_limit: u32,
|
reflection_limit: u32,
|
||||||
diffraction_index: f32,
|
diffraction_index: f32,
|
||||||
|
@ -55,6 +56,7 @@ impl Scene {
|
||||||
/// UniformTexture::new(LinearColor::new(0.5, 0.5, 0.5)).into(),
|
/// UniformTexture::new(LinearColor::new(0.5, 0.5, 0.5)).into(),
|
||||||
/// ),
|
/// ),
|
||||||
/// ],
|
/// ],
|
||||||
|
/// LinearColor::black(), // Background color
|
||||||
/// 5, // aliasing limit
|
/// 5, // aliasing limit
|
||||||
/// 3, // reflection recursion limit
|
/// 3, // reflection recursion limit
|
||||||
/// 0.0, // diffraction index
|
/// 0.0, // diffraction index
|
||||||
|
@ -64,6 +66,7 @@ impl Scene {
|
||||||
camera: Camera,
|
camera: Camera,
|
||||||
lights: LightAggregate,
|
lights: LightAggregate,
|
||||||
mut objects: Vec<Object>,
|
mut objects: Vec<Object>,
|
||||||
|
background: LinearColor,
|
||||||
aliasing_limit: u32,
|
aliasing_limit: u32,
|
||||||
reflection_limit: u32,
|
reflection_limit: u32,
|
||||||
diffraction_index: f32,
|
diffraction_index: f32,
|
||||||
|
@ -75,6 +78,7 @@ impl Scene {
|
||||||
lights,
|
lights,
|
||||||
objects,
|
objects,
|
||||||
bvh,
|
bvh,
|
||||||
|
background,
|
||||||
aliasing_limit,
|
aliasing_limit,
|
||||||
reflection_limit,
|
reflection_limit,
|
||||||
diffraction_index,
|
diffraction_index,
|
||||||
|
@ -121,8 +125,9 @@ impl Scene {
|
||||||
let pixel = self.camera.film().pixel_at_ratio(x, y);
|
let pixel = self.camera.film().pixel_at_ratio(x, y);
|
||||||
let direction = Unit::new_normalize(pixel - self.camera.origin());
|
let direction = Unit::new_normalize(pixel - self.camera.origin());
|
||||||
let indices = RefractionInfo::with_index(self.diffraction_index);
|
let indices = RefractionInfo::with_index(self.diffraction_index);
|
||||||
self.cast_ray(Ray::new(pixel, direction))
|
self.cast_ray(Ray::new(pixel, direction)).map_or_else(
|
||||||
.map_or_else(LinearColor::black, |(t, obj)| {
|
|| self.background.clone(),
|
||||||
|
|(t, obj)| {
|
||||||
self.color_at(
|
self.color_at(
|
||||||
pixel + direction.as_ref() * t,
|
pixel + direction.as_ref() * t,
|
||||||
obj,
|
obj,
|
||||||
|
@ -130,7 +135,8 @@ impl Scene {
|
||||||
self.reflection_limit,
|
self.reflection_limit,
|
||||||
indices,
|
indices,
|
||||||
)
|
)
|
||||||
})
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get pixel color with anti-aliasing
|
/// Get pixel color with anti-aliasing
|
||||||
|
@ -297,6 +303,8 @@ struct SerializedScene {
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
objects: Vec<Object>,
|
objects: Vec<Object>,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
|
background: LinearColor,
|
||||||
|
#[serde(default)]
|
||||||
aliasing_limit: u32,
|
aliasing_limit: u32,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
reflection_limit: u32,
|
reflection_limit: u32,
|
||||||
|
@ -310,6 +318,7 @@ impl From<SerializedScene> for Scene {
|
||||||
scene.camera,
|
scene.camera,
|
||||||
scene.lights,
|
scene.lights,
|
||||||
scene.objects,
|
scene.objects,
|
||||||
|
scene.background,
|
||||||
scene.aliasing_limit,
|
scene.aliasing_limit,
|
||||||
scene.reflection_limit,
|
scene.reflection_limit,
|
||||||
scene.starting_diffraction,
|
scene.starting_diffraction,
|
||||||
|
@ -347,10 +356,11 @@ mod test {
|
||||||
let _scene = Scene::new(
|
let _scene = Scene::new(
|
||||||
Camera::default(),
|
Camera::default(),
|
||||||
LightAggregate::empty(),
|
LightAggregate::empty(),
|
||||||
Vec::new(), // Objects list
|
Vec::new(), // Objects list
|
||||||
5, // aliasing limit
|
LinearColor::black(), // Background color
|
||||||
3, // reflection recursion limit
|
5, // aliasing limit
|
||||||
0.0, // diffraction index
|
3, // reflection recursion limit
|
||||||
|
0.0, // diffraction index
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue