From ed66f6748c8121aacf6c3cd48b9ac001c85c0978 Mon Sep 17 00:00:00 2001 From: Keuin Date: Thu, 14 Apr 2022 19:49:14 +0800 Subject: Implement Lambertian Reflection and Hemispherical Reflection. --- hitlist.h | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'hitlist.h') diff --git a/hitlist.h b/hitlist.h index 10be932..d498b26 100644 --- a/hitlist.h +++ b/hitlist.h @@ -22,6 +22,11 @@ //#define T_NORM_VISUAL #define T_DIFFUSE +// Select which diffuse method to use +//#define DIFFUSE_SIMPLE // Diffuse with a random vector whose length is in [0, 1] +#define DIFFUSE_LR // Diffuse with (possibly wrong) Lambertian Reflection, i.e. using a random unit vector +//#define DIFFUSE_HEMI // Diffuse with hemispherical scattering, i.e. using a normalized random vector within the hemisphere + // A world, T is color depth template class hitlist { @@ -76,7 +81,15 @@ public: const auto hit_point = r.at(hit_t); // hit point, on the surface auto nv = hit_obj->normal_vector(hit_point); if (dot(nv, r.direction()) > 0) return pixel::black(); // discard rays from inner (or invert nv) - vec3d diffuse_target = hit_point + nv + ruvg(); +#ifdef DIFFUSE_SIMPLE + vec3d diffuse_target = hit_point + nv + ruvg.range01(); +#endif +#ifdef DIFFUSE_LR + vec3d diffuse_target = hit_point + nv + ruvg.normalized(); +#endif +#ifdef DIFFUSE_HEMI + vec3d diffuse_target = hit_point + ruvg.hemisphere(nv); +#endif decay *= 0.5; // lose 50% light when diffused r = ray3d{hit_point, diffuse_target - hit_point}; // the new diffused ray we trace on continue; -- cgit v1.2.3