Raytracer and Debug views now align
parent
4c9e4b6787
commit
c881b780ff
Binary file not shown.
|
@ -2,53 +2,66 @@
|
||||||
374 3235 1668323538168825062 CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_tables.cpp.o f6dab204e07e8dcf
|
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
|
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
|
4 3390 1668323512856096078 CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_demo.cpp.o 7798aba97da63e31
|
||||||
1 2068 1668528621778322458 CMakeFiles/Step_3.dir/src/engine/world.cpp.o 6470df278966c4
|
2 2114 1668546480900864797 CMakeFiles/Step_3.dir/src/engine/world.cpp.o 6470df278966c4
|
||||||
2 1641 1668366223598629532 CMakeFiles/Step_3.dir/src/engine/util/debug.cpp.o d86a254d2bce8f74
|
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
|
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
|
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
|
4 605 1668323535536749264 CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_impl_x11.cpp.o d1e9a2fcb31e2ec8
|
||||||
0 26 1668358519550031316 build.ninja ccb5de0c063412ab
|
0 26 1668358519550031316 build.ninja ccb5de0c063412ab
|
||||||
1 1305 1668528538563906174 CMakeFiles/Step_3.dir/src/engine/globals.cpp.o 4ef77d2224f86511
|
2 1171 1668539611850637805 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 818 1668545258765546884 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
|
2 1391 1668546480176844883 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
|
3 6633 1668323516100189511 CMakeFiles/Step_3.dir/src/graphics/imgui/imgui.cpp.o 55e7538fd27b47be
|
||||||
2778 2864 1668528622574345618 Step_3 f055ce2b85635598
|
2466 2536 1668546481320876352 Step_3 f055ce2b85635598
|
||||||
4 521 1668323535452746847 CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_impl_glfw.cpp.o 6aef9db88eb3d76d
|
4 521 1668323535452746847 CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_impl_glfw.cpp.o 6aef9db88eb3d76d
|
||||||
1 2214 1668528621918326531 CMakeFiles/Step_3.dir/src/engine/raytracing.cpp.o 11f0e227e9fda9ca
|
1 1817 1668546480604856656 CMakeFiles/Step_3.dir/src/engine/raytracing.cpp.o 11f0e227e9fda9ca
|
||||||
1 827 1668366742693637470 CMakeFiles/Step_3.dir/src/graphics/input.cpp.o 510001b0955ab019
|
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
|
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
|
2 1656 1668546480440852145 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
|
521 6249 1668323541180911801 CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_widgets.cpp.o 84017388bc7af144
|
||||||
2 1520 1668528538779912434 CMakeFiles/Step_3.dir/src/graphics/gl/gl.cpp.o 330ad35a6abf06c3
|
3 1504 1668539612182647872 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
|
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
|
2 1655 1668489141487439674 CMakeFiles/Step_3.dir/src/graphics/gl/shader.cpp.o 2553d57dba16057b
|
||||||
1 2778 1668528622490343174 CMakeFiles/Step_3.dir/src/engine/main.cpp.o 641dce3f86933e2e
|
1 2466 1668546481252874479 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 2095 1668366224050642556 CMakeFiles/Step_3.dir/src/engine/util/parser.cpp.o 1007c86c207ac940
|
||||||
1 1359 1668528665647599927 CMakeFiles/Step_3.dir/src/engine/util/models.cpp.o 164394d360c43072
|
1 1595 1668546503513487557 CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o ce988de97a5cb51d
|
||||||
1 1399 1668528665687601092 CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o ce988de97a5cb51d
|
1596 1677 1668546503593489763 Step_3 f055ce2b85635598
|
||||||
1 1729 1668528666019610769 CMakeFiles/Step_3.dir/src/engine/world.cpp.o 6470df278966c4
|
1 1667 1668546613472534906 CMakeFiles/Step_3.dir/src/engine/util/models.cpp.o 164394d360c43072
|
||||||
1 1774 1668528666063612051 CMakeFiles/Step_3.dir/src/engine/raytracing.cpp.o 11f0e227e9fda9ca
|
1 1765 1668546613568537578 CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o ce988de97a5cb51d
|
||||||
1 2562 1668528666851635019 CMakeFiles/Step_3.dir/src/engine/main.cpp.o 641dce3f86933e2e
|
1 2011 1668546613816544487 CMakeFiles/Step_3.dir/src/engine/raytracing.cpp.o 11f0e227e9fda9ca
|
||||||
2563 2637 1668528666923637119 Step_3 f055ce2b85635598
|
1 2634 1668546614440561861 CMakeFiles/Step_3.dir/src/engine/world.cpp.o 6470df278966c4
|
||||||
2 981 1668530133106059603 CMakeFiles/Step_3.dir/src/engine/math/colliders.cpp.o 39e9f435096d066b
|
1 2839 1668546614644567542 CMakeFiles/Step_3.dir/src/engine/main.cpp.o 641dce3f86933e2e
|
||||||
1 1161 1668530133286064346 CMakeFiles/Step_3.dir/src/engine/globals.cpp.o 4ef77d2224f86511
|
2840 2924 1668546614728569881 Step_3 f055ce2b85635598
|
||||||
2 1264 1668530133390067087 CMakeFiles/Step_3.dir/src/graphics/gl/gl.cpp.o 330ad35a6abf06c3
|
2 1503 1668546664905969925 CMakeFiles/Step_3.dir/src/engine/util/models.cpp.o 164394d360c43072
|
||||||
2 1460 1668530133582072147 CMakeFiles/Step_3.dir/src/engine/util/models.cpp.o 164394d360c43072
|
2 1774 1668546665177977529 CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o ce988de97a5cb51d
|
||||||
2 1814 1668530133938081528 CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o ce988de97a5cb51d
|
1 1837 1668546665241979318 CMakeFiles/Step_3.dir/src/engine/raytracing.cpp.o 11f0e227e9fda9ca
|
||||||
2 1997 1668530134122086379 CMakeFiles/Step_3.dir/src/engine/raytracing.cpp.o 11f0e227e9fda9ca
|
2 2200 1668546665605989494 CMakeFiles/Step_3.dir/src/engine/world.cpp.o 6470df278966c4
|
||||||
2 2244 1668530134366092808 CMakeFiles/Step_3.dir/src/engine/world.cpp.o 6470df278966c4
|
1 2541 1668546665945998998 CMakeFiles/Step_3.dir/src/engine/main.cpp.o 641dce3f86933e2e
|
||||||
2 2479 1668530134602099030 CMakeFiles/Step_3.dir/src/engine/main.cpp.o 641dce3f86933e2e
|
2541 2621 1668546666026001236 Step_3 f055ce2b85635598
|
||||||
2479 2544 1668530134666100715 Step_3 f055ce2b85635598
|
2 1815 1668546866179632251 CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o ce988de97a5cb51d
|
||||||
2 868 1668530626127552949 CMakeFiles/Step_3.dir/src/engine/math/colliders.cpp.o 39e9f435096d066b
|
2 1821 1668546866187632477 CMakeFiles/Step_3.dir/src/engine/util/models.cpp.o 164394d360c43072
|
||||||
2 1000 1668530626263556771 CMakeFiles/Step_3.dir/src/engine/globals.cpp.o 4ef77d2224f86511
|
2 1885 1668546866251634287 CMakeFiles/Step_3.dir/src/engine/world.cpp.o 6470df278966c4
|
||||||
2 1425 1668530626687568690 CMakeFiles/Step_3.dir/src/engine/util/models.cpp.o 164394d360c43072
|
2 2159 1668546866523641982 CMakeFiles/Step_3.dir/src/engine/raytracing.cpp.o 11f0e227e9fda9ca
|
||||||
2 1461 1668530626723569702 CMakeFiles/Step_3.dir/src/graphics/gl/gl.cpp.o 330ad35a6abf06c3
|
1 2761 1668546867127659070 CMakeFiles/Step_3.dir/src/engine/main.cpp.o 641dce3f86933e2e
|
||||||
3 1490 1668530626751570490 CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o ce988de97a5cb51d
|
2761 2826 1668546867191660882 Step_3 f055ce2b85635598
|
||||||
2 1793 1668530627055579036 CMakeFiles/Step_3.dir/src/engine/world.cpp.o 6470df278966c4
|
1 1633 1668546918285108046 CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o ce988de97a5cb51d
|
||||||
2 1879 1668530627139581398 CMakeFiles/Step_3.dir/src/engine/raytracing.cpp.o 11f0e227e9fda9ca
|
1 1633 1668546918285108046 CMakeFiles/Step_3.dir/src/engine/util/models.cpp.o 164394d360c43072
|
||||||
2 2591 1668530627851601414 CMakeFiles/Step_3.dir/src/engine/main.cpp.o 641dce3f86933e2e
|
1 1915 1668546918565115986 CMakeFiles/Step_3.dir/src/engine/world.cpp.o 6470df278966c4
|
||||||
2591 2654 1668530627915603213 Step_3 f055ce2b85635598
|
1 1997 1668546918649118365 CMakeFiles/Step_3.dir/src/engine/raytracing.cpp.o 11f0e227e9fda9ca
|
||||||
1 769 1668530642748020441 CMakeFiles/Step_3.dir/src/engine/math/colliders.cpp.o 39e9f435096d066b
|
1 2691 1668546919341137991 CMakeFiles/Step_3.dir/src/engine/main.cpp.o 641dce3f86933e2e
|
||||||
769 834 1668530642812022239 Step_3 f055ce2b85635598
|
2691 2758 1668546919409139920 Step_3 f055ce2b85635598
|
||||||
1 813 1668530661440546885 CMakeFiles/Step_3.dir/src/engine/math/colliders.cpp.o 39e9f435096d066b
|
1 983 1668547097978221140 CMakeFiles/Step_3.dir/src/engine/math/colliders.cpp.o 39e9f435096d066b
|
||||||
813 887 1668530661512548914 Step_3 f055ce2b85635598
|
983 1070 1668547098062223537 Step_3 f055ce2b85635598
|
||||||
|
1 819 1668547150995735542 CMakeFiles/Step_3.dir/src/engine/math/colliders.cpp.o 39e9f435096d066b
|
||||||
|
819 897 1668547151071737716 Step_3 f055ce2b85635598
|
||||||
|
1 822 1668547225097855828 CMakeFiles/Step_3.dir/src/engine/math/colliders.cpp.o 39e9f435096d066b
|
||||||
|
822 890 1668547225161857663 Step_3 f055ce2b85635598
|
||||||
|
1 980 1668547305172151145 CMakeFiles/Step_3.dir/src/engine/math/colliders.cpp.o 39e9f435096d066b
|
||||||
|
980 1050 1668547305240153096 Step_3 f055ce2b85635598
|
||||||
|
1 1255 1668547390318595902 CMakeFiles/Step_3.dir/src/engine/math/colliders.cpp.o 39e9f435096d066b
|
||||||
|
1 1473 1668547390534602108 CMakeFiles/Step_3.dir/src/engine/util/models.cpp.o 164394d360c43072
|
||||||
|
2 1618 1668547390678606246 CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o ce988de97a5cb51d
|
||||||
|
1 2014 1668547391074617625 CMakeFiles/Step_3.dir/src/engine/raytracing.cpp.o 11f0e227e9fda9ca
|
||||||
|
1 2020 1668547391082617856 CMakeFiles/Step_3.dir/src/engine/world.cpp.o 6470df278966c4
|
||||||
|
1 3089 1668547392150648545 CMakeFiles/Step_3.dir/src/engine/main.cpp.o 641dce3f86933e2e
|
||||||
|
3089 3168 1668547392226650728 Step_3 f055ce2b85635598
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -1,3 +1,3 @@
|
||||||
Start testing: Nov 15 11:44 EST
|
Start testing: Nov 15 16:23 EST
|
||||||
----------------------------------------------------------
|
----------------------------------------------------------
|
||||||
End testing: Nov 15 11:44 EST
|
End testing: Nov 15 16:23 EST
|
||||||
|
|
|
@ -9,7 +9,7 @@ Size=550,680
|
||||||
Collapsed=1
|
Collapsed=1
|
||||||
|
|
||||||
[Window][Debug Menu]
|
[Window][Debug Menu]
|
||||||
Pos=-6,23
|
Pos=35,13
|
||||||
Size=339,226
|
Size=339,226
|
||||||
Collapsed=0
|
Collapsed=0
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ Size=324,211
|
||||||
Collapsed=0
|
Collapsed=0
|
||||||
|
|
||||||
[Window][BVH Data ]
|
[Window][BVH Data ]
|
||||||
Pos=913,184
|
Pos=897,115
|
||||||
Size=522,476
|
Size=522,476
|
||||||
Collapsed=0
|
Collapsed=0
|
||||||
|
|
||||||
|
|
|
@ -53,21 +53,56 @@ namespace Raytracing {
|
||||||
return transform;
|
return transform;
|
||||||
}
|
}
|
||||||
public:
|
public:
|
||||||
|
struct BVHHitData {
|
||||||
|
BVHNode* ptr;
|
||||||
|
AABBHitData data;
|
||||||
|
bool hit = false;
|
||||||
|
};
|
||||||
std::vector<BVHObject> objs;
|
std::vector<BVHObject> objs;
|
||||||
AABB aabb;
|
AABB aabb;
|
||||||
BVHNode* left;
|
BVHNode* left;
|
||||||
BVHNode* right;
|
BVHNode* right;
|
||||||
int index;
|
int index;
|
||||||
|
int hit = 0;
|
||||||
BVHNode(std::vector<BVHObject> objs, AABB aabb, BVHNode* left, BVHNode* right): objs(std::move(objs)), aabb(std::move(aabb)),
|
BVHNode(std::vector<BVHObject> 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++;
|
index = count++;
|
||||||
}
|
}
|
||||||
|
BVHHitData doesRayIntersect(const Ray& r, PRECISION_TYPE min, PRECISION_TYPE max){
|
||||||
|
auto ourHitData = aabb.intersects(r, min, max);
|
||||||
|
ilog << "Our hit did hit? " << ourHitData.hit << "\n";
|
||||||
|
if (!ourHitData.hit)
|
||||||
|
return {this, ourHitData, false};
|
||||||
|
|
||||||
|
/*this->hit = 2;
|
||||||
|
|
||||||
|
BVHHitData leftHit{};
|
||||||
|
BVHHitData rightHit{};
|
||||||
|
if (left != nullptr)
|
||||||
|
leftHit = left->doesRayIntersect(r, min, max);
|
||||||
|
if (right != nullptr)
|
||||||
|
rightHit = right->doesRayIntersect(r, min, max);
|
||||||
|
|
||||||
|
if (!leftHit.hit && !rightHit.hit)
|
||||||
|
return {this, ourHitData, ourHitData.hit};
|
||||||
|
|
||||||
|
return leftHit.hit ? leftHit : rightHit;*/
|
||||||
|
tlog << ourHitData.hit << "\n";
|
||||||
|
return {this, ourHitData, true};
|
||||||
|
}
|
||||||
#ifdef COMPILE_GUI
|
#ifdef COMPILE_GUI
|
||||||
void draw(Shader& worldShader) {
|
void draw(Shader& worldShader) {
|
||||||
worldShader.setVec3("color", {1.0, 1.0, 1.0});
|
worldShader.setVec3("color", {1.0, 1.0, 1.0});
|
||||||
if (selected == index) {
|
if (selected == index || hit) {
|
||||||
worldShader.setVec3("color", {0.0, 0.0, 1.0});
|
if (hit == 1)
|
||||||
if (ImGui::BeginListBox("", ImVec2(250, 350))) {
|
worldShader.setVec3("color", {0.0, 0.0, 1.0});
|
||||||
|
else if (hit == 2)
|
||||||
|
worldShader.setVec3("color", {0.0, 1.0, 0.0});
|
||||||
|
else if (hit == 0)
|
||||||
|
worldShader.setVec3("color", {1.0, 1.0, 1.0});
|
||||||
|
else
|
||||||
|
worldShader.setVec3("color", {1.0, 0.5, 0.5});
|
||||||
|
if (selected == index && ImGui::BeginListBox("", ImVec2(250, 350))) {
|
||||||
std::stringstream strs;
|
std::stringstream strs;
|
||||||
strs << aabb;
|
strs << aabb;
|
||||||
ImGui::Text("%s", strs.str().c_str());
|
ImGui::Text("%s", strs.str().c_str());
|
||||||
|
@ -124,7 +159,6 @@ namespace Raytracing {
|
||||||
|
|
||||||
class BVHTree {
|
class BVHTree {
|
||||||
private:
|
private:
|
||||||
const int MAX_TREE_DEPTH = 50;
|
|
||||||
BVHNode* root = nullptr;
|
BVHNode* root = nullptr;
|
||||||
|
|
||||||
// splits the objs in the vector based on the provided AABBs
|
// splits the objs in the vector based on the provided AABBs
|
||||||
|
@ -175,10 +209,6 @@ namespace Raytracing {
|
||||||
} else if (objects.empty()) // should never reach here!!
|
} else if (objects.empty()) // should never reach here!!
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
elog << partitionedObjs.left.size() << " :: " << partitionedObjs.right.size() << "\n";
|
|
||||||
|
|
||||||
BVHNode* left = nullptr;
|
BVHNode* left = nullptr;
|
||||||
BVHNode* right = nullptr;
|
BVHNode* right = nullptr;
|
||||||
// don't try to explore nodes which don't have anything in them.
|
// don't try to explore nodes which don't have anything in them.
|
||||||
|
@ -189,23 +219,6 @@ namespace Raytracing {
|
||||||
|
|
||||||
return new BVHNode(objects, world, left, right);
|
return new BVHNode(objects, world, left, right);
|
||||||
}
|
}
|
||||||
static std::vector<BVHObject> traverseFindRayIntersection(BVHNode* node, const Ray& ray, PRECISION_TYPE min, PRECISION_TYPE max) {
|
|
||||||
// check for intersections on both sides of the tree
|
|
||||||
if (node->left != nullptr) {
|
|
||||||
if (node->left->aabb.intersects(ray, min, max))
|
|
||||||
return traverseFindRayIntersection(node->left, ray, min, max);
|
|
||||||
}
|
|
||||||
// since each aabb should be minimum, we shouldn't have to traverse both sides.
|
|
||||||
// we want to reduce our problem size by half each iteration anyways
|
|
||||||
// divide and conquer and so on
|
|
||||||
if (node->right != nullptr)
|
|
||||||
if (node->right->aabb.intersects(ray, min, max))
|
|
||||||
return traverseFindRayIntersection(node->right, ray, min, max);
|
|
||||||
// return the objects of the lowest BVH node we can find
|
|
||||||
// if this is implemented properly this should only contain one, maybe two objects
|
|
||||||
// which is much faster! (especially when dealing with triangles)
|
|
||||||
return node->objs;
|
|
||||||
}
|
|
||||||
#ifdef COMPILE_GUI
|
#ifdef COMPILE_GUI
|
||||||
void drawNodesRecur(Shader& worldShader, BVHNode* node) {
|
void drawNodesRecur(Shader& worldShader, BVHNode* node) {
|
||||||
node->draw(worldShader);
|
node->draw(worldShader);
|
||||||
|
@ -222,6 +235,13 @@ namespace Raytracing {
|
||||||
guiNodesRecur(node->right);
|
guiNodesRecur(node->right);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
void reset(BVHNode* node){
|
||||||
|
if (node == nullptr)
|
||||||
|
return;
|
||||||
|
node->hit = false;
|
||||||
|
reset(node->left);
|
||||||
|
reset(node->right);
|
||||||
|
}
|
||||||
public:
|
public:
|
||||||
std::vector<Object*> noAABBObjects;
|
std::vector<Object*> noAABBObjects;
|
||||||
explicit BVHTree(const std::vector<Object*>& objectsInWorld) {
|
explicit BVHTree(const std::vector<Object*>& objectsInWorld) {
|
||||||
|
@ -256,7 +276,13 @@ namespace Raytracing {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<BVHObject> rayIntersect(const Ray& ray, PRECISION_TYPE min, PRECISION_TYPE max) {
|
std::vector<BVHObject> rayIntersect(const Ray& ray, PRECISION_TYPE min, PRECISION_TYPE max) {
|
||||||
return traverseFindRayIntersection(root, ray, min, max);
|
RTAssert(root != nullptr);
|
||||||
|
auto results = root->doesRayIntersect(ray, min, max);
|
||||||
|
results.ptr->hit = 1;
|
||||||
|
return results.ptr->objs;
|
||||||
|
}
|
||||||
|
void resetNodes(){
|
||||||
|
reset(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef COMPILE_GUI
|
#ifdef COMPILE_GUI
|
||||||
|
|
|
@ -10,6 +10,11 @@
|
||||||
|
|
||||||
namespace Raytracing {
|
namespace Raytracing {
|
||||||
// 3D Axis Aligned Bounding Box for use in a BVH
|
// 3D Axis Aligned Bounding Box for use in a BVH
|
||||||
|
struct AABBHitData {
|
||||||
|
bool hit;
|
||||||
|
PRECISION_TYPE tMax;
|
||||||
|
};
|
||||||
|
|
||||||
class AABB {
|
class AABB {
|
||||||
protected:
|
protected:
|
||||||
Vec4 min;
|
Vec4 min;
|
||||||
|
@ -69,8 +74,8 @@ namespace Raytracing {
|
||||||
return intersects(other.min, other.max);
|
return intersects(other.min, other.max);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool intersects(const Ray& ray, PRECISION_TYPE tmin, PRECISION_TYPE tmax);
|
AABBHitData intersects(const Ray& ray, PRECISION_TYPE tmin, PRECISION_TYPE tmax);
|
||||||
bool simpleSlabRayAABBMethod(const Ray& ray, PRECISION_TYPE tmin, PRECISION_TYPE tmax);
|
AABBHitData simpleSlabRayAABBMethod(const Ray& ray, PRECISION_TYPE tmin, PRECISION_TYPE tmax);
|
||||||
|
|
||||||
[[nodiscard]] inline bool isInside(PRECISION_TYPE x, PRECISION_TYPE y, PRECISION_TYPE z) const {
|
[[nodiscard]] inline bool isInside(PRECISION_TYPE x, PRECISION_TYPE y, PRECISION_TYPE z) const {
|
||||||
return x >= min.x() && x <= max.x() && y >= min.y() && y <= max.y() && z >= min.z() && z <= max.z();
|
return x >= min.x() && x <= max.x() && y >= min.y() && y <= max.y() && z >= min.z() && z <= max.z();
|
||||||
|
|
|
@ -135,6 +135,7 @@ namespace Raytracing {
|
||||||
inline void addMaterial(const std::string& materialName, Material* mat) { materials.insert({materialName, mat}); }
|
inline void addMaterial(const std::string& materialName, Material* mat) { materials.insert({materialName, mat}); }
|
||||||
|
|
||||||
inline Material* getMaterial(const std::string& materialName) { return materials.at(materialName); }
|
inline Material* getMaterial(const std::string& materialName) { return materials.at(materialName); }
|
||||||
|
[[nodiscard]] inline BVHTree* getBVH() { return bvhObjects.get(); }
|
||||||
|
|
||||||
[[nodiscard]] virtual std::pair<HitData, Object*> checkIfHit(const Ray& ray, PRECISION_TYPE min, PRECISION_TYPE max) const;
|
[[nodiscard]] virtual std::pair<HitData, Object*> checkIfHit(const Ray& ray, PRECISION_TYPE min, PRECISION_TYPE max) const;
|
||||||
~World();
|
~World();
|
||||||
|
|
|
@ -68,6 +68,8 @@ namespace Raytracing {
|
||||||
|
|
||||||
void setMouseGrabbed(bool grabbed);
|
void setMouseGrabbed(bool grabbed);
|
||||||
bool isMouseGrabbed();
|
bool isMouseGrabbed();
|
||||||
|
[[nodiscard]] inline int displayWidth() const {return m_displayWidth;}
|
||||||
|
[[nodiscard]] inline int displayHeight() const {return m_displayHeight;}
|
||||||
|
|
||||||
void closeWindow();
|
void closeWindow();
|
||||||
~XWindow();
|
~XWindow();
|
||||||
|
@ -132,6 +134,7 @@ namespace Raytracing {
|
||||||
private:
|
private:
|
||||||
XWindow& m_window;
|
XWindow& m_window;
|
||||||
Texture& m_mainImage;
|
Texture& m_mainImage;
|
||||||
|
World& m_world;
|
||||||
Shader& m_imageShader;
|
Shader& m_imageShader;
|
||||||
Shader& m_worldShader;
|
Shader& m_worldShader;
|
||||||
Raycaster& m_raycaster;
|
Raycaster& m_raycaster;
|
||||||
|
@ -143,6 +146,7 @@ namespace Raytracing {
|
||||||
public:
|
public:
|
||||||
DisplayRenderer(XWindow& mWindow,
|
DisplayRenderer(XWindow& mWindow,
|
||||||
Texture& mMainImage,
|
Texture& mMainImage,
|
||||||
|
World& world,
|
||||||
Shader& mImageShader,
|
Shader& mImageShader,
|
||||||
Shader& mWorldShader,
|
Shader& mWorldShader,
|
||||||
Raycaster& mRaycaster,
|
Raycaster& mRaycaster,
|
||||||
|
@ -152,7 +156,7 @@ namespace Raytracing {
|
||||||
VAO* mPlaneVao,
|
VAO* mPlaneVao,
|
||||||
Camera& mCamera)
|
Camera& mCamera)
|
||||||
: m_window(mWindow), m_mainImage(mMainImage), m_imageShader(mImageShader), m_worldShader(mWorldShader), m_raycaster(mRaycaster),
|
: m_window(mWindow), m_mainImage(mMainImage), m_imageShader(mImageShader), m_worldShader(mWorldShader), m_raycaster(mRaycaster),
|
||||||
m_parser(mParser), m_spiderVAO(mSpiderVao), m_houseVAO(mHouseVao), m_planeVAO(mPlaneVao), m_camera(mCamera) {}
|
m_parser(mParser), m_spiderVAO(mSpiderVao), m_houseVAO(mHouseVao), m_planeVAO(mPlaneVao), m_camera(mCamera), m_world(world) {}
|
||||||
void draw();
|
void draw();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -148,7 +148,7 @@ int main(int argc, char** args) {
|
||||||
auto planeVAO = new VAO(plane.toTriangles());
|
auto planeVAO = new VAO(plane.toTriangles());
|
||||||
Shader shader("../resources/shaders/basic.vs", "../resources/shaders/basic.fs");
|
Shader shader("../resources/shaders/basic.vs", "../resources/shaders/basic.fs");
|
||||||
Shader worldShader("../resources/shaders/world.vs", "../resources/shaders/world.fs");
|
Shader worldShader("../resources/shaders/world.vs", "../resources/shaders/world.fs");
|
||||||
Raytracing::DisplayRenderer renderer {window, mainImage, shader, worldShader, raycaster, parser, spiderVAO, houseVAO, planeVAO, camera};
|
Raytracing::DisplayRenderer renderer {window, mainImage, world, shader, worldShader, raycaster, parser, spiderVAO, houseVAO, planeVAO, camera};
|
||||||
while (!window.shouldWindowClose()) {
|
while (!window.shouldWindowClose()) {
|
||||||
window.beginUpdate();
|
window.beginUpdate();
|
||||||
renderer.draw();
|
renderer.draw();
|
||||||
|
|
|
@ -77,7 +77,7 @@ namespace Raytracing {
|
||||||
* https://medium.com/@bromanz/another-view-on-the-classic-ray-aabb-intersection-algorithm-for-bvh-traversal-41125138b525
|
* https://medium.com/@bromanz/another-view-on-the-classic-ray-aabb-intersection-algorithm-for-bvh-traversal-41125138b525
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool AABB::simpleSlabRayAABBMethod(const Ray& ray, PRECISION_TYPE tmin, PRECISION_TYPE tmax){
|
AABBHitData AABB::simpleSlabRayAABBMethod(const Ray& ray, PRECISION_TYPE tmin, PRECISION_TYPE tmax){
|
||||||
// branch less design
|
// branch less design
|
||||||
// adapted from 2d to fit our 3d scene.
|
// adapted from 2d to fit our 3d scene.
|
||||||
// (turns out this is actually a pretty standard design, but could use some optimization)
|
// (turns out this is actually a pretty standard design, but could use some optimization)
|
||||||
|
@ -87,32 +87,27 @@ namespace Raytracing {
|
||||||
tmin = std::min(tmin, std::min(tx1, tx2));
|
tmin = std::min(tmin, std::min(tx1, tx2));
|
||||||
tmax = std::max(tmax, std::max(tx1, tx2));
|
tmax = std::max(tmax, std::max(tx1, tx2));
|
||||||
|
|
||||||
// gives us an early exit if we know it's outside the bounds.
|
|
||||||
if (tmax <= tmin)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
PRECISION_TYPE ty1 = (min.y() - ray.getStartingPoint().y())*ray.getInverseDirection().y();
|
PRECISION_TYPE ty1 = (min.y() - ray.getStartingPoint().y())*ray.getInverseDirection().y();
|
||||||
PRECISION_TYPE ty2 = (max.y() - ray.getStartingPoint().y())*ray.getInverseDirection().y();
|
PRECISION_TYPE ty2 = (max.y() - ray.getStartingPoint().y())*ray.getInverseDirection().y();
|
||||||
|
|
||||||
tmin = std::max(tmin, std::min(ty1, ty2));
|
tmin = std::max(tmin, std::min(ty1, ty2));
|
||||||
tmax = std::min(tmax, std::max(ty1, ty2));
|
tmax = std::min(tmax, std::max(ty1, ty2));
|
||||||
|
|
||||||
if (tmax <= tmin)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
PRECISION_TYPE tz1 = (min.z() - ray.getStartingPoint().z())*ray.getInverseDirection().z();
|
PRECISION_TYPE tz1 = (min.z() - ray.getStartingPoint().z())*ray.getInverseDirection().z();
|
||||||
PRECISION_TYPE tz2 = (max.z() - ray.getStartingPoint().z())*ray.getInverseDirection().z();
|
PRECISION_TYPE tz2 = (max.z() - ray.getStartingPoint().z())*ray.getInverseDirection().z();
|
||||||
|
|
||||||
tmin = std::max(tmin, std::min(tz1, tz2));
|
tmin = std::max(tmin, std::min(tz1, tz2));
|
||||||
tmax = std::min(tmax, std::max(tz1, tz2));
|
tmax = std::min(tmax, std::max(tz1, tz2));
|
||||||
|
|
||||||
if (tmax <= tmin)
|
tmin = std::max(tmin, 0.0);
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
// TODO: nans?
|
||||||
|
tlog << "TMin: " << tmin << " TMax: " << tmax << " Case: " << (tmax > tmin) << "\n";
|
||||||
|
|
||||||
|
return {tmax > tmin, tmin};
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AABB::intersects(const Ray& ray, PRECISION_TYPE tmin, PRECISION_TYPE tmax) {
|
AABBHitData AABB::intersects(const Ray& ray, PRECISION_TYPE tmin, PRECISION_TYPE tmax) {
|
||||||
return simpleSlabRayAABBMethod(ray, tmin, tmax);
|
return simpleSlabRayAABBMethod(ray, tmin, tmax);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,8 +51,10 @@ namespace Raytracing {
|
||||||
auto y = Vec4{sinYaw * sinPitch, cosPitch, cosYaw * sinPitch}; // right
|
auto y = Vec4{sinYaw * sinPitch, cosPitch, cosYaw * sinPitch}; // right
|
||||||
auto z = Vec4{sinYaw * cosPitch, -sinPitch, cosPitch * cosYaw}; // up
|
auto z = Vec4{sinYaw * cosPitch, -sinPitch, cosPitch * cosYaw}; // up
|
||||||
|
|
||||||
viewportHeight = 1 * tanFovHalf;
|
// we can actually take those x, y, z vectors and use them to compute the raytracer camera settings
|
||||||
|
viewportHeight = 2 * tanFovHalf;
|
||||||
viewportWidth = aspectRatio * viewportHeight;
|
viewportWidth = aspectRatio * viewportHeight;
|
||||||
|
// exactly the same as the look at function.
|
||||||
horizontalAxis = viewportWidth * x;
|
horizontalAxis = viewportWidth * x;
|
||||||
verticalAxis = viewportHeight * y;
|
verticalAxis = viewportHeight * y;
|
||||||
imageOrigin = position - horizontalAxis / 2 - verticalAxis / 2 - z;
|
imageOrigin = position - horizontalAxis / 2 - verticalAxis / 2 - z;
|
||||||
|
|
|
@ -64,7 +64,9 @@ namespace Raytracing {
|
||||||
|
|
||||||
auto intersected = bvhObjects->rayIntersect(ray, min, max);
|
auto intersected = bvhObjects->rayIntersect(ray, min, max);
|
||||||
|
|
||||||
//dlog << "Intersections " << intersected.size() << " " << ray << "\n";
|
//tlog << " Our intersections found: " << intersected.size() << " objs\n";
|
||||||
|
|
||||||
|
//dlog << "Intersections " << intersected.objs.size() << " " << ray << "\n";
|
||||||
|
|
||||||
for (const auto& ptr : intersected) {
|
for (const auto& ptr : intersected) {
|
||||||
auto cResult = ptr.ptr->checkIfHit(ray, min, hResult.length);
|
auto cResult = ptr.ptr->checkIfHit(ray, min, hResult.length);
|
||||||
|
|
|
@ -558,6 +558,16 @@ namespace Raytracing {
|
||||||
|
|
||||||
m_camera.setPosition(m_camera.getPosition() + Vec4{deltaX, deltaY, deltaZ});
|
m_camera.setPosition(m_camera.getPosition() + Vec4{deltaX, deltaY, deltaZ});
|
||||||
}
|
}
|
||||||
|
if (Input::isKeyDown(GLFW_KEY_E) && Input::isState(GLFW_KEY_E)) {
|
||||||
|
auto ray = m_camera.projectRay((PRECISION_TYPE) m_window.displayWidth() / 2, (PRECISION_TYPE) m_window.displayHeight() / 2);
|
||||||
|
|
||||||
|
auto results = m_world.checkIfHit(ray, 0, 1000).first;
|
||||||
|
auto bvh = m_world.getBVH()->rayIntersect(ray, 0, 1000);
|
||||||
|
ilog << "World Results: " << results.hit << " " << results.hitPoint << " " << results.length << "\n";
|
||||||
|
ilog << "BVH Results: " << bvh.size() << " " << bvh[0].ptr->getPosition() << "\n";
|
||||||
|
}
|
||||||
|
if (Input::isKeyDown(GLFW_KEY_R) && Input::isState(GLFW_KEY_R))
|
||||||
|
m_world.getBVH()->resetNodes();
|
||||||
auto view = m_camera.view(yaw, pitch);
|
auto view = m_camera.view(yaw, pitch);
|
||||||
m_worldShader.setMatrix("projectMatrix", projection);
|
m_worldShader.setMatrix("projectMatrix", projection);
|
||||||
m_worldShader.setMatrix("viewMatrix", view);
|
m_worldShader.setMatrix("viewMatrix", view);
|
||||||
|
|
Loading…
Reference in New Issue