summaryrefslogtreecommitdiff
path: root/material_reflective.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'material_reflective.cpp')
-rw-r--r--material_reflective.cpp16
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