diff --git a/Step 3/cmake-build-release/.ninja_deps b/Step 3/cmake-build-release/.ninja_deps index 7934a5d..b1052ed 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 b075c7e..f3e3f6b 100644 --- a/Step 3/cmake-build-release/.ninja_log +++ b/Step 3/cmake-build-release/.ninja_log @@ -2,104 +2,25 @@ 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 -2 1840 1668361409895046083 CMakeFiles/Step_3.dir/src/engine/world.cpp.o 6470df278966c4 -1 1716 1668360835926339635 CMakeFiles/Step_3.dir/src/engine/util/debug.cpp.o d86a254d2bce8f74 -1 7565 1668362431984323343 CMakeFiles/Step_3.dir/src/engine/image/image.cpp.o 1c68ba16e6b4d09b -2 1499 1668360835706333174 CMakeFiles/Step_3.dir/src/graphics/debug_gui.cpp.o 9493619f74acd06a +2 1773 1668466039063176140 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 7895 1668377853507218742 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 1621 1668360835826336698 CMakeFiles/Step_3.dir/src/engine/globals.cpp.o 4ef77d2224f86511 -1 1405 1668362425824144748 CMakeFiles/Step_3.dir/src/engine/math/colliders.cpp.o 39e9f435096d066b -2 1712 1668362494026122707 CMakeFiles/Step_3.dir/src/engine/util/models.cpp.o 164394d360c43072 +1 1129 1668448492108683969 CMakeFiles/Step_3.dir/src/engine/globals.cpp.o 4ef77d2224f86511 +1 996 1668448491972679960 CMakeFiles/Step_3.dir/src/engine/math/colliders.cpp.o 39e9f435096d066b +1 1294 1668465885880220128 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 -2268 2354 1668361410407060406 Step_3 f055ce2b85635598 +1930 1998 1668466411374360550 Step_3 f055ce2b85635598 4 521 1668323535452746847 CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_impl_glfw.cpp.o 6aef9db88eb3d76d -2 2015 1668362494330131524 CMakeFiles/Step_3.dir/src/engine/raytracing.cpp.o 11f0e227e9fda9ca -1499 2524 1668360836734363373 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 -521 6249 1668323541180911801 CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_widgets.cpp.o 84017388bc7af144 -2 1830 1668362494146126186 CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o ce988de97a5cb51d -2 1624 1668362426044151124 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 1617 1668362426036150892 CMakeFiles/Step_3.dir/src/graphics/gl/shader.cpp.o 2553d57dba16057b -1 2419 1668362494734143245 CMakeFiles/Step_3.dir/src/engine/main.cpp.o 641dce3f86933e2e -2 2242 1668360836450355031 CMakeFiles/Step_3.dir/src/engine/util/parser.cpp.o 1007c86c207ac940 -2 1579 1668362569316307713 CMakeFiles/Step_3.dir/src/engine/world.cpp.o 6470df278966c4 -1579 1704 1668362569440311315 Step_3 f055ce2b85635598 -1 1319 1668362704700239985 CMakeFiles/Step_3.dir/src/engine/util/models.cpp.o 164394d360c43072 -2 1568 1668362704948247191 CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o ce988de97a5cb51d -2 1667 1668362705048250097 CMakeFiles/Step_3.dir/src/engine/world.cpp.o 6470df278966c4 -1 1710 1668362705092251375 CMakeFiles/Step_3.dir/src/engine/raytracing.cpp.o 11f0e227e9fda9ca -1 2005 1668362705384259861 CMakeFiles/Step_3.dir/src/engine/main.cpp.o 641dce3f86933e2e -2005 2097 1668362705476262536 Step_3 f055ce2b85635598 -2 1272 1668363213055029566 CMakeFiles/Step_3.dir/src/engine/globals.cpp.o 4ef77d2224f86511 -2 1432 1668363213215034227 CMakeFiles/Step_3.dir/src/engine/util/debug.cpp.o d86a254d2bce8f74 -2 1683 1668363213467041565 CMakeFiles/Step_3.dir/src/engine/util/models.cpp.o 164394d360c43072 -3 1733 1668363213515042961 CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o ce988de97a5cb51d -3 1931 1668363213715048785 CMakeFiles/Step_3.dir/src/engine/world.cpp.o 6470df278966c4 -2 1954 1668363213739049483 CMakeFiles/Step_3.dir/src/engine/raytracing.cpp.o 11f0e227e9fda9ca -2 2289 1668363214071059151 CMakeFiles/Step_3.dir/src/engine/main.cpp.o 641dce3f86933e2e -2289 2410 1668363214191062645 Step_3 f055ce2b85635598 -1 1208 1668364152310674596 CMakeFiles/Step_3.dir/src/engine/math/colliders.cpp.o 39e9f435096d066b -1 1510 1668364152614683513 CMakeFiles/Step_3.dir/src/graphics/gl/gl.cpp.o 330ad35a6abf06c3 -2 1564 1668364152666685039 CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o ce988de97a5cb51d -1 1385 1668364289054683772 CMakeFiles/Step_3.dir/src/engine/util/models.cpp.o 164394d360c43072 -2 1530 1668364289202688109 CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o ce988de97a5cb51d -2 1813 1668364289482696315 CMakeFiles/Step_3.dir/src/engine/world.cpp.o 6470df278966c4 -1 1987 1668364289658701473 CMakeFiles/Step_3.dir/src/engine/raytracing.cpp.o 11f0e227e9fda9ca -1 2206 1668364289878707920 CMakeFiles/Step_3.dir/src/engine/main.cpp.o 641dce3f86933e2e -2206 2315 1668364289982710970 Step_3 f055ce2b85635598 -2 1944 1668365722348270196 CMakeFiles/Step_3.dir/src/engine/main.cpp.o 641dce3f86933e2e -1944 2035 1668365722436272698 Step_3 f055ce2b85635598 -1 1300 1668366223258619732 CMakeFiles/Step_3.dir/src/engine/math/colliders.cpp.o 39e9f435096d066b -2 1301 1668366223258619732 CMakeFiles/Step_3.dir/src/graphics/debug_gui.cpp.o 9493619f74acd06a -1 1382 1668366223338622038 CMakeFiles/Step_3.dir/src/engine/globals.cpp.o 4ef77d2224f86511 -2 1641 1668366223598629532 CMakeFiles/Step_3.dir/src/engine/util/debug.cpp.o d86a254d2bce8f74 -2 1660 1668366223618630108 CMakeFiles/Step_3.dir/src/graphics/gl/gl.cpp.o 330ad35a6abf06c3 -2 1744 1668366223702632529 CMakeFiles/Step_3.dir/src/graphics/gl/shader.cpp.o 2553d57dba16057b -2 1909 1668366223866637256 CMakeFiles/Step_3.dir/src/engine/util/models.cpp.o 164394d360c43072 -2 2095 1668366224050642556 CMakeFiles/Step_3.dir/src/engine/util/parser.cpp.o 1007c86c207ac940 -1301 2392 1668366224350651205 CMakeFiles/Step_3.dir/src/graphics/input.cpp.o 510001b0955ab019 -2 2453 1668366224410652933 CMakeFiles/Step_3.dir/src/engine/raytracing.cpp.o 11f0e227e9fda9ca -2 2479 1668366224434653626 CMakeFiles/Step_3.dir/src/engine/world.cpp.o 6470df278966c4 -1 2602 1668366224558657200 CMakeFiles/Step_3.dir/src/engine/main.cpp.o 641dce3f86933e2e -1300 2954 1668366224910667345 CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o ce988de97a5cb51d -1 7659 1668366229618803041 CMakeFiles/Step_3.dir/src/engine/image/image.cpp.o 1c68ba16e6b4d09b -7659 7729 1668366229686805000 Step_3 f055ce2b85635598 -3 1994 1668366292612619600 CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o ce988de97a5cb51d -2 1994 1668366292624619946 CMakeFiles/Step_3.dir/src/engine/util/models.cpp.o 164394d360c43072 -2 1994 1668366292612619600 CMakeFiles/Step_3.dir/src/graphics/gl/gl.cpp.o 330ad35a6abf06c3 -2 2406 1668366293180635989 CMakeFiles/Step_3.dir/src/engine/world.cpp.o 6470df278966c4 -2 2527 1668366293300639450 CMakeFiles/Step_3.dir/src/engine/raytracing.cpp.o 11f0e227e9fda9ca -1 2658 1668366293432643257 CMakeFiles/Step_3.dir/src/engine/main.cpp.o 641dce3f86933e2e -2658 2744 1668366293516645683 Step_3 f055ce2b85635598 -1 1246 1668366327169616852 CMakeFiles/Step_3.dir/src/graphics/gl/gl.cpp.o 330ad35a6abf06c3 -1 1400 1668366327325621356 CMakeFiles/Step_3.dir/src/engine/util/models.cpp.o 164394d360c43072 -2 1457 1668366327381622973 CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o ce988de97a5cb51d -1 2170 1668366328093643522 CMakeFiles/Step_3.dir/src/engine/main.cpp.o 641dce3f86933e2e -1 2192 1668366328117644217 CMakeFiles/Step_3.dir/src/engine/world.cpp.o 6470df278966c4 -1 2211 1668366328133644679 CMakeFiles/Step_3.dir/src/engine/raytracing.cpp.o 11f0e227e9fda9ca -2211 2280 1668366328201646641 Step_3 f055ce2b85635598 -2 1393 1668366431552631890 CMakeFiles/Step_3.dir/src/graphics/gl/gl.cpp.o 330ad35a6abf06c3 -2 1607 1668366431768638134 CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o ce988de97a5cb51d -2 1645 1668366431808639289 CMakeFiles/Step_3.dir/src/engine/util/models.cpp.o 164394d360c43072 -2 1992 1668366432152649232 CMakeFiles/Step_3.dir/src/engine/world.cpp.o 6470df278966c4 -2 2096 1668366432256652239 CMakeFiles/Step_3.dir/src/engine/raytracing.cpp.o 11f0e227e9fda9ca -1 2208 1668366432368655476 CMakeFiles/Step_3.dir/src/engine/main.cpp.o 641dce3f86933e2e -2208 2278 1668366432440657557 Step_3 f055ce2b85635598 -1 1579 1668366543867879961 CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o ce988de97a5cb51d -1580 1655 1668366543943882158 Step_3 f055ce2b85635598 -2 1394 1668366561612393436 CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o ce988de97a5cb51d -1394 1480 1668366561696395867 Step_3 f055ce2b85635598 -1 811 1668366640958690420 CMakeFiles/Step_3.dir/src/graphics/input.cpp.o 510001b0955ab019 -1 1412 1668366641558707792 CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o ce988de97a5cb51d -1 1963 1668366642110723778 CMakeFiles/Step_3.dir/src/engine/main.cpp.o 641dce3f86933e2e -1963 2035 1668366642178725749 Step_3 f055ce2b85635598 -1 820 1668366663439341462 CMakeFiles/Step_3.dir/src/graphics/input.cpp.o 510001b0955ab019 -1 1408 1668366664027358491 CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o ce988de97a5cb51d -1 2072 1668366664691377723 CMakeFiles/Step_3.dir/src/engine/main.cpp.o 641dce3f86933e2e -2072 2145 1668366664763379807 Step_3 f055ce2b85635598 +1 1719 1668466319832594099 CMakeFiles/Step_3.dir/src/engine/raytracing.cpp.o 11f0e227e9fda9ca 1 827 1668366742693637470 CMakeFiles/Step_3.dir/src/graphics/input.cpp.o 510001b0955ab019 -1 1424 1668366743293654856 CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o ce988de97a5cb51d -1 1979 1668366743849670968 CMakeFiles/Step_3.dir/src/engine/main.cpp.o 641dce3f86933e2e -1979 2054 1668366743921673055 Step_3 f055ce2b85635598 +5 4715 1668323514180134213 CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_draw.cpp.o f89fa3d7b779872a +2 1366 1668466038659168342 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 +2 1340 1668448492316690097 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 1790 1668377847399042915 CMakeFiles/Step_3.dir/src/graphics/gl/shader.cpp.o 2553d57dba16057b +1 1930 1668466411306359238 CMakeFiles/Step_3.dir/src/engine/main.cpp.o 641dce3f86933e2e +2 2095 1668366224050642556 CMakeFiles/Step_3.dir/src/engine/util/parser.cpp.o 1007c86c207ac940 diff --git a/Step 3/cmake-build-release/CMakeFiles/Step_3.dir/src/engine/globals.cpp.o b/Step 3/cmake-build-release/CMakeFiles/Step_3.dir/src/engine/globals.cpp.o index 229a532..2479ec5 100644 Binary files a/Step 3/cmake-build-release/CMakeFiles/Step_3.dir/src/engine/globals.cpp.o and b/Step 3/cmake-build-release/CMakeFiles/Step_3.dir/src/engine/globals.cpp.o differ diff --git a/Step 3/cmake-build-release/CMakeFiles/Step_3.dir/src/engine/main.cpp.o b/Step 3/cmake-build-release/CMakeFiles/Step_3.dir/src/engine/main.cpp.o index 227cf7d..9f52323 100644 Binary files a/Step 3/cmake-build-release/CMakeFiles/Step_3.dir/src/engine/main.cpp.o and b/Step 3/cmake-build-release/CMakeFiles/Step_3.dir/src/engine/main.cpp.o differ 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 eef0ca7..0828c77 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/raytracing.cpp.o b/Step 3/cmake-build-release/CMakeFiles/Step_3.dir/src/engine/raytracing.cpp.o index 9e57d29..0848ff6 100644 Binary files a/Step 3/cmake-build-release/CMakeFiles/Step_3.dir/src/engine/raytracing.cpp.o and b/Step 3/cmake-build-release/CMakeFiles/Step_3.dir/src/engine/raytracing.cpp.o differ diff --git a/Step 3/cmake-build-release/CMakeFiles/Step_3.dir/src/engine/util/models.cpp.o b/Step 3/cmake-build-release/CMakeFiles/Step_3.dir/src/engine/util/models.cpp.o index 02d1e8c..9895aa0 100644 Binary files a/Step 3/cmake-build-release/CMakeFiles/Step_3.dir/src/engine/util/models.cpp.o and b/Step 3/cmake-build-release/CMakeFiles/Step_3.dir/src/engine/util/models.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 210150d..d154515 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/CMakeFiles/Step_3.dir/src/graphics/gl/gl.cpp.o b/Step 3/cmake-build-release/CMakeFiles/Step_3.dir/src/graphics/gl/gl.cpp.o index 4f78ef9..fbcd523 100644 Binary files a/Step 3/cmake-build-release/CMakeFiles/Step_3.dir/src/graphics/gl/gl.cpp.o and b/Step 3/cmake-build-release/CMakeFiles/Step_3.dir/src/graphics/gl/gl.cpp.o differ diff --git a/Step 3/cmake-build-release/CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o b/Step 3/cmake-build-release/CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o index 0c996a3..137d5db 100644 Binary files a/Step 3/cmake-build-release/CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o and b/Step 3/cmake-build-release/CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o differ diff --git a/Step 3/cmake-build-release/Step_3 b/Step 3/cmake-build-release/Step_3 index 6599667..cc344ab 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 cb241fe..1a0421d 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 13 14:12 EST +Start testing: Nov 14 20:44 EST ---------------------------------------------------------- -End testing: Nov 13 14:12 EST +End testing: Nov 14 20:44 EST diff --git a/Step 3/cmake-build-release/imgui.ini b/Step 3/cmake-build-release/imgui.ini index 98ef4b3..70a9483 100644 --- a/Step 3/cmake-build-release/imgui.ini +++ b/Step 3/cmake-build-release/imgui.ini @@ -4,12 +4,86 @@ Size=400,400 Collapsed=0 [Window][Dear ImGui Demo] -Pos=650,20 +Pos=649,26 Size=550,680 Collapsed=1 [Window][Debug Menu] -Pos=26,34 +Pos=13,12 Size=339,226 Collapsed=0 +[Window][BVH Data] +Pos=953,64 +Size=775,355 +Collapsed=0 + +[Window][Example: Property editor] +Pos=60,60 +Size=430,450 +Collapsed=0 + +[Window][Example: Simple layout] +Pos=76,222 +Size=500,440 +Collapsed=0 + +[Window][BVH Data 0] +Pos=780,106 +Size=556,373 +Collapsed=0 + +[Window][BVH Data 10] +Pos=1079,43 +Size=491,217 +Collapsed=0 + +[Window][BVH Data 1] +Pos=60,60 +Size=1127,267 +Collapsed=0 + +[Window][BVH Data 4] +Pos=1111,78 +Size=498,168 +Collapsed=0 + +[Window][BVH Data 3] +Pos=60,60 +Size=358,266 +Collapsed=0 + +[Window][BVH Data 9] +Pos=60,60 +Size=293,240 +Collapsed=0 + +[Window][BVH Data 6] +Pos=60,60 +Size=372,270 +Collapsed=0 + +[Window][BVH Data 8] +Pos=60,60 +Size=327,303 +Collapsed=0 + +[Window][BVH Data 2] +Pos=60,60 +Size=324,211 +Collapsed=0 + +[Window][BVH Data ] +Pos=930,180 +Size=397,473 +Collapsed=0 + +[Window][Example: Long text display] +Pos=60,60 +Size=520,600 +Collapsed=0 + +[Table][0xD0F0C6E3,2] +Column 0 Weight=1.0000 +Column 1 Weight=1.0000 + diff --git a/Step 3/include/engine/math/bvh.h b/Step 3/include/engine/math/bvh.h index 818c916..d2e549b 100644 --- a/Step 3/include/engine/math/bvh.h +++ b/Step 3/include/engine/math/bvh.h @@ -11,6 +11,7 @@ #include #ifdef COMPILE_GUI #include + #include #endif #include @@ -21,10 +22,9 @@ namespace Raytracing { #ifdef COMPILE_GUI - struct BVHDebugVAO { - VAO* vaoPtr; - Vec4 position; - }; + extern std::shared_ptr aabbVAO; + extern int count; + extern int selected; #endif struct BVHObject { @@ -38,13 +38,64 @@ namespace Raytracing { }; struct BVHNode { + private: + static Raytracing::Mat4x4 getTransform(const AABB& _aabb){ + Raytracing::Mat4x4 transform {}; + auto center = _aabb.getCenter(); + transform.translate(center); + auto xRadius = _aabb.getXRadius(center) * 2; + auto yRadius = _aabb.getYRadius(center) * 2; + auto zRadius = _aabb.getZRadius(center) * 2; + transform.scale(float(xRadius), float(yRadius), float(zRadius)); + return transform; + } public: std::vector objs; AABB aabb; BVHNode* left; BVHNode* right; + int index; BVHNode(std::vector objs, AABB aabb, BVHNode* left, BVHNode* right): objs(std::move(objs)), aabb(std::move(aabb)), - left(left), right(right) {} + left(left), right(right) { + index = count++; + } + #ifdef COMPILE_GUI + void draw(Shader& worldShader){ + worldShader.setVec3("color", {1.0, 1.0, 1.0}); + if (selected == index){ + worldShader.setVec3("color", {0.0, 0.0, 1.0}); + if (ImGui::BeginListBox("")){ + for (const auto& item : objs){ + auto pos = item.ptr->getPosition(); + ImGui::Text("%s", (std::to_string(pos.x()) + " " + std::to_string(pos.y()) + " " + std::to_string(pos.z())).c_str()); + } + ImGui::EndListBox(); + } + + aabbVAO->bind(); + for (const auto& obj : objs) { + auto transform = getTransform(obj.aabb); + worldShader.setMatrix("transform", transform); + aabbVAO->draw(worldShader); + } + auto transform = getTransform(aabb); + worldShader.setMatrix("transform", transform); + aabbVAO->draw(worldShader); + + auto splitAABBs = aabb.splitByLongestAxis(); + transform = getTransform(splitAABBs.second); + worldShader.setMatrix("transform", transform); + aabbVAO->draw(worldShader); + transform = getTransform(splitAABBs.first); + worldShader.setMatrix("transform", transform); + aabbVAO->draw(worldShader); + } + } + void gui() const { + if (ImGui::Selectable(("S: " + std::to_string(objs.size()) + " I: " + std::to_string(index)).c_str(), selected == index)) + selected = index; + } + #endif ~BVHNode() { delete (left); delete (right); @@ -53,9 +104,6 @@ namespace Raytracing { class BVHTree { private: - #ifdef COMPILE_GUI - std::vector aabbVAOs; - #endif const int MAX_TREE_DEPTH = 50; BVHNode* root = nullptr; @@ -66,21 +114,23 @@ namespace Raytracing { // if this object doesn't have an AABB, we cannot use a BVH on it // If this ever fails we have a problem with the implementation. RTAssert(!obj.aabb.isEmpty()); - if (obj.aabb.intersects(aabbs.first)) { + if (aabbs.first.intersects(obj.aabb)) { space.left.push_back(obj); + tlog << "left\n"; } - if (obj.aabb.intersects(aabbs.second)) { + if (aabbs.second.intersects(obj.aabb)) { space.right.push_back(obj); + tlog << "right\n"; } } return space; } - BVHNode* addObjectsRecur(const std::vector& objects, unsigned long prevSize) { - //ilog << "size: " << objects.size() << "\n"; + BVHNode* addObjectsRecur(const std::vector& objects, long prevSize) { + ilog << "size: " << objects.size() << " " << prevSize << "\n"; // prevSize was required to solve some really weird bugs // which are a TODO: - if ((objects.size() <= 2 && !objects.empty()) || prevSize == objects.size()) { + if ((objects.size() <= 1 && !objects.empty()) || prevSize == objects.size()) { AABB local; for (const auto& obj: objects) local = local.expand(obj.aabb); @@ -93,21 +143,21 @@ namespace Raytracing { // this ensures that we have a minimum AABB. AABB world; for (const auto& obj: objects) { - //tlog << obj->getAABB(); world = world.expand(obj.aabb); } - //tlog << "\n"; // then split and partition the world auto splitAABBs = world.splitByLongestAxis(); auto partitionedObjs = partition(splitAABBs, objects); + elog << partitionedObjs.left.size() << " :: " << partitionedObjs.right.size() << "\n"; + BVHNode* left = nullptr; BVHNode* right = nullptr; // don't try to explore nodes which don't have anything in them. if (!partitionedObjs.left.empty()) - left = addObjectsRecur(partitionedObjs.left, objects.size()); + left = addObjectsRecur(partitionedObjs.left, (long) objects.size()); if (!partitionedObjs.right.empty()) - right = addObjectsRecur(partitionedObjs.right, objects.size()); + right = addObjectsRecur(partitionedObjs.right, (long) objects.size()); return new BVHNode(objects, world, left, right); } @@ -128,10 +178,31 @@ namespace Raytracing { // which is much faster! (especially when dealing with triangles) return node->objs; } + #ifdef COMPILE_GUI + void drawNodesRecur(Shader& worldShader, BVHNode* node){ + node->draw(worldShader); + if (node->left != nullptr) + drawNodesRecur(worldShader, node->left); + if (node->right != nullptr) + drawNodesRecur(worldShader, node->right); + } + void guiNodesRecur(BVHNode* node){ + node->gui(); + if (node->left != nullptr) + guiNodesRecur(node->left); + if (node->right != nullptr) + guiNodesRecur(node->right); + } + #endif public: std::vector noAABBObjects; explicit BVHTree(const std::vector& objectsInWorld) { addObjects(objectsInWorld); + #ifdef COMPILE_GUI + auto aabbVertexData = Shapes::cubeVertexBuilder{}; + if (aabbVAO == nullptr) + aabbVAO = std::make_shared(aabbVertexData.cubeVerticesRaw, aabbVertexData.cubeUVs); + #endif } void addObjects(const std::vector& objects) { @@ -146,19 +217,6 @@ namespace Raytracing { noAABBObjects.push_back(obj); continue; } - - #ifdef COMPILE_GUI - // create a VAO for debugging the AABB bounds. - BVHDebugVAO vaoStorage {}; - auto aabbCenter = obj->getAABB().getCenter(); - auto aabbXRadius = obj->getAABB().getXRadius(aabbCenter); - auto aabbYRadius = obj->getAABB().getYRadius(aabbCenter); - auto aabbZRadius = obj->getAABB().getZRadius(aabbCenter); - auto aabbVertexData = Shapes::cubeVertexBuilder::getCubeExtends(float(aabbXRadius), float(aabbYRadius), float(aabbZRadius)); - vaoStorage.vaoPtr = new VAO(aabbVertexData.cubeVerticesRaw, aabbVertexData.cubeUVs); - vaoStorage.position = obj->getPosition(); - aabbVAOs.push_back(vaoStorage); - #endif BVHObject bvhObject; // returns a copy of the AABB object and assigns it in to the tree storage object @@ -167,7 +225,7 @@ namespace Raytracing { bvhObject.ptr = obj; objs.push_back(bvhObject); } - root = addObjectsRecur(objs, -1); + root = addObjectsRecur(objs, 1); } std::vector rayIntersect(const Ray& ray, PRECISION_TYPE min, PRECISION_TYPE max) { @@ -177,22 +235,30 @@ namespace Raytracing { #ifdef COMPILE_GUI // renders all the debug VAOs on screen. void render (Shader& worldShader){ + ImGui::Begin(("BVH Data "), nullptr, ImGuiWindowFlags_NoCollapse); worldShader.use(); worldShader.setInt("useWhite", 1); - for (const auto& debugVAO : aabbVAOs){ - debugVAO.vaoPtr->bind(); - debugVAO.vaoPtr->draw(worldShader, {debugVAO.position}); + worldShader.setVec3("color", {1.0, 1.0, 1.0}); + { + ImGui::BeginChild("left pane", ImVec2(150, 0), true); + guiNodesRecur(root); + ImGui::EndChild(); + } + ImGui::SameLine(); + { + ImGui::BeginGroup(); + ImGui::BeginChild("item view", ImVec2(0, -ImGui::GetFrameHeightWithSpacing()), true, ImGuiWindowFlags_AlwaysAutoResize); // Leave room for 1 line below us + drawNodesRecur(worldShader, root); + ImGui::EndChild(); + ImGui::EndGroup(); } worldShader.setInt("useWhite", 0); + ImGui::End(); } #endif ~BVHTree() { delete (root); - #ifdef COMPILE_GUI - for (const auto& debugVAORef : aabbVAOs) - delete(debugVAORef.vaoPtr); - #endif } }; diff --git a/Step 3/include/engine/math/colliders.h b/Step 3/include/engine/math/colliders.h index f732bfe..6eb80f9 100644 --- a/Step 3/include/engine/math/colliders.h +++ b/Step 3/include/engine/math/colliders.h @@ -104,13 +104,13 @@ namespace Raytracing { [[nodiscard]] Vec4 getMin() const { return min; } [[nodiscard]] Vec4 getMax() const { return max; } - inline PRECISION_TYPE getXRadius(const Vec4& center){ + [[nodiscard]] inline PRECISION_TYPE getXRadius(const Vec4& center) const { return max.x() - center.x(); } - inline PRECISION_TYPE getYRadius(const Vec4& center){ + [[nodiscard]] inline PRECISION_TYPE getYRadius(const Vec4& center) const { return max.y() - center.y(); } - inline PRECISION_TYPE getZRadius(const Vec4& center){ + [[nodiscard]] inline PRECISION_TYPE getZRadius(const Vec4& center) const { return max.z() - center.z(); } @@ -118,8 +118,13 @@ namespace Raytracing { }; inline std::ostream& operator<<(std::ostream& out, const AABB& v) { - return out << "AABB{min{" << v.getMin().x() << ", " << v.getMin().y() << ", " << v.getMin().z() << "}, max{" << v.getMax().x() << ", " << v.getMax().y() - << ", " << v.getMax().z() << "}} "; + auto max = v.getMax(); + auto min = v.getMin(); + auto center = v.getCenter(); + return out << "AABB {\n\t min{" << min.x() << ", " << min.y() << ", " << min.z() << "},\n\t max{" << max.x() << ", " << max.y() + << ", " << max.z() << "},\n\t diff{" << max.x() - min.x() << ", " << max.y() - min.y() << ", " << max.z() - min.z() << "},\n\t " + << "center{" << center.x() << ", " << center.y() << ", " << center.z() << "},\n\t " + << "radi{" << v.getXRadius(center) << ", " << v.getYRadius(center) << ", " << v.getZRadius(center) << "}\n};\n"; } } diff --git a/Step 3/include/engine/math/vectors.h b/Step 3/include/engine/math/vectors.h index 650dc39..8ae5022 100644 --- a/Step 3/include/engine/math/vectors.h +++ b/Step 3/include/engine/math/vectors.h @@ -617,6 +617,20 @@ namespace Raytracing { inline float m23(float d) { return data.dim[3][2] = d; } inline float m33(float d) { return data.dim[3][3] = d; } inline float m(int i, int j, float d) { return data.dim[i][j] = d; }; +// inline float* operator [](int _i) { +// return data.dim[_i]; +// } + + [[nodiscard]] PRECISION_TYPE determinant() const { + return m00() * (m11() * m22() * m33() + m12() * m23() * m31() + m13() * m21() * m32() + - m31() * m22() * m13() - m32() * m23() * m11() - m33() * m21() * m12()) + - m10() * (m01() * m22() * m33() + m02() * m23() * m31() + m03() * m21() * m32() + - m31() * m32() * m03() - m32() * m23() * m01() - m33() * m21() * m02()) + + m20() * (m01() * m12() * m33() + m02() * m13() * m31() + m03() * m11() * m32() + - m31() * m12() * m03() - m32() * m13() * m01() - m33() * m11() * m02()) + - m30() * (m01() * m12() * m23() + m02() * m13() * m21() + m03() * m11() * m22() + - m21() * m12() * m03() - m22() * m13() * m01() - m23() * m11() * m02()); + } }; // adds the two Mat4x4 left and right diff --git a/Step 3/include/engine/raytracing.h b/Step 3/include/engine/raytracing.h index e690c42..9bc23d8 100644 --- a/Step 3/include/engine/raytracing.h +++ b/Step 3/include/engine/raytracing.h @@ -72,7 +72,7 @@ namespace Raytracing { void setPosition(const Vec4& pos) { this->position = pos; } - void setRotation(PRECISION_TYPE yaw, PRECISION_TYPE pitch, PRECISION_TYPE roll); + void setRotation(PRECISION_TYPE yaw, PRECISION_TYPE pitch); // the follow utility functions are actually taking forever to get right // I can't tell if my projection calculation is off or the view calc? @@ -95,7 +95,7 @@ namespace Raytracing { //glm::mat4 projectG = glm::perspective(glm::radians(90.0f), (float)aspectRatio, 0.1f, (float)1000); //return Mat4x4{projectG}; } - Mat4x4 view(const Vec4& lookAtPos){ + [[nodiscard]] Mat4x4 view(const Vec4& lookAtPos) const { Mat4x4 view; auto w = (position - lookAtPos).normalize(); // forward @@ -125,44 +125,8 @@ namespace Raytracing { return view; } - Mat4x4 view(PRECISION_TYPE yaw, PRECISION_TYPE pitch) { - Mat4x4 view; - - pitch = degreeeToRadian(pitch); - yaw = degreeeToRadian(yaw); - - PRECISION_TYPE cosPitch = std::cos(pitch); - PRECISION_TYPE cosYaw = std::cos(yaw); - PRECISION_TYPE sinPitch = std::sin(pitch); - PRECISION_TYPE sinYaw = std::sin(yaw); - - auto x = Vec4{cosYaw, 0, -sinYaw}; // forward - auto y = Vec4{sinYaw * sinPitch, cosPitch, cosYaw * sinPitch}; // right - auto z = Vec4{sinYaw * cosPitch, -sinPitch, cosPitch * cosYaw}; // up - - view.m00(float(x.x())); - view.m01(float(x.y())); - view.m02(float(x.z())); - view.m03(float(x.w())); - - view.m10(float(y.x())); - view.m11(float(y.y())); - view.m12(float(y.z())); - view.m13(float(y.w())); - - view.m20(float(z.x())); - view.m21(float(z.y())); - view.m22(float(z.z())); - view.m23(float(z.w())); - - // view matrix are inverted, dot product to simulate translate matrix multiplication - view.m03(-float(Vec4::dot(x, position))); - view.m13(-float(Vec4::dot(y, position))); - view.m23(-float(Vec4::dot(z, position))); - view.m33(1); - - return view; - } + Mat4x4 view(PRECISION_TYPE yaw, PRECISION_TYPE pitch); + [[nodiscard]] inline Vec4 getPosition() const {return position;}; // the camera's position must be set with setPosition(Vec4); diff --git a/Step 3/include/graphics/gl/gl.h b/Step 3/include/graphics/gl/gl.h index e171799..661e1d9 100644 --- a/Step 3/include/graphics/gl/gl.h +++ b/Step 3/include/graphics/gl/gl.h @@ -237,6 +237,7 @@ class VAO { void draw() const; // draw as if it's a box that we need to bulk draw. void draw(Raytracing::Shader& shader, const std::vector& positions); + void draw(Raytracing::Shader& shader); ~VAO(); }; diff --git a/Step 3/resources/shaders/world.fs b/Step 3/resources/shaders/world.fs index c1cd475..30ee58b 100644 --- a/Step 3/resources/shaders/world.fs +++ b/Step 3/resources/shaders/world.fs @@ -6,6 +6,7 @@ in vec3 outNormal; uniform sampler2D tex; uniform int useWhite; +uniform vec3 color; const vec3 lightDir = vec3(1.0, 1.0, 1.0); @@ -15,5 +16,5 @@ void main() { if (useWhite == 0) FragColor = vec4(vec3(1.0, 0.0f, 0.0f) * dot(lightDir, outNormal), 1.0f); else - FragColor = vec4(1.0); + FragColor = vec4(color, 1.0f); } \ No newline at end of file diff --git a/Step 3/src/engine/globals.cpp b/Step 3/src/engine/globals.cpp index 74749ba..4c32ab3 100644 --- a/Step 3/src/engine/globals.cpp +++ b/Step 3/src/engine/globals.cpp @@ -4,6 +4,10 @@ */ // Yes, globals are bad. #include "engine/util/debug.h" +#include +#ifdef COMPILE_GUI + #include +#endif bool* haltExecution; bool* pauseRaytracing; @@ -11,4 +15,9 @@ bool* haltRaytracing; namespace Raytracing { std::unordered_map> profiles; + #ifdef COMPILE_GUI + std::shared_ptr aabbVAO = nullptr; + int count = 0; + int selected = 0; + #endif } \ No newline at end of file diff --git a/Step 3/src/engine/main.cpp b/Step 3/src/engine/main.cpp index 727ad94..edefc73 100644 --- a/Step 3/src/engine/main.cpp +++ b/Step 3/src/engine/main.cpp @@ -126,11 +126,17 @@ int main(int argc, char** args) { //world.add(new Raytracing::SphereObject({1,0,-1,0}, 0.5, world.getMaterial("redMetal"))); world.add(new Raytracing::SphereObject({0, -100.5, -1, 0}, 100, world.getMaterial("greenDiffuse"))); //world.add(new Raytracing::TriangleObject({0,0.1,-0.5f,0}, {{-0.5, -0.5, 0.0}, {0.5, -0.5, 0.0}, {0.0, 0.5, 0}}, world.getMaterial("greenDiffuse"))); - world.add(new Raytracing::ModelObject({0, 1, 0}, spider, world.getMaterial("redDiffuse"))); + /*world.add(new Raytracing::ModelObject({0, 1, 0}, spider, world.getMaterial("redDiffuse"))); world.add(new Raytracing::ModelObject({-5, 0.5, 0}, plane, world.getMaterial("greenMetal"))); world.add(new Raytracing::ModelObject({5, 1, 0}, house, world.getMaterial("redDiffuse"))); world.add(new Raytracing::ModelObject({0, 0, -5}, house, world.getMaterial("blueDiffuse"))); - world.add(new Raytracing::ModelObject({0, 0, 5}, house, world.getMaterial("blueDiffuse"))); + world.add(new Raytracing::ModelObject({0, 0, 5}, house, world.getMaterial("blueDiffuse")));*/ + + world.add(new Raytracing::ModelObject({0, 1, 0}, spider, world.getMaterial("redDiffuse"))); + world.add(new Raytracing::ModelObject({-15, 0.5, 0}, plane, world.getMaterial("greenMetal"))); + world.add(new Raytracing::ModelObject({15, 1, 0}, house, world.getMaterial("redDiffuse"))); + world.add(new Raytracing::ModelObject({0, 0, -15}, house, world.getMaterial("blueDiffuse"))); + world.add(new Raytracing::ModelObject({0, 0, 15}, house, world.getMaterial("blueDiffuse"))); if (parser.hasOption("--gui") || parser.hasOption("-g")) { #ifdef COMPILE_GUI diff --git a/Step 3/src/engine/raytracing.cpp b/Step 3/src/engine/raytracing.cpp index a39345b..63d34bb 100644 --- a/Step 3/src/engine/raytracing.cpp +++ b/Step 3/src/engine/raytracing.cpp @@ -33,9 +33,53 @@ namespace Raytracing { imageOrigin = position - horizontalAxis / 2 - verticalAxis / 2 - w; } - void Camera::setRotation(const PRECISION_TYPE yaw, const PRECISION_TYPE pitch, const PRECISION_TYPE roll) { + void Camera::setRotation(const PRECISION_TYPE yaw, const PRECISION_TYPE pitch) { // TODO: } + Mat4x4 Camera::view(PRECISION_TYPE yaw, PRECISION_TYPE pitch) { + Mat4x4 view; + + pitch = degreeeToRadian(pitch); + yaw = degreeeToRadian(yaw); + + PRECISION_TYPE cosPitch = std::cos(pitch); + PRECISION_TYPE cosYaw = std::cos(yaw); + PRECISION_TYPE sinPitch = std::sin(pitch); + PRECISION_TYPE sinYaw = std::sin(yaw); + + auto x = Vec4{cosYaw, 0, -sinYaw}; // forward + auto y = Vec4{sinYaw * sinPitch, cosPitch, cosYaw * sinPitch}; // right + auto z = Vec4{sinYaw * cosPitch, -sinPitch, cosPitch * cosYaw}; // up + + viewportHeight = 1 * tanFovHalf; + viewportWidth = aspectRatio * viewportHeight; + horizontalAxis = viewportWidth * x; + verticalAxis = viewportHeight * y; + imageOrigin = position - horizontalAxis / 2 - verticalAxis / 2 - z; + + view.m00(float(x.x())); + view.m01(float(x.y())); + view.m02(float(x.z())); + view.m03(float(x.w())); + + view.m10(float(y.x())); + view.m11(float(y.y())); + view.m12(float(y.z())); + view.m13(float(y.w())); + + view.m20(float(z.x())); + view.m21(float(z.y())); + view.m22(float(z.z())); + view.m23(float(z.w())); + + // view matrix are inverted, dot product to simulate translate matrix multiplication + view.m03(-float(Vec4::dot(x, position))); + view.m13(-float(Vec4::dot(y, position))); + view.m23(-float(Vec4::dot(z, position))); + view.m33(1); + + return view; + } struct RayData { Ray ray; diff --git a/Step 3/src/graphics/gl/gl.cpp b/Step 3/src/graphics/gl/gl.cpp index 7501f30..1e17005 100644 --- a/Step 3/src/graphics/gl/gl.cpp +++ b/Step 3/src/graphics/gl/gl.cpp @@ -209,6 +209,9 @@ void VAO::draw(Raytracing::Shader& shader, const std::vector& glDrawArrays(GL_TRIANGLES, 0, drawCount); } } +void VAO::draw(Raytracing::Shader& shader) { + glDrawArrays(GL_TRIANGLES, 0, drawCount); +} void VAO::draw() const { if (drawCount < 0) return; diff --git a/Step 3/src/graphics/graphics.cpp b/Step 3/src/graphics/graphics.cpp index 1248ea9..0e0bb0f 100644 --- a/Step 3/src/graphics/graphics.cpp +++ b/Step 3/src/graphics/graphics.cpp @@ -516,6 +516,17 @@ namespace Raytracing { yaw += (float) Input::getMouseDelta().x * (1000.0f / ImGui::GetIO().Framerate / 1000.0f) * 3; pitch += (float) Input::getMouseDelta().y * (1000.0f / ImGui::GetIO().Framerate / 1000.0f) * 1.5f; + const PRECISION_TYPE turnSpeed = 50; + + if (Input::isKeyDown(GLFW_KEY_LEFT)) + yaw += float(turnSpeed * m_window.getFrameTimeSeconds()); + if (Input::isKeyDown(GLFW_KEY_RIGHT)) + yaw -= float(turnSpeed * m_window.getFrameTimeSeconds()); + if (Input::isKeyDown(GLFW_KEY_UP)) + pitch += float(turnSpeed * m_window.getFrameTimeSeconds()); + if (Input::isKeyDown(GLFW_KEY_DOWN)) + pitch -= float(turnSpeed * m_window.getFrameTimeSeconds()); + PRECISION_TYPE moveAtX = 0, moveAtY = 0, moveAtZ = 0; PRECISION_TYPE speed = 40.0f; @@ -554,9 +565,9 @@ namespace Raytracing { m_spiderVAO->bind(); m_spiderVAO->draw(m_worldShader, {{0, 1, 0}}); m_houseVAO->bind(); - m_houseVAO->draw(m_worldShader, {{5, 1, 0}, {0, 0, -5}, {0, 0, 5}}); + m_houseVAO->draw(m_worldShader, {{15, 1, 0}, {0, 0, -15}, {0, 0, 15}}); m_planeVAO->bind(); - m_planeVAO->draw(m_worldShader, {{-5, 0.5, 0}}); + m_planeVAO->draw(m_worldShader, {{-15, 0.5, 0}}); } else { m_imageShader.use(); m_mainImage.updateImage();