aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJulian T <julian@jtle.dk>2021-08-01 23:24:44 +0200
committerJulian T <julian@jtle.dk>2021-08-01 23:24:44 +0200
commit13e018067631a7401df5b232f95f3d1f7a0cd75c (patch)
tree2c91fe273cfeab48548ffb77c3392bdbdad650a5 /src
parent86ad7845219e8db06fe47b62794180e1b40f90a5 (diff)
Readd reflective material
Diffstat (limited to 'src')
-rw-r--r--src/main.rs14
-rw-r--r--src/material/dielectric.rs5
-rw-r--r--src/material/mod.rs2
-rw-r--r--src/material/reflectant.rs6
4 files changed, 14 insertions, 13 deletions
diff --git a/src/main.rs b/src/main.rs
index a05c1c1..a21380f 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -25,16 +25,18 @@ fn main() {
let brown = Arc::new(Lambertian::new(Spectrum::new_rgb(0.5, 0.3, 0.0)));
let blue = Arc::new(Lambertian::new(Spectrum::new_rgb(0.0, 0.3, 0.7)));
let green = Arc::new(Lambertian::new(Spectrum::new_rgb(0.0, 0.7, 0.3)));
- let metal = Arc::new(Dielectric::new(1.5));
- let sun = Arc::new(DiffuseLight::new_white(13.0));
+ let metal = Arc::new(Reflectant::new(Spectrum::new_rgb(0.8, 0.8, 0.9), Some(1.0)));
+ let glass = Arc::new(Dielectric::new(1.5));
+ let sun = Arc::new(DiffuseLight::new_white(50.0));
let mut scn = Scene::new();
scn.add_objects(vec![
- Object::new(metal, Sphere::new(0.2, Vector3f::new_xyz(0.0, 0.0, -1.0))),
- Object::new(blue.clone(), Sphere::new(0.5, Vector3f::new_xyz(1.0, 0.0, -1.5))),
+ Object::new(glass, Sphere::new(0.2, Vector3f::new_xyz(0.0, 0.0, -1.0))),
+ Object::new(blue, Sphere::new(0.5, Vector3f::new_xyz(1.0, 0.0, -1.5))),
Object::new(green, Sphere::new(0.3, Vector3f::new_xyz(0.5, 0.0, -2.5))),
Object::new(brown, Sphere::new(100.0, Vector3f::new_xyz(0.0, -100.5, -1.0))),
- Object::new(sun, Sphere::new(0.4, Vector3f::new_xyz(-1.0, 0.7, 0.0))),
+ Object::new(metal, Sphere::new(0.2, Vector3f::new_xyz(-0.5, 0.0, -1.0))),
+ Object::new(sun, Sphere::new(0.4, Vector3f::new_xyz(-1.0, 3.0, 0.0))),
]);
let tracer = DefaultTracer::new(&scn, Some(50),
@@ -48,7 +50,7 @@ fn main() {
let mut film = Film::new(res);
{
- let coord = RenderCoord::new(&mut film, Vector2i::new_xy(64, 64), 50);
+ let coord = RenderCoord::new(&mut film, Vector2i::new_xy(50, 50), 1000);
coord.run_threaded(&ctx, &mut sampler, 8);
}
diff --git a/src/material/dielectric.rs b/src/material/dielectric.rs
index 41f47c2..c8dc279 100644
--- a/src/material/dielectric.rs
+++ b/src/material/dielectric.rs
@@ -3,15 +3,12 @@ use crate::core::{min, Vector3f, Spectrum, Ray};
use crate::world::Intersection;
use crate::sample::Sampler;
use crate::Float;
+use crate::material::reflectant::reflect;
pub struct Dielectric {
ratio: Float,
}
-fn reflect(v: Vector3f, n: Vector3f) -> Vector3f {
- v - n * (2.0 * v.dot(&n))
-}
-
// Implementation from RTIOW
fn refract(v: Vector3f, n: Vector3f, r_ratio: Float, cos_theta: Float) -> Vector3f {
let r_perp = (v + n * cos_theta) * r_ratio;
diff --git a/src/material/mod.rs b/src/material/mod.rs
index d3c3154..6732598 100644
--- a/src/material/mod.rs
+++ b/src/material/mod.rs
@@ -6,11 +6,13 @@ mod lambertian;
mod diffuse_light;
mod sky_light;
mod dielectric;
+pub mod reflectant;
pub use lambertian::Lambertian;
pub use diffuse_light::DiffuseLight;
pub use sky_light::SkyLight;
pub use dielectric::Dielectric;
+pub use reflectant::Reflectant;
pub trait Material: Sync + Send {
fn scatter(&self, _: &Ray, _: &Intersection, _: &mut dyn Sampler) -> Option<(Spectrum, Ray)> {
diff --git a/src/material/reflectant.rs b/src/material/reflectant.rs
index dea7aca..b5ec0ae 100644
--- a/src/material/reflectant.rs
+++ b/src/material/reflectant.rs
@@ -18,14 +18,14 @@ impl Reflectant {
}
}
-fn reflect(v: &Vector3f, n: &Vector3f) -> Vector3f {
- *v - *n * (2.0 * v.dot(n))
+pub fn reflect(v: Vector3f, n: Vector3f) -> Vector3f {
+ v - n * (2.0 * v.dot(&n))
}
impl Material for Reflectant {
fn scatter(&self, ray: &Ray, i: &Intersection, sampler: &mut dyn Sampler) -> Option<(Spectrum, Ray)> {
// Find reflectance vector
- let mut reflected = reflect(&ray.direction, &i.n);
+ let mut reflected = reflect(ray.direction, i.n);
if let Some(fuzz) = self.fuzz {
reflected += &(sampler.get_unit_vector() * fuzz);
}