diff options
author | Keuin <[email protected]> | 2022-04-15 12:32:42 +0800 |
---|---|---|
committer | Keuin <[email protected]> | 2022-04-15 12:32:42 +0800 |
commit | 4193adbbff4a5b633f59f88367fe1b74aec7789b (patch) | |
tree | 25056ac9e028e268193615724dda8c3ac12317d0 /hitlist.h | |
parent | 2ed39ad4eb9ebf64768dbf4aeefafc5ebb072ca7 (diff) |
Code Refactor:
- Add material class.
- Move diffuse routine into separate material classes.
Diffstat (limited to 'hitlist.h')
-rw-r--r-- | hitlist.h | 21 |
1 files changed, 6 insertions, 15 deletions
@@ -78,21 +78,12 @@ public: return pixel<T>::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<T>::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<T>::black(); // The ray is absorbed by an object completely. Return black. + } #endif } |