changed initial t0/t1
This commit is contained in:
parent
2983d06bea
commit
bab7493071
1 changed files with 9 additions and 4 deletions
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue