+ | TopLevel builded

This commit is contained in:
TheRedShip
2025-01-21 22:53:42 +01:00
parent 896cd02e45
commit 83fed19862
12 changed files with 236 additions and 73 deletions

View File

@ -62,7 +62,25 @@ struct Vertex {
# include "Scene.hpp"
# include "SceneParser.hpp"
# include "ObjParser.hpp"
struct AABB
{
glm::vec3 min;
glm::vec3 max;
AABB(glm::vec3 min, glm::vec3 max) : min(min), max(max) {}
void grow( glm::vec3 p ) { min = glm::min( min, p ), max = glm::max( max, p ); }
float area()
{
glm::vec3 e = max - min;
return (e.x * e.y + e.y * e.z + e.z * e.x);
}
};
# include "BVH.hpp"
# include "TopBVH.hpp"

View File

@ -18,22 +18,7 @@
struct GPUTriangle;
struct GPUObject;
struct GPUBvh;
struct AABB
{
glm::vec3 min;
glm::vec3 max;
AABB(glm::vec3 min, glm::vec3 max) : min(min), max(max) {}
void grow( glm::vec3 p ) { min = glm::min( min, p ), max = glm::max( max, p ); }
float area()
{
glm::vec3 e = max - min;
return (e.x * e.y + e.y * e.z + e.z * e.x);
}
};
struct AABB;
struct BVHStats
{

54
includes/RT/TopBVH.hpp Normal file
View File

@ -0,0 +1,54 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* TopBVH.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/16 21:36:19 by TheRed #+# #+# */
/* Updated: 2025/01/17 18:59:28 by ycontre ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef RT_TOPBVH__HPP
# define RT_TOPBVH__HPP
# include "RT.hpp"
struct GPUBvhData;
struct GPUTopBvh;
struct AABB;
class TopBVH
{
public:
TopBVH(std::vector<GPUBvhData> &bvhs_data, std::vector<GPUBvh> &bvhs, int first_bvh, int bvh_count);
void updateBounds(std::vector<GPUBvhData> &bvhs_data, std::vector<GPUBvh> &bvhs);
void subdivide(std::vector<GPUBvhData> &bvhs_data, std::vector<GPUBvh> &bvhs);
float evaluateSah(std::vector<GPUBvhData> &bvhs_data, std::vector<GPUBvh> &bvhs, int axis, float pos);
// int getSize();
// int getLeaves();
// void flatten(std::vector<GPUTopBVH> &TopBVHs, int &currentIndex);
// GPUTopBVH toGPUTopBVH();
// const AABB &getAABB() const;
// std::vector<GPUTopBVH> getGPUTopBVHs();
private:
AABB _aabb;
TopBVH *_left;
TopBVH *_right;
bool _is_leaf;
int _first_bvh;
int _bvh_count;
};
#endif