Implement isotropic scattering for ConstantMedium volumes.
This commit is contained in:
parent
6a1e8b2784
commit
aeaf4994fe
@ -6,38 +6,42 @@ use rand::Rng;
|
|||||||
use aabb::AABB;
|
use aabb::AABB;
|
||||||
use hitable::Hit;
|
use hitable::Hit;
|
||||||
use hitable::HitRecord;
|
use hitable::HitRecord;
|
||||||
use material::Material;
|
use material::Isotropic;
|
||||||
use ray::Ray;
|
use ray::Ray;
|
||||||
|
use texture::Texture;
|
||||||
use vec3::Vec3;
|
use vec3::Vec3;
|
||||||
|
|
||||||
pub struct ConstantMedium<H, M>
|
pub struct ConstantMedium<H, T>
|
||||||
where
|
where
|
||||||
H: Hit,
|
H: Hit,
|
||||||
M: Material,
|
T: Texture,
|
||||||
{
|
{
|
||||||
density: f32,
|
density: f32,
|
||||||
material: M,
|
material: Isotropic<T>,
|
||||||
hitable: H,
|
hitable: H,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<H, M> ConstantMedium<H, M>
|
impl<H, T> ConstantMedium<H, T>
|
||||||
where
|
where
|
||||||
H: Hit,
|
H: Hit,
|
||||||
M: Material,
|
T: Texture,
|
||||||
|
{
|
||||||
|
pub fn new(hitable: H, density: f32, texture: T) -> ConstantMedium<H, T>
|
||||||
|
where
|
||||||
|
T: Texture,
|
||||||
{
|
{
|
||||||
pub fn new(hitable: H, density: f32, material: M) -> ConstantMedium<H, M> {
|
|
||||||
ConstantMedium {
|
ConstantMedium {
|
||||||
density,
|
density,
|
||||||
material,
|
material: Isotropic::new(texture),
|
||||||
hitable,
|
hitable,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<H, M> Hit for ConstantMedium<H, M>
|
impl<H, T> Hit for ConstantMedium<H, T>
|
||||||
where
|
where
|
||||||
H: Hit,
|
H: Hit,
|
||||||
M: Material,
|
T: Texture,
|
||||||
{
|
{
|
||||||
fn hit(&self, r: Ray, t_min: f32, t_max: f32) -> Option<HitRecord> {
|
fn hit(&self, r: Ray, t_min: f32, t_max: f32) -> Option<HitRecord> {
|
||||||
let mut rng = rand::thread_rng();
|
let mut rng = rand::thread_rng();
|
||||||
|
|||||||
@ -56,11 +56,40 @@ impl Material for Box<Material> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct Isotropic<T>
|
||||||
|
where
|
||||||
|
T: Texture,
|
||||||
|
{
|
||||||
|
albedo: T,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> Isotropic<T>
|
||||||
|
where
|
||||||
|
T: Texture,
|
||||||
|
{
|
||||||
|
pub fn new(texture: T) -> Isotropic<T> {
|
||||||
|
Isotropic { albedo: texture }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> Material for Isotropic<T>
|
||||||
|
where
|
||||||
|
T: Texture,
|
||||||
|
{
|
||||||
|
fn scatter(&self, _r_in: &Ray, rec: &HitRecord) -> ScatterResponse {
|
||||||
|
let (u, v) = rec.uv;
|
||||||
|
ScatterResponse {
|
||||||
|
attenutation: self.albedo.value(u, v, rec.p),
|
||||||
|
scattered: Ray::new(rec.p, random_in_unit_sphere(), 0.),
|
||||||
|
reflected: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct Lambertian<T>
|
pub struct Lambertian<T>
|
||||||
where
|
where
|
||||||
T: Texture,
|
T: Texture,
|
||||||
{
|
{
|
||||||
// TODO(wathiede): implement texture sharing via references
|
|
||||||
albedo: T,
|
albedo: T,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -59,7 +59,7 @@ pub fn new(opt: &Opt) -> Scene {
|
|||||||
Vec3::new(130., 0., 65.),
|
Vec3::new(130., 0., 65.),
|
||||||
),
|
),
|
||||||
0.01,
|
0.01,
|
||||||
Lambertian::new(ConstantTexture::new([1., 1., 1.])),
|
ConstantTexture::new([1., 1., 1.]),
|
||||||
)),
|
)),
|
||||||
// Black smoke box on the left
|
// Black smoke box on the left
|
||||||
Box::new(ConstantMedium::new(
|
Box::new(ConstantMedium::new(
|
||||||
@ -75,7 +75,7 @@ pub fn new(opt: &Opt) -> Scene {
|
|||||||
Vec3::new(265., 0., 295.),
|
Vec3::new(265., 0., 295.),
|
||||||
),
|
),
|
||||||
0.01,
|
0.01,
|
||||||
Lambertian::new(ConstantTexture::new([0., 0., 0.])),
|
ConstantTexture::new([0., 0., 0.]),
|
||||||
)),
|
)),
|
||||||
// Green wall left
|
// Green wall left
|
||||||
Box::new(FlipNormals::new(YZRect::new(
|
Box::new(FlipNormals::new(YZRect::new(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user