Add CheckerTexture.
This commit is contained in:
parent
a1d3cce4e4
commit
96d49e685f
@ -5,10 +5,10 @@ use hitable::Hit;
|
|||||||
use hitable_list::HitableList;
|
use hitable_list::HitableList;
|
||||||
use kdtree::KDTree;
|
use kdtree::KDTree;
|
||||||
use material::Lambertian;
|
use material::Lambertian;
|
||||||
use material::Metal;
|
|
||||||
use renderer::Opt;
|
use renderer::Opt;
|
||||||
use renderer::Scene;
|
use renderer::Scene;
|
||||||
use sphere::Sphere;
|
use sphere::Sphere;
|
||||||
|
use texture::CheckerTexture;
|
||||||
use texture::ConstantTexture;
|
use texture::ConstantTexture;
|
||||||
use vec3::Vec3;
|
use vec3::Vec3;
|
||||||
|
|
||||||
@ -33,7 +33,10 @@ pub fn new(opt: &Opt) -> Scene {
|
|||||||
let mut objects: Vec<Box<Hit>> = vec![Box::new(Sphere::new(
|
let mut objects: Vec<Box<Hit>> = vec![Box::new(Sphere::new(
|
||||||
Vec3::new(0., 0., 0.),
|
Vec3::new(0., 0., 0.),
|
||||||
5.,
|
5.,
|
||||||
Box::new(Metal::new(Vec3::new(0.5, 0.5, 0.5), 0.)),
|
Box::new(Lambertian::new(Box::new(CheckerTexture::new(
|
||||||
|
Box::new(ConstantTexture::new(Vec3::new(0., 0., 0.))),
|
||||||
|
Box::new(ConstantTexture::new(Vec3::new(1., 1., 1.))),
|
||||||
|
)))),
|
||||||
))];
|
))];
|
||||||
let num_spheres = 6;
|
let num_spheres = 6;
|
||||||
let radius = 7.;
|
let radius = 7.;
|
||||||
|
|||||||
@ -19,3 +19,25 @@ impl Texture for ConstantTexture {
|
|||||||
self.color
|
self.color
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct CheckerTexture {
|
||||||
|
odd: Box<Texture>,
|
||||||
|
even: Box<Texture>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CheckerTexture {
|
||||||
|
pub fn new(odd: Box<Texture>, even: Box<Texture>) -> CheckerTexture {
|
||||||
|
CheckerTexture { odd, even }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Texture for CheckerTexture {
|
||||||
|
fn value(&self, u: f32, v: f32, p: Vec3) -> Vec3 {
|
||||||
|
let sines = (10. * p.x).sin() * (10. * p.y).sin() * (10. * p.z).sin();
|
||||||
|
if sines < 0. {
|
||||||
|
self.odd.value(u, v, p)
|
||||||
|
} else {
|
||||||
|
self.even.value(u, v, p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user