diff --git a/src/main.rs b/src/main.rs index 52302d1..13c895f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -84,17 +84,18 @@ fn main() { // render let mut small_rng = SmallRng::from_entropy(); - let distrib = Uniform::new(0.0, 1.0); + let distrib_zero_one = Uniform::new(0.0, 1.0); + let distrib_plusminus_one = Uniform::new(-1.0, 1.0); println!("P3\n{} {}\n255", image.0, image.1); for y in (0..image.1).rev() { eprintln!("Scanlines remaining: {}", y); for x in 0..image.0 { let mut color = Vec3::zero(); for _ in 0..samples_per_pixel { - let u = ((x as f32) + small_rng.sample(distrib)) / ((image.0 - 1) as f32); - let v = ((y as f32) + small_rng.sample(distrib)) / ((image.1 - 1) as f32); + let u = ((x as f32) + small_rng.sample(distrib_zero_one)) / ((image.0 - 1) as f32); + let v = ((y as f32) + small_rng.sample(distrib_zero_one)) / ((image.1 - 1) as f32); let ray = cam.get_ray(u, v); - color+= ray_color(ray, &world, max_depth, &mut small_rng, distrib); + color+= ray_color(ray, &world, max_depth, &mut small_rng, distrib_plusminus_one); } println!("{}", color.print_ppm(samples_per_pixel)); } @@ -119,7 +120,6 @@ fn ray_color(r: Ray, world: &dyn Hittable, depth: u32, srng: &mut SmallRng, dist if mat.scatter(r, rec, &mut attenuation, &mut scattered, srng, distrib) { return attenuation * ray_color(scattered, world, depth-1, srng, distrib); }; - }, None => return Vec3::zero(), } diff --git a/src/ray.rs b/src/ray.rs index 314f6a5..f6eb722 100644 --- a/src/ray.rs +++ b/src/ray.rs @@ -1,12 +1,7 @@ use crate::vec3::Vec3; -use crate::hittable::{ - Hittable, - HitRecord, -}; -#[derive(Copy)] -#[derive(Clone)] +#[derive(Copy, Clone)] pub struct Ray{ pub orig: Vec3, pub dir: Vec3,