From 272141d93324f32c15b7e230b0e37d122a418f54 Mon Sep 17 00:00:00 2001 From: Keuin Date: Fri, 15 Apr 2022 18:03:14 +0800 Subject: Add fuzzy reflective material. --- material_reflective.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'material_reflective.cpp') 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_::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_::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 -- cgit v1.2.3