diff options
author | Julian T <julian@jtle.dk> | 2021-08-06 11:58:49 +0200 |
---|---|---|
committer | Julian T <julian@jtle.dk> | 2021-08-06 11:58:49 +0200 |
commit | 978580ff9464f7470c46f3084ee26021b71933c8 (patch) | |
tree | bb4d42fb5f1730a63a019727aee0ed2828e7033d /src | |
parent | 19914dfc7d8ce04f36539abd92f10e52baa7f740 (diff) |
Add other axis rectangles and render empty box
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 33 | ||||
-rw-r--r-- | src/world/shapes/rectangle.rs | 21 |
2 files changed, 34 insertions, 20 deletions
diff --git a/src/main.rs b/src/main.rs index 9cd2fc2..a288689 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,35 +12,35 @@ fn main() { let res = Vector2i::new_xy(500, 500); let cam = Camera::new(&CameraSettings { - target: Vector3f::new_xyz(0.0, 0.0, -1.0), - origin: Vector3f::new_xyz(0.0, 0.0, 1.0), + target: Vector3f::new_xyz(0.0, 0.0, 0.0), + origin: Vector3f::new_xyz(0.0, 0.0, 5.0), up: Vector3f::new_xyz(0.0, 1.0, 0.0), - fov: 50.0, + fov: 85.0, filmsize: res, focus: None, aperture: None, }); - 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 red = Arc::new(Lambertian::new(Spectrum::new_rgb(0.65, 0.05, 0.05))); + let white = Arc::new(Lambertian::new(Spectrum::new_rgb(0.73, 0.73, 0.73))); + let green = Arc::new(Lambertian::new(Spectrum::new_rgb(0.12, 0.45, 0.15))); let metal = Arc::new(Reflectant::new(Spectrum::new_rgb(0.8, 0.8, 0.9), Some(1.0))); let mirror = Arc::new(Reflectant::new(Spectrum::new_rgb(1.0, 1.0, 1.0), None)); let glass = Arc::new(Dielectric::new(1.5)); - let sun = Arc::new(DiffuseLight::new_white(14.0)); + let sun = Arc::new(DiffuseLight::new_white(15.0)); let mut scn = Scene::new(); scn.add_objects(vec![ - Object::new(glass, Sphere::new(0.2).translate(0.0, 0.0, -1.0)), - Object::new(blue, Sphere::new(0.5).translate(1.0, 0.0, -1.5)), - Object::new(mirror, Rect::new(0.4, 0.7, Plane::XY).translate(0.5, 0.0, -2.5)), - Object::new(brown.clone(), Rect::new(10.0, 2.0, Plane::XY).translate(0.5, 0.0, -2.6)), - Object::new(brown, Sphere::new(100.0).translate(0.0, -100.5, -1.0)), - Object::new(green, Sphere::new(0.4).translate(-0.5, 0.0, -2.0)), - //Object::new(sun, Sphere::new(0.4).translate(-1.0, 6.0, 0.0)), + Object::new(white.clone(), Rect::new_with_offset(10.0, 10.0, -5.0, Plane::XY)), + Object::new(white.clone(), Rect::new_with_offset(10.0, 10.0, 5.0, Plane::XY)), + Object::new(white.clone(), Rect::new_with_offset(10.0, 10.0, -5.0, Plane::XZ)), + Object::new(white.clone(), Rect::new_with_offset(10.0, 10.0, 5.0, Plane::XZ)), + Object::new(red.clone(), Rect::new_with_offset(10.0, 10.0, -5.0, Plane::YZ)), + Object::new(green.clone(), Rect::new_with_offset(10.0, 10.0, 5.0, Plane::YZ)), + Object::new(sun, Rect::new(1.4, 1.0, Plane::XZ).translate(0.0, 4.99, -2.5)), ]); - let tracer = DefaultTracer::new(&scn, Some(10), + let tracer = DefaultTracer::new(&scn, Some(5), Some(Box::new(SkyLight::new())) //None ); @@ -51,9 +51,10 @@ fn main() { let mut film = Film::new(res); { - let coord = RenderCoord::new(&mut film, Vector2i::new_xy(50, 50), 200); + let coord = RenderCoord::new(&mut film, Vector2i::new_xy(50, 50), 500); coord.run_threaded(&ctx, &mut sampler, 8); + //coord.work(&ctx, &mut sampler); } let image = film.finalize_image(); diff --git a/src/world/shapes/rectangle.rs b/src/world/shapes/rectangle.rs index 313ebb8..1630c00 100644 --- a/src/world/shapes/rectangle.rs +++ b/src/world/shapes/rectangle.rs @@ -6,6 +6,8 @@ const OUT_XY: Vector3f = Vector3f { x: 0.0, y: 0.0, z: 1.0 }; pub enum Plane { XY, + XZ, + YZ, } pub struct Rect { @@ -35,19 +37,20 @@ impl Rect { impl Hittable for Rect { fn intersect(&self, ray: &Ray) -> Option<Intersection> { - let t = (self.offset-ray.origin.z) / ray.direction.z; + let t = (self.offset - self.plane.translate(ray.origin).z) + / self.plane.translate(ray.direction).z; if t <= NEAR_ZERO { return None; } - let poi = ray.at(t); + let poi = self.plane.translate(ray.at(t)); // Check if at is inside rectangle on plane if poi.x.abs() > (self.d1/2.0) || poi.y.abs() > (self.d2/2.0) { // No collision return None; } - Some(Intersection::new(OUT_XY, poi, ray, t)) + Some(Intersection::new(self.plane.translate_inv(OUT_XY), self.plane.translate_inv(poi), ray, t)) } fn bounding_box(&self) -> Bound3f { @@ -68,9 +71,19 @@ impl Into<DynHittable> for Rect { impl Instancable for Rect {} impl Plane { - pub fn switch(&self, v: Vector3f) -> Vector3f { + pub fn translate(&self, v: Vector3f) -> Vector3f { match self { Plane::XY => v, + Plane::XZ => Vector3f::new_xyz(v.x, v.z, v.y), + Plane::YZ => Vector3f::new_xyz(v.y, v.z, v.x), + } + } + + pub fn translate_inv(&self, v: Vector3f) -> Vector3f { + match self { + Plane::XY => v, + Plane::XZ => Vector3f::new_xyz(v.x, v.z, v.y), + Plane::YZ => Vector3f::new_xyz(v.z, v.x, v.y), } } } |