Raytracer and Debug views now align

main
Brett 2022-11-15 16:23:37 -05:00
parent 4c9e4b6787
commit c881b780ff
19 changed files with 147 additions and 89 deletions

View File

@ -2,53 +2,66 @@
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
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
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 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
2 1171 1668539611850637805 CMakeFiles/Step_3.dir/src/engine/globals.cpp.o 4ef77d2224f86511
1 818 1668545258765546884 CMakeFiles/Step_3.dir/src/engine/math/colliders.cpp.o 39e9f435096d066b
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
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
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
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
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
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
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
1 1595 1668546503513487557 CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o ce988de97a5cb51d
1596 1677 1668546503593489763 Step_3 f055ce2b85635598
1 1667 1668546613472534906 CMakeFiles/Step_3.dir/src/engine/util/models.cpp.o 164394d360c43072
1 1765 1668546613568537578 CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o ce988de97a5cb51d
1 2011 1668546613816544487 CMakeFiles/Step_3.dir/src/engine/raytracing.cpp.o 11f0e227e9fda9ca
1 2634 1668546614440561861 CMakeFiles/Step_3.dir/src/engine/world.cpp.o 6470df278966c4
1 2839 1668546614644567542 CMakeFiles/Step_3.dir/src/engine/main.cpp.o 641dce3f86933e2e
2840 2924 1668546614728569881 Step_3 f055ce2b85635598
2 1503 1668546664905969925 CMakeFiles/Step_3.dir/src/engine/util/models.cpp.o 164394d360c43072
2 1774 1668546665177977529 CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o ce988de97a5cb51d
1 1837 1668546665241979318 CMakeFiles/Step_3.dir/src/engine/raytracing.cpp.o 11f0e227e9fda9ca
2 2200 1668546665605989494 CMakeFiles/Step_3.dir/src/engine/world.cpp.o 6470df278966c4
1 2541 1668546665945998998 CMakeFiles/Step_3.dir/src/engine/main.cpp.o 641dce3f86933e2e
2541 2621 1668546666026001236 Step_3 f055ce2b85635598
2 1815 1668546866179632251 CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o ce988de97a5cb51d
2 1821 1668546866187632477 CMakeFiles/Step_3.dir/src/engine/util/models.cpp.o 164394d360c43072
2 1885 1668546866251634287 CMakeFiles/Step_3.dir/src/engine/world.cpp.o 6470df278966c4
2 2159 1668546866523641982 CMakeFiles/Step_3.dir/src/engine/raytracing.cpp.o 11f0e227e9fda9ca
1 2761 1668546867127659070 CMakeFiles/Step_3.dir/src/engine/main.cpp.o 641dce3f86933e2e
2761 2826 1668546867191660882 Step_3 f055ce2b85635598
1 1633 1668546918285108046 CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o ce988de97a5cb51d
1 1633 1668546918285108046 CMakeFiles/Step_3.dir/src/engine/util/models.cpp.o 164394d360c43072
1 1915 1668546918565115986 CMakeFiles/Step_3.dir/src/engine/world.cpp.o 6470df278966c4
1 1997 1668546918649118365 CMakeFiles/Step_3.dir/src/engine/raytracing.cpp.o 11f0e227e9fda9ca
1 2691 1668546919341137991 CMakeFiles/Step_3.dir/src/engine/main.cpp.o 641dce3f86933e2e
2691 2758 1668546919409139920 Step_3 f055ce2b85635598
1 983 1668547097978221140 CMakeFiles/Step_3.dir/src/engine/math/colliders.cpp.o 39e9f435096d066b
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.

View File

@ -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

View File

@ -9,7 +9,7 @@ Size=550,680
Collapsed=1
[Window][Debug Menu]
Pos=-6,23
Pos=35,13
Size=339,226
Collapsed=0
@ -74,7 +74,7 @@ Size=324,211
Collapsed=0
[Window][BVH Data ]
Pos=913,184
Pos=897,115
Size=522,476
Collapsed=0

View File

@ -53,21 +53,56 @@ namespace Raytracing {
return transform;
}
public:
struct BVHHitData {
BVHNode* ptr;
AABBHitData data;
bool hit = false;
};
std::vector<BVHObject> objs;
AABB aabb;
BVHNode* left;
BVHNode* right;
int index;
int hit = 0;
BVHNode(std::vector<BVHObject> objs, AABB aabb, BVHNode* left, BVHNode* right): objs(std::move(objs)), aabb(std::move(aabb)),
left(left), right(right) {
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
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("", ImVec2(250, 350))) {
if (selected == index || hit) {
if (hit == 1)
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;
strs << aabb;
ImGui::Text("%s", strs.str().c_str());
@ -124,7 +159,6 @@ namespace Raytracing {
class BVHTree {
private:
const int MAX_TREE_DEPTH = 50;
BVHNode* root = nullptr;
// splits the objs in the vector based on the provided AABBs
@ -174,10 +208,6 @@ namespace Raytracing {
return new BVHNode(objects, world, nullptr, nullptr);
} else if (objects.empty()) // should never reach here!!
return nullptr;
elog << partitionedObjs.left.size() << " :: " << partitionedObjs.right.size() << "\n";
BVHNode* left = nullptr;
BVHNode* right = nullptr;
@ -189,23 +219,6 @@ namespace Raytracing {
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
void drawNodesRecur(Shader& worldShader, BVHNode* node) {
node->draw(worldShader);
@ -222,6 +235,13 @@ namespace Raytracing {
guiNodesRecur(node->right);
}
#endif
void reset(BVHNode* node){
if (node == nullptr)
return;
node->hit = false;
reset(node->left);
reset(node->right);
}
public:
std::vector<Object*> noAABBObjects;
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) {
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

View File

@ -10,6 +10,11 @@
namespace Raytracing {
// 3D Axis Aligned Bounding Box for use in a BVH
struct AABBHitData {
bool hit;
PRECISION_TYPE tMax;
};
class AABB {
protected:
Vec4 min;
@ -68,9 +73,9 @@ namespace Raytracing {
[[nodiscard]] inline bool intersects(const AABB& other) const {
return intersects(other.min, other.max);
}
bool intersects(const Ray& ray, PRECISION_TYPE tmin, PRECISION_TYPE tmax);
bool simpleSlabRayAABBMethod(const Ray& ray, PRECISION_TYPE tmin, PRECISION_TYPE tmax);
AABBHitData intersects(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 {
return x >= min.x() && x <= max.x() && y >= min.y() && y <= max.y() && z >= min.z() && z <= max.z();

View File

@ -135,6 +135,7 @@ namespace Raytracing {
inline void addMaterial(const std::string& materialName, Material* mat) { materials.insert({materialName, mat}); }
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;
~World();

View File

@ -68,6 +68,8 @@ namespace Raytracing {
void setMouseGrabbed(bool grabbed);
bool isMouseGrabbed();
[[nodiscard]] inline int displayWidth() const {return m_displayWidth;}
[[nodiscard]] inline int displayHeight() const {return m_displayHeight;}
void closeWindow();
~XWindow();
@ -132,6 +134,7 @@ namespace Raytracing {
private:
XWindow& m_window;
Texture& m_mainImage;
World& m_world;
Shader& m_imageShader;
Shader& m_worldShader;
Raycaster& m_raycaster;
@ -143,6 +146,7 @@ namespace Raytracing {
public:
DisplayRenderer(XWindow& mWindow,
Texture& mMainImage,
World& world,
Shader& mImageShader,
Shader& mWorldShader,
Raycaster& mRaycaster,
@ -152,7 +156,7 @@ namespace Raytracing {
VAO* mPlaneVao,
Camera& mCamera)
: 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();
};
}

View File

@ -148,7 +148,7 @@ int main(int argc, char** args) {
auto planeVAO = new VAO(plane.toTriangles());
Shader shader("../resources/shaders/basic.vs", "../resources/shaders/basic.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()) {
window.beginUpdate();
renderer.draw();

View File

@ -77,7 +77,7 @@ namespace Raytracing {
* 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
// adapted from 2d to fit our 3d scene.
// (turns out this is actually a pretty standard design, but could use some optimization)
@ -86,33 +86,28 @@ namespace Raytracing {
tmin = std::min(tmin, std::min(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 ty2 = (max.y() - ray.getStartingPoint().y())*ray.getInverseDirection().y();
tmin = std::max(tmin, std::min(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 tz2 = (max.z() - ray.getStartingPoint().z())*ray.getInverseDirection().z();
tmin = std::max(tmin, std::min(tz1, tz2));
tmax = std::min(tmax, std::max(tz1, tz2));
if (tmax <= tmin)
return false;
return true;
tmin = std::max(tmin, 0.0);
// 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);
}

View File

@ -51,8 +51,10 @@ namespace Raytracing {
auto y = Vec4{sinYaw * sinPitch, cosPitch, cosYaw * sinPitch}; // right
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;
// exactly the same as the look at function.
horizontalAxis = viewportWidth * x;
verticalAxis = viewportHeight * y;
imageOrigin = position - horizontalAxis / 2 - verticalAxis / 2 - z;

View File

@ -64,7 +64,9 @@ namespace Raytracing {
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) {
auto cResult = ptr.ptr->checkIfHit(ray, min, hResult.length);

View File

@ -558,6 +558,16 @@ namespace Raytracing {
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);
m_worldShader.setMatrix("projectMatrix", projection);
m_worldShader.setMatrix("viewMatrix", view);