summaryrefslogtreecommitdiff
path: root/material_dielectric.cpp
diff options
context:
space:
mode:
authorKeuin <[email protected]>2022-04-16 14:31:38 +0800
committerKeuin <[email protected]>2022-04-16 14:31:38 +0800
commitb26a0168788a28c384d394b9e3bb4ebaebc815c2 (patch)
tree19d7d1532e66c0b6c1dc976b4f34022554c49b1c /material_dielectric.cpp
parent1c27339c33a9170a519da847d9f00f8ffd5f47b9 (diff)
Add dielectric material. (glass ball)
Diffstat (limited to 'material_dielectric.cpp')
-rw-r--r--material_dielectric.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/material_dielectric.cpp b/material_dielectric.cpp
new file mode 100644
index 0000000..3aaf259
--- /dev/null
+++ b/material_dielectric.cpp
@@ -0,0 +1,22 @@
+//
+// Created by Keuin on 2022/4/15.
+//
+
+#include "material_dielectric.h"
+
+bool material_dielectric::scatter(ray3d &r, const object &hit_obj, double hit_t, random_uv_gen_3d &ruvg) const {
+ const auto hit_p = r.at(hit_t);
+ assert(hit_obj.is_on(hit_p));
+ auto n = hit_obj.normal_vector(hit_p);
+ auto ri_ = ri_inv;
+ if (dot(r.direction(), n) > 0) {
+ // the ray is started from the object's inner,
+ // use normal vector and ri on the surface's inner side
+ n = -n;
+ ri_ = 1.0 / ri_;
+ }
+ const auto r2 = n.refract<true>(r.direction(), ri_); // refracted vector
+ r.direction(r2.unit_vec());
+ r.source(hit_p);
+ return true;
+}