From 09c233e4f4af81981d72f10691153d318c83c9fd Mon Sep 17 00:00:00 2001 From: Keuin Date: Fri, 15 Apr 2022 14:08:31 +0800 Subject: Rename material.cpp -> material_diffusive.cpp. --- CMakeLists.txt | 4 +-- material.cpp | 76 -------------------------------------------------- material_diffusive.cpp | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+), 78 deletions(-) delete mode 100644 material.cpp create mode 100644 material_diffusive.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 7ff949a..343cf09 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,9 +12,9 @@ set(CMAKE_VERBOSE_MAKEFILE on) # main executable -add_executable(rt main.cpp vec.h bitmap.h ray.h bitfont.h hitlist.h object.h sphere.h viewport.h aa.h material.h material.cpp) +add_executable(rt main.cpp vec.h bitmap.h ray.h bitfont.h hitlist.h object.h sphere.h viewport.h aa.h material.h material_diffusive.cpp) add_executable(image_output main_image_output.cpp vec.h bitmap.h bitfont.h hitlist.h object.h sphere.h viewport.h) -add_executable(simple_scanner main_simple_scanner.cpp vec.h bitmap.h ray.h timer.h bitfont.h hitlist.h object.h sphere.h viewport.h aa.h material.h material.cpp) +add_executable(simple_scanner main_simple_scanner.cpp vec.h bitmap.h ray.h timer.h bitfont.h hitlist.h object.h sphere.h viewport.h aa.h material.h material_diffusive.cpp) # googletest diff --git a/material.cpp b/material.cpp deleted file mode 100644 index b312246..0000000 --- a/material.cpp +++ /dev/null @@ -1,76 +0,0 @@ -// -// Created by Keuin on 2022/4/15. -// - -#include "material.h" - - -bool material_diffuse_lambertian::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); - if (dot(nv, r.direction()) > 0) return false; // discard rays from inner (or invert nv) - auto d = nv + ruvg.normalized(); - if (d.is_zero()) d = nv; - vec3d diffuse_target = hit_point + d; - r.decay(albedo); // lose some light when diffused - r.source(hit_point); - r.direction((diffuse_target - hit_point).unit_vec()); // the new diffused ray we trace on - return true; -} - -material_diffuse_lambertian::material_diffuse_lambertian(vec3d albedo) : albedo(albedo) { - assert(albedo.mod2() >= 0); - assert(albedo.mod2() <= 1); -} - -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); - if (dot(nv, r.direction()) > 0) return false; // discard rays from inner (or invert nv) - auto d = nv + ruvg.normalized(); - if (d.is_zero()) d = nv; - vec3d diffuse_target = hit_point + nv + ruvg.range01(); - r.decay(albedo); // lose some light when diffused - r.source(hit_point); - r.direction((diffuse_target - hit_point).unit_vec()); // the new diffused ray we trace on - return true; -} - -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 - auto nv = hit_obj.normal_vector(hit_point); - if (dot(nv, r.direction()) > 0) return false; // discard rays from inner (or invert nv) - auto d = nv + ruvg.normalized(); - if (d.is_zero()) d = nv; - vec3d diffuse_target = hit_point + ruvg.hemisphere(nv); - r.decay(albedo); // lose some light when diffused - r.source(hit_point); - 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); -} diff --git a/material_diffusive.cpp b/material_diffusive.cpp new file mode 100644 index 0000000..b312246 --- /dev/null +++ b/material_diffusive.cpp @@ -0,0 +1,76 @@ +// +// Created by Keuin on 2022/4/15. +// + +#include "material.h" + + +bool material_diffuse_lambertian::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); + if (dot(nv, r.direction()) > 0) return false; // discard rays from inner (or invert nv) + auto d = nv + ruvg.normalized(); + if (d.is_zero()) d = nv; + vec3d diffuse_target = hit_point + d; + r.decay(albedo); // lose some light when diffused + r.source(hit_point); + r.direction((diffuse_target - hit_point).unit_vec()); // the new diffused ray we trace on + return true; +} + +material_diffuse_lambertian::material_diffuse_lambertian(vec3d albedo) : albedo(albedo) { + assert(albedo.mod2() >= 0); + assert(albedo.mod2() <= 1); +} + +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); + if (dot(nv, r.direction()) > 0) return false; // discard rays from inner (or invert nv) + auto d = nv + ruvg.normalized(); + if (d.is_zero()) d = nv; + vec3d diffuse_target = hit_point + nv + ruvg.range01(); + r.decay(albedo); // lose some light when diffused + r.source(hit_point); + r.direction((diffuse_target - hit_point).unit_vec()); // the new diffused ray we trace on + return true; +} + +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 + auto nv = hit_obj.normal_vector(hit_point); + if (dot(nv, r.direction()) > 0) return false; // discard rays from inner (or invert nv) + auto d = nv + ruvg.normalized(); + if (d.is_zero()) d = nv; + vec3d diffuse_target = hit_point + ruvg.hemisphere(nv); + r.decay(albedo); // lose some light when diffused + r.source(hit_point); + 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