diff options
author | Keuin <[email protected]> | 2022-04-14 19:49:14 +0800 |
---|---|---|
committer | Keuin <[email protected]> | 2022-04-14 20:02:22 +0800 |
commit | ed66f6748c8121aacf6c3cd48b9ac001c85c0978 (patch) | |
tree | adc72ccb8599b5742b141645faf6e03452efb261 /hitlist.h | |
parent | 25305140df28c19f622209bb514d290ad6e6486b (diff) |
Implement Lambertian Reflection and Hemispherical Reflection.
Diffstat (limited to 'hitlist.h')
-rw-r--r-- | hitlist.h | 15 |
1 files changed, 14 insertions, 1 deletions
@@ -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<typename T> 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<T>::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; |