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.h | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) (limited to 'material_reflective.h') diff --git a/material_reflective.h b/material_reflective.h index 91afa7c..64e6457 100644 --- a/material_reflective.h +++ b/material_reflective.h @@ -8,15 +8,44 @@ #include "vec.h" #include "material.h" -// metal -class material_reflective : public material { +template +struct s_fuzzy_ { + // non-fuzzy material does not need these variables + // we remove them with an empty struct +}; + +template<> +struct s_fuzzy_ { + double f; // how fuzzy the material is + // those are parameters that only fuzzy materials have +}; + +// metal with perfectly smooth surface +template +class material_reflective_ : public material { vec3d albedo; + s_fuzzy_ fuzzy_; public: - explicit material_reflective(vec3d &color) : albedo(color) {} - explicit material_reflective(vec3d &&color) : albedo(color) {} - explicit material_reflective(double color) : albedo{color, color, color} {} + // FIXME conditionally enable these constructors by template parameter `Fuzzy`. + + // Non-fuzzy constructors + explicit material_reflective_(vec3d &color) : albedo(color), fuzzy_{} {} + + explicit material_reflective_(vec3d &&color) : albedo(color), fuzzy_{} {} + + explicit material_reflective_(double color) : albedo{color, color, color}, fuzzy_{} {} + + // Fuzzy constructors, with special parameters + explicit material_reflective_(vec3d &color, double f) : albedo(color), fuzzy_{f} {} + + explicit material_reflective_(vec3d &&color, double f) : albedo(color), fuzzy_{f} {} + + explicit material_reflective_(double color, double f) : albedo{color, color, color}, fuzzy_{f} {} bool scatter(ray3d &r, const object &hit_obj, double hit_t, random_uv_gen_3d &ruvg) const override; }; +using material_reflective = material_reflective_; +using material_fuzzy_reflective = material_reflective_; + #endif //RT_MATERIAL_REFLECTIVE_H -- cgit v1.2.3