Add checker texture to tutorial image to spruce things up.

This commit is contained in:
Bill Thiede 2019-10-26 15:21:45 -07:00
parent bda42922e4
commit 56743b5d77
2 changed files with 17 additions and 6 deletions

View File

@ -9,7 +9,9 @@ use crate::moving_sphere::MovingSphere;
use crate::renderer::Opt;
use crate::renderer::Scene;
use crate::sphere::Sphere;
use crate::texture::CheckerTexture;
use crate::texture::ConstantTexture;
use crate::texture::Texture;
use crate::vec3::Vec3;
pub fn new(opt: &Opt) -> Scene {
@ -30,23 +32,26 @@ pub fn new(opt: &Opt) -> Scene {
time_min,
time_max,
);
let ground_color = if opt.use_accel {
ConstantTexture::new(Vec3::new(1.0, 0.4, 0.4))
let ground_color: Box<dyn Texture> = if opt.use_accel {
Box::new(CheckerTexture::new(
ConstantTexture::new([0., 0., 0.]),
ConstantTexture::new([1.0, 0.4, 0.4]),
))
} else {
ConstantTexture::new(Vec3::new(0.4, 1.0, 0.4))
Box::new(ConstantTexture::new(Vec3::new(0.4, 1.0, 0.4)))
};
let objects: Vec<Box<dyn Hit>> = vec![
//let world: Box<Hit> = Box::new(HitableList::new(vec![
Box::new(Sphere::new([1., 0., 0.], 0.5, Dielectric::new(1.5))),
Box::new(Sphere::new([1., 0.5, 1.], 0.5, Dielectric::new(1.5))),
Box::new(Sphere::new(
Vec3::new(0., 0., -1.),
0.5,
Lambertian::new(ConstantTexture::new(Vec3::new(0.1, 0.2, 0.5))),
)),
Box::new(Sphere::new(
Vec3::new(0., -100.5, -1.),
100.,
Vec3::new(0., -1000.5, -1.),
1000.,
Lambertian::new(ground_color),
)),
Box::new(Sphere::new(

View File

@ -25,6 +25,12 @@ impl Texture for Arc<dyn Texture> {
}
}
impl Texture for Box<dyn Texture> {
fn value(&self, u: f32, v: f32, p: Vec3) -> Vec3 {
(**self).value(u, v, p)
}
}
#[cfg(test)]
mod test {
use super::*;