From 4193adbbff4a5b633f59f88367fe1b74aec7789b Mon Sep 17 00:00:00 2001 From: Keuin Date: Fri, 15 Apr 2022 12:32:42 +0800 Subject: Code Refactor: - Add material class. - Move diffuse routine into separate material classes. --- hitlist.h | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) (limited to 'hitlist.h') diff --git a/hitlist.h b/hitlist.h index 8625cb5..8073587 100644 --- a/hitlist.h +++ b/hitlist.h @@ -78,21 +78,12 @@ public: return pixel::from_normalized(nv); #endif #ifdef T_DIFFUSE - 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) -#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 - r.decay(0.5); // lose 50% light when diffused - r.source(hit_point); r.direction((diffuse_target - hit_point).unit_vec()); // the new diffused ray we trace on - continue; + const auto &materi = hit_obj->material(); + if (materi.scatter(r, *hit_obj, hit_t, ruvg)) { + continue; // The ray is scatted by an object. Continue processing the scattered ray. + } else { + return pixel::black(); // The ray is absorbed by an object completely. Return black. + } #endif } -- cgit v1.2.3