From bab749307103b7cd7f0f2e9e63debb0a1c361c5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?arvid=20schr=C3=B6der?= Date: Thu, 8 Dec 2022 13:27:23 +0100 Subject: [PATCH] changed initial t0/t1 --- scene/fastscene.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/scene/fastscene.cpp b/scene/fastscene.cpp index a3fd2d5..76facd0 100644 --- a/scene/fastscene.cpp +++ b/scene/fastscene.cpp @@ -94,7 +94,12 @@ int FastScene::countNodeIntersections(const Ray &ray) const { } bool FastScene::findIntersection(Ray &ray) const { - return root->findIntersection(ray, 0, ray.length); + Vector3d distMin = (this->absoluteMinimum - ray.origin) / ray.direction; + Vector3d distMax = (this->absoluteMaximum - ray.origin) / ray.direction; + float t0 = std::min(distMin.x, std::min(distMin.y, distMin.z)); + float t1 = std::max(distMax.x, std::max(distMax.y, distMax.z)); + if (t0 > t1) std::swap(t0, t1); + return root->findIntersection(ray, t0, t1); } bool FastScene::findOcclusion(Ray &ray) const { @@ -109,7 +114,7 @@ void FastScene::buildTree(int maximumDepth, int minimumNumberOfPrimitives) { // Determine the bounding box of the kD-Tree - Vector3d maximumBounds = { + this->absoluteMaximum = { std::max_element(this->primitives().begin(), this->primitives().end(), [](const auto &prim1, const auto &prim2) { @@ -126,7 +131,7 @@ void FastScene::buildTree(int maximumDepth, int minimumNumberOfPrimitives) { return prim1->maximumBounds(2) < prim2->maximumBounds(2); })->get()->maximumBounds(2) }; - Vector3d minimumBounds = { + this->absoluteMinimum = { std::min_element(this->primitives().begin(), this->primitives().end(), [](const auto &prim1, const auto &prim2) { @@ -143,7 +148,7 @@ void FastScene::buildTree(int maximumDepth, int minimumNumberOfPrimitives) { return prim1->minimumBounds(2) < prim2->minimumBounds(2); })->get()->minimumBounds(2) }; - this->root = build(minimumBounds, maximumBounds, this->primitives(), 0); + this->root = build(this->absoluteMinimum, this->absoluteMaximum, this->primitives(), 0); // Recursively build the kD-Tree }