summaryrefslogtreecommitdiff
path: root/hitlist.h
diff options
context:
space:
mode:
authorKeuin <[email protected]>2022-04-16 14:31:23 +0800
committerKeuin <[email protected]>2022-04-16 14:31:23 +0800
commit1c27339c33a9170a519da847d9f00f8ffd5f47b9 (patch)
tree878267c6bf9613863c76805d5a2efd265c28c34e /hitlist.h
parentbac87e9c4c61a69c5d315f331031d0745ee9d8d2 (diff)
Add macro LOG_TRACE for logging ray-trace process to stderr.
Diffstat (limited to 'hitlist.h')
-rw-r--r--hitlist.h30
1 files changed, 30 insertions, 0 deletions
diff --git a/hitlist.h b/hitlist.h
index 797644a..1ad040a 100644
--- a/hitlist.h
+++ b/hitlist.h
@@ -22,6 +22,15 @@
//#define T_NORM_VISUAL
#define T_DIFFUSE
+// log ray traces to stderr
+//#define LOG_TRACE
+
+#ifdef LOG_TRACE
+#define TRACELOG(...) (fprintf(stderr, __VA_ARGS__))
+#else
+#define TRACELOG(...)
+#endif
+
// A world, T is color depth
class hitlist {
std::vector<std::shared_ptr<object>> objects;
@@ -40,6 +49,9 @@ public:
template<typename T>
pixel<T> color(ray3d r, random_uv_gen_3d &ruvg, uint_fast32_t max_recursion_depth = 64) const {
assert(r.decay().is_one());
+ TRACELOG("+++ start tracing (limit=%zu)\n", max_recursion_depth);
+ TRACELOG(" ray: [%10f,%10f,%10f], decay=[%10f,%10f,%10f]\n",
+ r.direction().x, r.direction().y, r.direction().z, r.decay().x, r.decay().y, r.decay().z);
while (max_recursion_depth-- > 0) {
// Detect hits
bool hit = false;
@@ -62,6 +74,13 @@ public:
}
}
if (hit) {
+#ifdef LOG_TRACE
+ const auto _hit_p_ = r.at(hit_t);
+ const auto _rn_ = dot(r.direction(), hit_obj->normal_vector(_hit_p_));
+ TRACELOG(" hit object <%p> at [%10f,%10f,%10f], t=%10f, surface=%10f (%s)\n",
+ hit_obj.get(), _hit_p_.x, _hit_p_.y, _hit_p_.z,
+ hit_t, _rn_, (_rn_ < 0) ? "outside" : "inside");
+#endif
#ifdef T_SIMPLE_COLOR
// simply returns color of the object
return hit_obj->color();
@@ -75,8 +94,12 @@ public:
#ifdef T_DIFFUSE
const auto &materi = hit_obj->material();
if (materi.scatter(r, *hit_obj, hit_t, ruvg)) {
+ TRACELOG(" scattered: [%10f,%10f,%10f], decay=[%10f,%10f,%10f]\n",
+ r.direction().x, r.direction().y, r.direction().z,
+ r.decay().x, r.decay().y, r.decay().z);
continue; // The ray is scatted by an object. Continue processing the scattered ray.
} else {
+ TRACELOG("--- finish (absorbed by object <%p>)\n", hit_obj.get());
return pixel<T>::black(); // The ray is absorbed by an object completely. Return black.
}
#endif
@@ -91,11 +114,18 @@ public:
u
);
#ifdef T_DIFFUSE
+#ifdef LOG_TRACE
+ const auto co = pixel8b::from(r.hit(c));
+ TRACELOG(" result: [%d, %d, %d]\n", co.r, co.g, co.b);
+ TRACELOG("--- finish (reached infinity)\n");
+#endif
return r.hit(c);
#else
+ TRACELOG("--- finish (hit)\n");
return c;
#endif
}
+ TRACELOG("--- finish (max search depth)\n");
return pixel<T>::black(); // reached recursion time limit, very little light
}
};