diff --git a/Step 3/cmake-build-release/.ninja_deps b/Step 3/cmake-build-release/.ninja_deps index 3a58d69..90eb52b 100644 Binary files a/Step 3/cmake-build-release/.ninja_deps and b/Step 3/cmake-build-release/.ninja_deps differ diff --git a/Step 3/cmake-build-release/.ninja_log b/Step 3/cmake-build-release/.ninja_log index c81c9a5..31c9562 100644 --- a/Step 3/cmake-build-release/.ninja_log +++ b/Step 3/cmake-build-release/.ninja_log @@ -2,82 +2,53 @@ 374 3235 1668323538168825062 CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_tables.cpp.o f6dab204e07e8dcf 2 2022 1668323499583713805 CMakeFiles/Step_3.dir/src/graphics/gl/gl.c.o 30ab06816e8637c1 4 3390 1668323512856096078 CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_demo.cpp.o 7798aba97da63e31 -13 1984 1668489872732758544 CMakeFiles/Step_3.dir/src/engine/world.cpp.o 6470df278966c4 +1 2068 1668528621778322458 CMakeFiles/Step_3.dir/src/engine/world.cpp.o 6470df278966c4 2 1641 1668366223598629532 CMakeFiles/Step_3.dir/src/engine/util/debug.cpp.o d86a254d2bce8f74 1 6863 1668489146695541389 CMakeFiles/Step_3.dir/src/engine/image/image.cpp.o 1c68ba16e6b4d09b 2 1301 1668366223258619732 CMakeFiles/Step_3.dir/src/graphics/debug_gui.cpp.o 9493619f74acd06a 4 605 1668323535536749264 CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_impl_x11.cpp.o d1e9a2fcb31e2ec8 0 26 1668358519550031316 build.ninja ccb5de0c063412ab -1 1034 1668489140867427595 CMakeFiles/Step_3.dir/src/engine/globals.cpp.o 4ef77d2224f86511 -1 1244 1668489141075431646 CMakeFiles/Step_3.dir/src/engine/math/colliders.cpp.o 39e9f435096d066b -2 1373 1668489872120742440 CMakeFiles/Step_3.dir/src/engine/util/models.cpp.o 164394d360c43072 +1 1305 1668528538563906174 CMakeFiles/Step_3.dir/src/engine/globals.cpp.o 4ef77d2224f86511 +1 1167 1668528538427902233 CMakeFiles/Step_3.dir/src/engine/math/colliders.cpp.o 39e9f435096d066b +1 1600 1668528621314308958 CMakeFiles/Step_3.dir/src/engine/util/models.cpp.o 164394d360c43072 3 6633 1668323516100189511 CMakeFiles/Step_3.dir/src/graphics/imgui/imgui.cpp.o 55e7538fd27b47be -2275 2350 1668489873096768119 Step_3 f055ce2b85635598 +2778 2864 1668528622574345618 Step_3 f055ce2b85635598 4 521 1668323535452746847 CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_impl_glfw.cpp.o 6aef9db88eb3d76d -2 1850 1668489872596754964 CMakeFiles/Step_3.dir/src/engine/raytracing.cpp.o 11f0e227e9fda9ca +1 2214 1668528621918326531 CMakeFiles/Step_3.dir/src/engine/raytracing.cpp.o 11f0e227e9fda9ca 1 827 1668366742693637470 CMakeFiles/Step_3.dir/src/graphics/input.cpp.o 510001b0955ab019 5 4715 1668323514180134213 CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_draw.cpp.o f89fa3d7b779872a +1 1903 1668528621614317686 CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o ce988de97a5cb51d 521 6249 1668323541180911801 CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_widgets.cpp.o 84017388bc7af144 -13 1419 1668489872168743705 CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o ce988de97a5cb51d -2 1717 1668489141551440921 CMakeFiles/Step_3.dir/src/graphics/gl/gl.cpp.o 330ad35a6abf06c3 +2 1520 1668528538779912434 CMakeFiles/Step_3.dir/src/graphics/gl/gl.cpp.o 330ad35a6abf06c3 4 374 1668323535308742700 CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_impl_opengl3.cpp.o 1b5f0fbe3cf8ce4e 2 1655 1668489141487439674 CMakeFiles/Step_3.dir/src/graphics/gl/shader.cpp.o 2553d57dba16057b -1 2275 1668489873024766225 CMakeFiles/Step_3.dir/src/engine/main.cpp.o 641dce3f86933e2e +1 2778 1668528622490343174 CMakeFiles/Step_3.dir/src/engine/main.cpp.o 641dce3f86933e2e 2 2095 1668366224050642556 CMakeFiles/Step_3.dir/src/engine/util/parser.cpp.o 1007c86c207ac940 -2 1303 1668489957751009761 CMakeFiles/Step_3.dir/src/engine/util/models.cpp.o 164394d360c43072 -2 1330 1668489957775010400 CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o ce988de97a5cb51d -2 1652 1668489958099019032 CMakeFiles/Step_3.dir/src/engine/world.cpp.o 6470df278966c4 -2 1717 1668489958163020738 CMakeFiles/Step_3.dir/src/engine/raytracing.cpp.o 11f0e227e9fda9ca -1 2233 1668489958679034483 CMakeFiles/Step_3.dir/src/engine/main.cpp.o 641dce3f86933e2e -2233 2297 1668489958743036189 Step_3 f055ce2b85635598 -1 1328 1668490081042319128 CMakeFiles/Step_3.dir/src/engine/util/models.cpp.o 164394d360c43072 -1 1374 1668490081086320317 CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o ce988de97a5cb51d -1 1640 1668490081354327561 CMakeFiles/Step_3.dir/src/engine/world.cpp.o 6470df278966c4 -1 1726 1668490081438329831 CMakeFiles/Step_3.dir/src/engine/raytracing.cpp.o 11f0e227e9fda9ca -1 2239 1668490081950343672 CMakeFiles/Step_3.dir/src/engine/main.cpp.o 641dce3f86933e2e -2239 2302 1668490082014345402 Step_3 f055ce2b85635598 -2 1256 1668491007091920404 CMakeFiles/Step_3.dir/src/engine/util/models.cpp.o 164394d360c43072 -2 1303 1668491007139921206 CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o ce988de97a5cb51d -2 1588 1668491007423925947 CMakeFiles/Step_3.dir/src/engine/world.cpp.o 6470df278966c4 -2 1684 1668491007519927550 CMakeFiles/Step_3.dir/src/engine/raytracing.cpp.o 11f0e227e9fda9ca -1 2245 1668491008079936900 CMakeFiles/Step_3.dir/src/engine/main.cpp.o 641dce3f86933e2e -2245 2308 1668491008143937971 Step_3 f055ce2b85635598 -1 1258 1668491031264329637 CMakeFiles/Step_3.dir/src/engine/util/models.cpp.o 164394d360c43072 -1 1307 1668491031312330460 CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o ce988de97a5cb51d -1 1588 1668491031592335269 CMakeFiles/Step_3.dir/src/engine/world.cpp.o 6470df278966c4 -1 1666 1668491031672336643 CMakeFiles/Step_3.dir/src/engine/raytracing.cpp.o 11f0e227e9fda9ca -1 2226 1668491032232346264 CMakeFiles/Step_3.dir/src/engine/main.cpp.o 641dce3f86933e2e -2226 2286 1668491032292347296 Step_3 f055ce2b85635598 -1 1248 1668491266864840576 CMakeFiles/Step_3.dir/src/engine/util/models.cpp.o 164394d360c43072 -1 1301 1668491266920841745 CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o ce988de97a5cb51d -1 1581 1668491267200847580 CMakeFiles/Step_3.dir/src/engine/world.cpp.o 6470df278966c4 -1 1660 1668491267276849164 CMakeFiles/Step_3.dir/src/engine/raytracing.cpp.o 11f0e227e9fda9ca -1 2223 1668491267840860925 CMakeFiles/Step_3.dir/src/engine/main.cpp.o 641dce3f86933e2e -2223 2284 1668491267900862176 Step_3 f055ce2b85635598 -2 1275 1668491276045032437 CMakeFiles/Step_3.dir/src/engine/util/models.cpp.o 164394d360c43072 -2 1285 1668491276057032688 CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o ce988de97a5cb51d -2 1604 1668491276373039313 CMakeFiles/Step_3.dir/src/engine/world.cpp.o 6470df278966c4 -1 1655 1668491276425040402 CMakeFiles/Step_3.dir/src/engine/raytracing.cpp.o 11f0e227e9fda9ca -1 2261 1668491277033053146 CMakeFiles/Step_3.dir/src/engine/main.cpp.o 641dce3f86933e2e -2261 2322 1668491277093054405 Step_3 f055ce2b85635598 -2 1357 1668491283805195413 CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o ce988de97a5cb51d -1 1532 1668491283981199118 CMakeFiles/Step_3.dir/src/engine/util/models.cpp.o 164394d360c43072 -2 1651 1668491284097201557 CMakeFiles/Step_3.dir/src/engine/world.cpp.o 6470df278966c4 -1 1723 1668491284169203075 CMakeFiles/Step_3.dir/src/engine/raytracing.cpp.o 11f0e227e9fda9ca -1 2530 1668491284977220089 CMakeFiles/Step_3.dir/src/engine/main.cpp.o 641dce3f86933e2e -2531 2593 1668491285041221437 Step_3 f055ce2b85635598 -1 1314 1668491300465547709 CMakeFiles/Step_3.dir/src/engine/util/models.cpp.o 164394d360c43072 -1 1439 1668491300589550343 CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o ce988de97a5cb51d -1 1634 1668491300785554506 CMakeFiles/Step_3.dir/src/engine/world.cpp.o 6470df278966c4 -1 1684 1668491300837555611 CMakeFiles/Step_3.dir/src/engine/raytracing.cpp.o 11f0e227e9fda9ca -1 2282 1668491301433568277 CMakeFiles/Step_3.dir/src/engine/main.cpp.o 641dce3f86933e2e -2282 2342 1668491301493569552 Step_3 f055ce2b85635598 -1 945 1668491473161369910 CMakeFiles/Step_3.dir/src/engine/globals.cpp.o 4ef77d2224f86511 -2 1141 1668491473361374498 CMakeFiles/Step_3.dir/src/graphics/gl/gl.cpp.o 330ad35a6abf06c3 -1 1161 1668491473377374863 CMakeFiles/Step_3.dir/src/engine/math/colliders.cpp.o 39e9f435096d066b -2 1346 1668491473565379176 CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o ce988de97a5cb51d -2 1656 1668491473873386239 CMakeFiles/Step_3.dir/src/engine/world.cpp.o 6470df278966c4 -2 1688 1668491473905386973 CMakeFiles/Step_3.dir/src/engine/util/models.cpp.o 164394d360c43072 -1 1730 1668491473949387979 CMakeFiles/Step_3.dir/src/engine/raytracing.cpp.o 11f0e227e9fda9ca -1 2359 1668491474577402387 CMakeFiles/Step_3.dir/src/engine/main.cpp.o 641dce3f86933e2e -2359 2426 1668491474641403855 Step_3 f055ce2b85635598 +1 1359 1668528665647599927 CMakeFiles/Step_3.dir/src/engine/util/models.cpp.o 164394d360c43072 +1 1399 1668528665687601092 CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o ce988de97a5cb51d +1 1729 1668528666019610769 CMakeFiles/Step_3.dir/src/engine/world.cpp.o 6470df278966c4 +1 1774 1668528666063612051 CMakeFiles/Step_3.dir/src/engine/raytracing.cpp.o 11f0e227e9fda9ca +1 2562 1668528666851635019 CMakeFiles/Step_3.dir/src/engine/main.cpp.o 641dce3f86933e2e +2563 2637 1668528666923637119 Step_3 f055ce2b85635598 +2 981 1668530133106059603 CMakeFiles/Step_3.dir/src/engine/math/colliders.cpp.o 39e9f435096d066b +1 1161 1668530133286064346 CMakeFiles/Step_3.dir/src/engine/globals.cpp.o 4ef77d2224f86511 +2 1264 1668530133390067087 CMakeFiles/Step_3.dir/src/graphics/gl/gl.cpp.o 330ad35a6abf06c3 +2 1460 1668530133582072147 CMakeFiles/Step_3.dir/src/engine/util/models.cpp.o 164394d360c43072 +2 1814 1668530133938081528 CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o ce988de97a5cb51d +2 1997 1668530134122086379 CMakeFiles/Step_3.dir/src/engine/raytracing.cpp.o 11f0e227e9fda9ca +2 2244 1668530134366092808 CMakeFiles/Step_3.dir/src/engine/world.cpp.o 6470df278966c4 +2 2479 1668530134602099030 CMakeFiles/Step_3.dir/src/engine/main.cpp.o 641dce3f86933e2e +2479 2544 1668530134666100715 Step_3 f055ce2b85635598 +2 868 1668530626127552949 CMakeFiles/Step_3.dir/src/engine/math/colliders.cpp.o 39e9f435096d066b +2 1000 1668530626263556771 CMakeFiles/Step_3.dir/src/engine/globals.cpp.o 4ef77d2224f86511 +2 1425 1668530626687568690 CMakeFiles/Step_3.dir/src/engine/util/models.cpp.o 164394d360c43072 +2 1461 1668530626723569702 CMakeFiles/Step_3.dir/src/graphics/gl/gl.cpp.o 330ad35a6abf06c3 +3 1490 1668530626751570490 CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o ce988de97a5cb51d +2 1793 1668530627055579036 CMakeFiles/Step_3.dir/src/engine/world.cpp.o 6470df278966c4 +2 1879 1668530627139581398 CMakeFiles/Step_3.dir/src/engine/raytracing.cpp.o 11f0e227e9fda9ca +2 2591 1668530627851601414 CMakeFiles/Step_3.dir/src/engine/main.cpp.o 641dce3f86933e2e +2591 2654 1668530627915603213 Step_3 f055ce2b85635598 +1 769 1668530642748020441 CMakeFiles/Step_3.dir/src/engine/math/colliders.cpp.o 39e9f435096d066b +769 834 1668530642812022239 Step_3 f055ce2b85635598 +1 813 1668530661440546885 CMakeFiles/Step_3.dir/src/engine/math/colliders.cpp.o 39e9f435096d066b +813 887 1668530661512548914 Step_3 f055ce2b85635598 diff --git a/Step 3/cmake-build-release/CMakeFiles/Step_3.dir/src/engine/math/colliders.cpp.o b/Step 3/cmake-build-release/CMakeFiles/Step_3.dir/src/engine/math/colliders.cpp.o index afda27f..81b68b4 100644 Binary files a/Step 3/cmake-build-release/CMakeFiles/Step_3.dir/src/engine/math/colliders.cpp.o and b/Step 3/cmake-build-release/CMakeFiles/Step_3.dir/src/engine/math/colliders.cpp.o differ diff --git a/Step 3/cmake-build-release/CMakeFiles/Step_3.dir/src/engine/world.cpp.o b/Step 3/cmake-build-release/CMakeFiles/Step_3.dir/src/engine/world.cpp.o index 11fbc3e..bc559e0 100644 Binary files a/Step 3/cmake-build-release/CMakeFiles/Step_3.dir/src/engine/world.cpp.o and b/Step 3/cmake-build-release/CMakeFiles/Step_3.dir/src/engine/world.cpp.o differ diff --git a/Step 3/cmake-build-release/Step_3 b/Step 3/cmake-build-release/Step_3 index 868cfd2..3605326 100755 Binary files a/Step 3/cmake-build-release/Step_3 and b/Step 3/cmake-build-release/Step_3 differ diff --git a/Step 3/cmake-build-release/Testing/Temporary/LastTest.log b/Step 3/cmake-build-release/Testing/Temporary/LastTest.log index 232babf..6cca44b 100644 --- a/Step 3/cmake-build-release/Testing/Temporary/LastTest.log +++ b/Step 3/cmake-build-release/Testing/Temporary/LastTest.log @@ -1,3 +1,3 @@ -Start testing: Nov 15 00:51 EST +Start testing: Nov 15 11:44 EST ---------------------------------------------------------- -End testing: Nov 15 00:51 EST +End testing: Nov 15 11:44 EST diff --git a/Step 3/include/engine/math/bvh.h b/Step 3/include/engine/math/bvh.h index 518c7b9..0165c6d 100644 --- a/Step 3/include/engine/math/bvh.h +++ b/Step 3/include/engine/math/bvh.h @@ -141,25 +141,41 @@ namespace Raytracing { return space; } - BVHNode* addObjectsRecur(const std::vector& objects, long prevSize) { - ilog << "size: " << objects.size() << " " << prevSize << "\n"; + static bool vectorEquals(const BVHPartitionedSpace& oldSpace, const BVHPartitionedSpace& newSpace){ + if (oldSpace.left.size() != newSpace.left.size() || oldSpace.right.size() != newSpace.right.size()) + return false; + for (int i = 0; i < oldSpace.left.size(); i++){ + if (oldSpace.left[i].aabb != newSpace.left[i].aabb) + return false; + } + for (int i = 0; i < oldSpace.right.size(); i++){ + if (oldSpace.right[i].aabb != newSpace.right[i].aabb) + return false; + } + return true; + } + + BVHNode* addObjectsRecur(const std::vector& objects, const BVHPartitionedSpace& prevSpace) { // create a volume for the entire world. - // yes, we could use the recursion provided AABB, - // but that wouldn't be minimum, only half. - // this ensures that we have a minimum AABB. + // yes, we could use a recursion provided AABB, but that wouldn't be minimum, only half. this ensures that we have a minimum AABB. AABB world; for (const auto& obj: objects) world = world.expand(obj.aabb); - // prevSize was required to solve some really weird bugs - // which are a TODO: - if ((objects.size() <= 1 && !objects.empty()) || prevSize == objects.size()) { + + // then split and partition the world + auto splitAABBs = world.splitByLongestAxis(); + auto partitionedObjs = partition(splitAABBs, objects); + if (vectorEquals(prevSpace, partitionedObjs)){ + splitAABBs = world.splitAlongAxis(); + partitionedObjs = partition(splitAABBs, objects); + } + + if ((objects.size() <= 1 && !objects.empty())) { return new BVHNode(objects, world, nullptr, nullptr); } else if (objects.empty()) // should never reach here!! return nullptr; - // then split and partition the world - auto splitAABBs = world.splitByLongestAxis(); - auto partitionedObjs = partition(splitAABBs, objects); + elog << partitionedObjs.left.size() << " :: " << partitionedObjs.right.size() << "\n"; @@ -167,9 +183,9 @@ namespace Raytracing { BVHNode* right = nullptr; // don't try to explore nodes which don't have anything in them. if (!partitionedObjs.left.empty()) - left = addObjectsRecur(partitionedObjs.left, (long) objects.size()); + left = addObjectsRecur(partitionedObjs.left, partitionedObjs); if (!partitionedObjs.right.empty()) - right = addObjectsRecur(partitionedObjs.right, (long) objects.size()); + right = addObjectsRecur(partitionedObjs.right, partitionedObjs); return new BVHNode(objects, world, left, right); } @@ -236,7 +252,7 @@ namespace Raytracing { bvhObject.ptr = obj; objs.push_back(bvhObject); } - root = addObjectsRecur(objs, 1); + root = addObjectsRecur(objs, {}); } std::vector rayIntersect(const Ray& ray, PRECISION_TYPE min, PRECISION_TYPE max) { diff --git a/Step 3/include/engine/math/colliders.h b/Step 3/include/engine/math/colliders.h index a24e724..e09731a 100644 --- a/Step 3/include/engine/math/colliders.h +++ b/Step 3/include/engine/math/colliders.h @@ -99,6 +99,7 @@ namespace Raytracing { [[nodiscard]] int longestAxis() const; [[nodiscard]] PRECISION_TYPE longestAxisLength() const; [[nodiscard]] std::pair splitByLongestAxis(); + [[nodiscard]] std::pair splitAlongAxis(); [[nodiscard]] PRECISION_TYPE avgDistanceFromCenter() const; @@ -121,6 +122,14 @@ namespace Raytracing { }; + + inline bool operator==(const AABB& a, const AABB& b){ + const auto& aMax = a.getMax(); + const auto& aMin = a.getMin(); + const auto& bMax = b.getMax(); + const auto& bMin = b.getMin(); + return aMax == bMax && aMin == bMin; + } inline std::ostream& operator<<(std::ostream& out, const AABB& v) { auto max = v.getMax(); diff --git a/Step 3/src/engine/math/colliders.cpp b/Step 3/src/engine/math/colliders.cpp index 243e930..925f160 100644 --- a/Step 3/src/engine/math/colliders.cpp +++ b/Step 3/src/engine/math/colliders.cpp @@ -115,4 +115,35 @@ namespace Raytracing { bool AABB::intersects(const Ray& ray, PRECISION_TYPE tmin, PRECISION_TYPE tmax) { return simpleSlabRayAABBMethod(ray, tmin, tmax); } + + // I want this function to be somewhat deterministic + // Yet if this is being called divide and conquer isn't working. + // so we need a way of splitting the AABB to get different results + // preventing the plague of infinite recursion. + + // this alternating of axis is like K-Trees? Pretty sure the algorithms book I read said to split in alternating order. + // Might have been for red-black trees. Either way we are going to take a page from that book. + int lastAxis = 2; + + std::pair AABB::splitAlongAxis() { + lastAxis %= 3; + lastAxis += 1; + // return the new split AABBs based on the calculated max lengths, but only in their respective axis. + if (lastAxis == 1){ + PRECISION_TYPE X = std::abs(max.x() - min.x()); + PRECISION_TYPE X2 = X/2; + // end the first at half the parent. + return {{min.x(), min.y(), min.z(), max.x()-X2, max.y(), max.z()}, + // start the second AABB at the end of the first AABB. + {min.x()+X2, min.y(), min.z(), max.x(), max.y(), max.z()}}; + } else if (lastAxis == 2) { + PRECISION_TYPE Y = std::abs(max.y() - min.y()); + PRECISION_TYPE Y2 = Y/2; + return {{min.x(), min.y(), min.z(), max.x(), max.y()-Y2, max.z()}, {min.x(), min.y()+Y2, min.z(), max.x(), max.y(), max.z()}}; + } else { + PRECISION_TYPE Z = std::abs(max.z() - min.z()); + PRECISION_TYPE Z2 = Z/2; + return {{min.x(), min.y(), min.z(), max.x(), max.y(), max.z()-Z2}, {min.x(), min.y(), min.z()+Z2, max.x(), max.y(), max.z()}}; + } + } } \ No newline at end of file