From 2d4671d5469116b05709bb1acb614d784d339964 Mon Sep 17 00:00:00 2001 From: Keuin Date: Fri, 15 Apr 2022 14:06:27 +0800 Subject: Make ray3::decay_ distinguishable between different color channels. --- material.cpp | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'material.cpp') diff --git a/material.cpp b/material.cpp index f92b02c..b312246 100644 --- a/material.cpp +++ b/material.cpp @@ -18,16 +18,21 @@ bool material_diffuse_lambertian::scatter(ray3d &r, const object &hit_obj, doubl return true; } -material_diffuse_lambertian::material_diffuse_lambertian(double albedo) : albedo(albedo) { - assert(albedo >= 0); - assert(albedo <= 1); +material_diffuse_lambertian::material_diffuse_lambertian(vec3d albedo) : albedo(albedo) { + assert(albedo.mod2() >= 0); + assert(albedo.mod2() <= 1); } -material_diffuse_simple::material_diffuse_simple(double albedo) : albedo(albedo) { +material_diffuse_lambertian::material_diffuse_lambertian(double albedo) : albedo{albedo, albedo, albedo} { assert(albedo >= 0); assert(albedo <= 1); } +material_diffuse_simple::material_diffuse_simple(vec3d albedo) : albedo(albedo) { + assert(albedo.mod2() >= 0); + assert(albedo.mod2() <= 1); +} + bool material_diffuse_simple::scatter(ray3d &r, const object &hit_obj, double hit_t, random_uv_gen_3d &ruvg) const { const auto hit_point = r.at(hit_t); // hit point, on the surface auto nv = hit_obj.normal_vector(hit_point); @@ -41,11 +46,16 @@ bool material_diffuse_simple::scatter(ray3d &r, const object &hit_obj, double hi return true; } -material_diffuse_hemispherical::material_diffuse_hemispherical(double albedo) : albedo(albedo) { +material_diffuse_simple::material_diffuse_simple(double albedo) : albedo{albedo, albedo, albedo} { assert(albedo >= 0); assert(albedo <= 1); } +material_diffuse_hemispherical::material_diffuse_hemispherical(vec3d albedo) : albedo(albedo) { + assert(albedo.mod2() >= 0); + assert(albedo.mod2() <= 1); +} + bool material_diffuse_hemispherical::scatter(ray3d &r, const object &hit_obj, double hit_t, random_uv_gen_3d &ruvg) const { const auto hit_point = r.at(hit_t); // hit point, on the surface @@ -59,3 +69,8 @@ material_diffuse_hemispherical::scatter(ray3d &r, const object &hit_obj, double r.direction((diffuse_target - hit_point).unit_vec()); // the new diffused ray we trace on return true; } + +material_diffuse_hemispherical::material_diffuse_hemispherical(double albedo) : albedo{albedo, albedo, albedo} { + assert(albedo >= 0); + assert(albedo <= 1); +} -- cgit v1.2.3