diff options
author | Keuin <[email protected]> | 2022-04-15 18:03:14 +0800 |
---|---|---|
committer | Keuin <[email protected]> | 2022-04-15 18:03:14 +0800 |
commit | 272141d93324f32c15b7e230b0e37d122a418f54 (patch) | |
tree | 78ab672f4ca3bc08f2e09799025cd0c5640fe7ca /material_reflective.cpp | |
parent | 973806b2a59d458eae7dac8868721c4990cf8650 (diff) |
Add fuzzy reflective material.
Diffstat (limited to 'material_reflective.cpp')
-rw-r--r-- | material_reflective.cpp | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/material_reflective.cpp b/material_reflective.cpp index dc38baf..aa0d361 100644 --- a/material_reflective.cpp +++ b/material_reflective.cpp @@ -6,7 +6,9 @@ #include "material.h" #include "material_reflective.h" -bool material_reflective::scatter(ray3d &r, const object &hit_obj, double hit_t, random_uv_gen_3d &ruvg) const { +// perfectly-smooth reflective +template<> +bool material_reflective_<false>::scatter(ray3d &r, const object &hit_obj, double hit_t, random_uv_gen_3d &ruvg) const { const auto hit_point = r.at(hit_t); const auto nv = hit_obj.normal_vector(hit_point); const auto reflected = nv.reflect(r.direction()); @@ -15,3 +17,15 @@ bool material_reflective::scatter(ray3d &r, const object &hit_obj, double hit_t, r.decay(albedo); return dot(reflected, nv) > 0; } + +// fuzzy reflective +template<> +bool material_reflective_<true>::scatter(ray3d &r, const object &hit_obj, double hit_t, random_uv_gen_3d &ruvg) const { + const auto hit_point = r.at(hit_t); + const auto nv = hit_obj.normal_vector(hit_point); + const auto reflected = nv.reflect(r.direction()) + fuzzy_.f * ruvg.range01(); + r.source(hit_point); + r.direction(reflected.unit_vec()); + r.decay(albedo); + return dot(reflected, nv) > 0; +}
\ No newline at end of file |