Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/raytracer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl Raytracer {
Raytracer {
config,
canvas,
scene: Scene::new_specular(),
scene: Scene::new_glass(),
}
}

Expand Down
10 changes: 9 additions & 1 deletion src/scene/geo.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
extern crate nalgebra as na;

use std::ops::{Add, Mul, Sub};
use std::ops::{Add, Mul, Neg, Sub};
use std::f64::consts::PI;

use na::base::{Matrix3, Vector3};
Expand Down Expand Up @@ -207,3 +207,11 @@ impl Mul<f64> for Vector {
Vector::new_from_na(self.v * other)
}
}

impl Neg for Vector {
type Output = Vector;

fn neg(self) -> Self::Output {
Vector::new_from_na(-self.v)
}
}
37 changes: 34 additions & 3 deletions src/scene/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ impl<'a> RayIntersection<'a> {
let min_dist = self.distance();
let ray = self.ray();
let scaled_vector = ray.direction * min_dist;
let intersection_point = ray.origin + scaled_vector;
let intersection_point = ray.origin + scaled_vector;
intersection_point
// bumping the point a little out of the object to prevent self-collision
let surface_normal: Vector = self.object.surface_normal(intersection_point);
intersection_point + (surface_normal * EPS)
// let surface_normal: Vector = self.object.surface_normal(intersection_point);
// intersection_point + (surface_normal * EPS)
}
}

Expand Down Expand Up @@ -254,6 +255,36 @@ impl Scene {
Scene::new(triangles, spheres)
}

pub fn new_glass() -> Scene {
let cb = Scene::cornell_box();
let (half_length,
box_z_offset,
red_diffuse_material,
triangles,
) = (cb.half_length, cb.box_z_offset, cb.red_diffuse_material, cb.triangles);
let glass_material = Material::new(
BSDF::Glass(1.5),
Spectrum::white(),
Spectrum::black(),
);
let sphere_radius = 6.0;
let spheres = vec![
cb.sphere_light,
Sphere::new(Point::new(-half_length / 3.0,
-half_length + sphere_radius,
box_z_offset - 2.0 * half_length / 3.0),
sphere_radius,
glass_material),
Sphere::new(Point::new(half_length / 3.0,
-half_length + sphere_radius,
box_z_offset - half_length / 3.0),
sphere_radius,
red_diffuse_material),
];

Scene::new(triangles, spheres)
}

pub fn new_diffuse() -> Scene {
let cb = Scene::cornell_box();
let (half_length,
Expand Down
Loading