Use true Lambertian diffusion

This commit is contained in:
Jean-Michel Gorius 2022-11-11 09:48:49 +01:00
parent 204180b1a7
commit e397ee9ad9
3 changed files with 6 additions and 1 deletions

2
main.c
View File

@ -18,7 +18,7 @@ Color ray_color(Ray r, Hittable world, int depth) {
HitRecord record;
if (hittable_hit(&world, r, 0.001, DBL_MAX, &record)) {
Point3 target = point3_add(
record.p, vec3_add(record.normal, vec3_random_in_unit_sphere()));
record.p, vec3_add(record.normal, vec3_random_unit_vector()));
return color_mul(0.5,
ray_color((Ray){record.p, point3_sub(target, record.p)},
world, depth - 1));

4
vec3.c
View File

@ -59,3 +59,7 @@ Vec3 vec3_random_in_unit_sphere(void) {
return result;
}
}
Vec3 vec3_random_unit_vector(void) {
return vec3_normalize(vec3_random_in_unit_sphere());
}

1
vec3.h
View File

@ -22,5 +22,6 @@ Vec3 vec3_cross(Vec3 v1, Vec3 v2);
Vec3 vec3_random(void);
Vec3 vec3_random_in_range(double min, double max);
Vec3 vec3_random_in_unit_sphere(void);
Vec3 vec3_random_unit_vector(void);
#endif /* INCLUDED_VEC3_H */