summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test_vec.cpp13
-rw-r--r--vec.h33
2 files changed, 0 insertions, 46 deletions
diff --git a/test_vec.cpp b/test_vec.cpp
index a81ee09..537e556 100644
--- a/test_vec.cpp
+++ b/test_vec.cpp
@@ -106,19 +106,6 @@ TEST(Vec, Reflect) {
ASSERT_EQ(v, n.reflect(u));
}
-TEST(Vec, Refract) {
- vec3d n{1, 0, 0}, u{-1, 0, -1}, v{-sqrt(14), 0, -sqrt(2)};
- ASSERT_EQ(u.unit_vec(), n.refract<true>(u.unit_vec(), 1).unit_vec());
- ASSERT_EQ(u.unit_vec(), n.refract<false>(u.unit_vec(), 1).unit_vec());
- ASSERT_EQ(v.unit_vec(), n.refract<true>(u.unit_vec(), 0.5).unit_vec());
- ASSERT_EQ(v.unit_vec(), n.refract<false>(u.unit_vec(), 0.5).unit_vec());
-}
-
-TEST(Vec, Refract_TIR) {
- vec3d n{1, 0, 0}, u{-1, 0, -sqrt(3)}, v{1, 0, -sqrt(3)};
- ASSERT_EQ(v.unit_vec(), n.refract<true>(u.unit_vec(), 2));
-}
-
TEST(Vec, VecParallel) {
vec3d a{1, 1, 2}, b{1.1, 1.1, 2.2}, c{0,0,0}, d{1, 2, 1};
ASSERT_TRUE(a.parallel(b));
diff --git a/vec.h b/vec.h
index c109f7c..13e87b5 100644
--- a/vec.h
+++ b/vec.h
@@ -10,7 +10,6 @@
#include <ostream>
#include <cassert>
#include <algorithm>
-#include "tracelog.h"
static inline bool eq(int a, int b) {
return a == b;
@@ -123,38 +122,6 @@ struct vec3 {
assert(fabs(mod2() - 1.0) < 1e-8);
return v - (2.0 * dot(v)) * (*this);
}
-
- // Get the refracted vector. Current vector is the normal vector (length should be 1),
- // r1 is the incoming vector, ri_inv is the relative refraction index n2/n1,
- // where n2 is the destination media's refraction index, and n1 is the source media's refraction index.
- // TIR (Total Internal Reflection) is optionally enabled by macro TIR_OR and TIR_OFF.
- // If TIR happens, the ray will be reflected.
- template<bool Enable_TIR>
- vec3 refract(const vec3 &r1, double ri_inv) const {
- assert(fabs(mod2() - 1.0) < 1e-7);
- assert(fabs(r1.mod2() - 1.0) < 1e-7);
- assert(ri_inv > 0);
- assert(dot(r1) < 0); // normal vector must be on the same side
- const auto &n = *this; // normal vector
- const auto m_cos1 = std::max(dot(r1), (T) (-1)); // cos(a1), a1 is the incoming angle
-// assert(m_cos1 <= 0); // incoming angle must smaller than 90deg
- const auto c = ri_inv; // c = nx * r`x + ny * r`y
- auto d = 1 - c * c * (1 - m_cos1 * m_cos1);
- if (d < 0) {
- // TODO test TIR
- if (Enable_TIR) {
- // ri_inv < sin(a1), cannot refract, must reflect (Total Internal Reflection)
- TRACELOG(" reflect (TIR, d=%f)\n", d);
- return reflect(r1);
- } else {
- TRACELOG(" refract (forced, d=%f)\n", d);
- d = -d; // abs, just make the sqrt has a real solution
- }
- }
- const auto n2 = (r1 - dot(r1) * n) * c - sqrt(d) * n;
- assert(n2.valid());
- return n2;
- }
};
// print to ostream