summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeuin <[email protected]>2022-04-15 14:34:46 +0800
committerKeuin <[email protected]>2022-04-15 14:34:46 +0800
commit1ed823c4fc7ad137b88019a2fa9f17ae3d10215d (patch)
treed1ababb9e3c0dd10929ee60c086b1f91b210c430
parent9c3632426ca0cf8691347873dd9b1fae92e5e5bf (diff)
Move diffusive into material_diffusive. Add material_reflective.h.
-rw-r--r--CMakeLists.txt4
-rw-r--r--main_simple_scanner.cpp3
-rw-r--r--material.h27
-rw-r--r--material_diffusive.cpp2
-rw-r--r--material_diffusive.h38
-rw-r--r--material_reflective.cpp17
-rw-r--r--material_reflective.h20
7 files changed, 80 insertions, 31 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 343cf09..2ed3de8 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_diffusive.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.h material_diffusive.cpp material_reflective.h material_reflective.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_diffusive.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.h material_diffusive.cpp material_reflective.h material_reflective.cpp)
# googletest
diff --git a/main_simple_scanner.cpp b/main_simple_scanner.cpp
index 264bf4e..1c05a8c 100644
--- a/main_simple_scanner.cpp
+++ b/main_simple_scanner.cpp
@@ -14,7 +14,8 @@
#include "hitlist.h"
#include "sphere.h"
#include "aa.h"
-#include "material.h"
+#include "material_diffusive.h"
+#include "material_reflective.h"
// T: intermediate color depth
template<typename T>
diff --git a/material.h b/material.h
index adb2b69..b340796 100644
--- a/material.h
+++ b/material.h
@@ -22,31 +22,4 @@ public:
virtual bool scatter(ray3d &r, const object &hit_obj, double hit_t, random_uv_gen_3d &ruvg) const = 0;
};
-class material_diffuse_lambertian : public material {
- vec3d albedo;
-public:
- explicit material_diffuse_lambertian(vec3d albedo);
- explicit material_diffuse_lambertian(double albedo);
-
- bool scatter(ray3d &r, const object &hit_obj, double hit_t, random_uv_gen_3d &ruvg) const override;
-};
-
-class material_diffuse_simple : public material {
- vec3d albedo;
-public:
- explicit material_diffuse_simple(vec3d albedo);
- explicit material_diffuse_simple(double albedo);
-
- bool scatter(ray3d &r, const object &hit_obj, double hit_t, random_uv_gen_3d &ruvg) const override;
-};
-
-class material_diffuse_hemispherical : public material {
- vec3d albedo;
-public:
- explicit material_diffuse_hemispherical(vec3d albedo);
- explicit material_diffuse_hemispherical(double albedo);
-
- bool scatter(ray3d &r, const object &hit_obj, double hit_t, random_uv_gen_3d &ruvg) const override;
-};
-
#endif //RT_MATERIAL_H
diff --git a/material_diffusive.cpp b/material_diffusive.cpp
index 2a554d0..74f58f7 100644
--- a/material_diffusive.cpp
+++ b/material_diffusive.cpp
@@ -3,7 +3,7 @@
//
#include "vec.h"
-#include "material.h"
+#include "material_diffusive.h"
bool material_diffuse_lambertian::scatter(ray3d &r, const object &hit_obj, double hit_t, random_uv_gen_3d &ruvg) const {
diff --git a/material_diffusive.h b/material_diffusive.h
new file mode 100644
index 0000000..73377aa
--- /dev/null
+++ b/material_diffusive.h
@@ -0,0 +1,38 @@
+//
+// Created by Keuin on 2022/4/15.
+//
+
+#ifndef RT_MATERIAL_DIFFUSIVE_H
+#define RT_MATERIAL_DIFFUSIVE_H
+
+#include "vec.h"
+#include "material.h"
+
+class material_diffuse_lambertian : public material {
+ vec3d albedo;
+public:
+ explicit material_diffuse_lambertian(vec3d albedo);
+ explicit material_diffuse_lambertian(double albedo);
+
+ bool scatter(ray3d &r, const object &hit_obj, double hit_t, random_uv_gen_3d &ruvg) const override;
+};
+
+class material_diffuse_simple : public material {
+ vec3d albedo;
+public:
+ explicit material_diffuse_simple(vec3d albedo);
+ explicit material_diffuse_simple(double albedo);
+
+ bool scatter(ray3d &r, const object &hit_obj, double hit_t, random_uv_gen_3d &ruvg) const override;
+};
+
+class material_diffuse_hemispherical : public material {
+ vec3d albedo;
+public:
+ explicit material_diffuse_hemispherical(vec3d albedo);
+ explicit material_diffuse_hemispherical(double albedo);
+
+ bool scatter(ray3d &r, const object &hit_obj, double hit_t, random_uv_gen_3d &ruvg) const override;
+};
+
+#endif //RT_MATERIAL_DIFFUSIVE_H
diff --git a/material_reflective.cpp b/material_reflective.cpp
new file mode 100644
index 0000000..dc38baf
--- /dev/null
+++ b/material_reflective.cpp
@@ -0,0 +1,17 @@
+//
+// Created by Keuin on 2022/4/15.
+//
+
+#include "vec.h"
+#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 {
+ const auto hit_point = r.at(hit_t);
+ const auto nv = hit_obj.normal_vector(hit_point);
+ const auto reflected = nv.reflect(r.direction());
+ r.source(hit_point);
+ r.direction(reflected);
+ r.decay(albedo);
+ return dot(reflected, nv) > 0;
+}
diff --git a/material_reflective.h b/material_reflective.h
new file mode 100644
index 0000000..d2e4010
--- /dev/null
+++ b/material_reflective.h
@@ -0,0 +1,20 @@
+//
+// Created by Keuin on 2022/4/15.
+//
+
+#ifndef RT_MATERIAL_REFLECTIVE_H
+#define RT_MATERIAL_REFLECTIVE_H
+
+#include "vec.h"
+#include "material.h"
+
+// metal
+class material_reflective : public material {
+ vec3d albedo;
+public:
+ explicit material_reflective(vec3d &color) : albedo(color) {}
+
+ bool scatter(ray3d &r, const object &hit_obj, double hit_t, random_uv_gen_3d &ruvg) const override;
+};
+
+#endif //RT_MATERIAL_REFLECTIVE_H