Skip to content

Commit

Permalink
9.4 - lambertian reflection
Browse files Browse the repository at this point in the history
  • Loading branch information
grishy committed Feb 18, 2024
1 parent 1a1f78c commit 93a614a
Showing 1 changed file with 2 additions and 15 deletions.
17 changes: 2 additions & 15 deletions src/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl Camera {
pixel00_loc: pixel00_loc,
pixel_delta_u: pixel_delta_u,
pixel_delta_v: pixel_delta_v,
samples_per_pixel: 100,
samples_per_pixel: 50,
max_depth: 10,
}
}
Expand Down Expand Up @@ -151,7 +151,7 @@ fn ray_color(ray: &ray::Ray, depth: i32, world: &HittableList) -> Color {

match world.hit(ray, range) {
Some(h) => {
let direction = random_on_hemisphere(h.normal);
let direction = h.normal + random_in_unit_sphere();
let new_ray = ray::Ray::new(h.p, direction);
0.5 * ray_color(&new_ray, depth - 1, world)
}
Expand All @@ -163,19 +163,6 @@ fn ray_color(ray: &ray::Ray, depth: i32, world: &HittableList) -> Color {
}
}

fn random_on_hemisphere(normal: Vector3) -> Vector3 {
let on_unit_sphere = random_unit_vector();
if on_unit_sphere.dot(&normal) > 0.0 {
on_unit_sphere
} else {
-on_unit_sphere
}
}

fn random_unit_vector() -> Vector3 {
return random_in_unit_sphere().normalize();
}

fn random_in_unit_sphere() -> Vector3 {
let mut rng = rand::thread_rng();
loop {
Expand Down

0 comments on commit 93a614a

Please sign in to comment.