From e397ee9ad9187b102bdcf7b1b9913b6f6b499287 Mon Sep 17 00:00:00 2001 From: Jean-Michel Gorius Date: Fri, 11 Nov 2022 09:48:49 +0100 Subject: [PATCH] Use true Lambertian diffusion --- main.c | 2 +- vec3.c | 4 ++++ vec3.h | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/main.c b/main.c index 2d972ab..d78b555 100644 --- a/main.c +++ b/main.c @@ -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)); diff --git a/vec3.c b/vec3.c index 3d148d8..4dda89a 100644 --- a/vec3.c +++ b/vec3.c @@ -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()); +} diff --git a/vec3.h b/vec3.h index d4400c9..1bbd53b 100644 --- a/vec3.h +++ b/vec3.h @@ -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 */