add alternate diffuse method

This commit is contained in:
Fabien Freling 2021-05-11 19:11:14 +02:00
parent 58f710c967
commit 3296ea3e81
2 changed files with 15 additions and 1 deletions

View file

@ -41,7 +41,7 @@ fn rayColor(ray: Ray, world: World, rng: *Random, depth: i32) Color {
}
if (world.hit(ray, 0.001, 99999)) |hit| {
const target = hit.p.add(hit.normal).add(vec3.random_in_unit_sphere(rng));
const target = hit.p.add(vec3.random_in_hemisphere(rng, hit.normal));
const newRay = Ray{ .origin = hit.p, .direction = target.sub(hit.p)};
return rayColor(newRay, world, rng, depth - 1).div(2);
}