mirror of
https://github.com/TheRedShip/RT_GPU.git
synced 2025-09-27 18:48:36 +02:00
+ | Multiple obj using multiple BVH
This commit is contained in:
@ -28,7 +28,7 @@ struct AABB
|
||||
|
||||
void grow( glm::vec3 p ) { min = glm::min( min, p ), max = glm::max( max, p ); }
|
||||
|
||||
float area()
|
||||
float area()
|
||||
{
|
||||
glm::vec3 e = max - min;
|
||||
return (e.x * e.y + e.y * e.z + e.z * e.x);
|
||||
@ -45,15 +45,13 @@ struct BVHStats
|
||||
class BVH
|
||||
{
|
||||
public:
|
||||
BVH(std::vector<GPUTriangle> &primitives, int first_primitive, int primitive_count);
|
||||
BVH(std::vector<Triangle> &triangles, int first_primitive, int primitive_count);
|
||||
|
||||
|
||||
void showAABB(Scene *scene);
|
||||
|
||||
void updateBounds(std::vector <GPUTriangle> &primitives);
|
||||
void subdivide(std::vector<GPUTriangle> &primitives);
|
||||
void updateBounds(std::vector<Triangle> &triangles);
|
||||
void subdivide(std::vector<Triangle> &triangles);
|
||||
|
||||
float evaluateSah(std::vector<GPUTriangle> &primitives, int axis, float pos);
|
||||
float evaluateSah(std::vector<Triangle> &triangles, int axis, float pos);
|
||||
|
||||
int getSize();
|
||||
int getLeaves();
|
||||
|
@ -39,6 +39,8 @@ class ObjParser
|
||||
std::vector<glm::vec2> _textureVertices;
|
||||
int _mat;
|
||||
std::map<std::string, int> _matNames;
|
||||
|
||||
std::vector<Triangle> _triangles;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -86,6 +86,14 @@ struct GPUBvh
|
||||
int primitive_count;
|
||||
};
|
||||
|
||||
struct GPUBvhData
|
||||
{
|
||||
alignas(16) glm::vec3 offset;
|
||||
|
||||
int bvh_start_index;
|
||||
int triangle_start_index;
|
||||
};
|
||||
|
||||
class Sphere;
|
||||
class Camera;
|
||||
|
||||
@ -103,11 +111,15 @@ class Scene
|
||||
void updateLightAndObjects(int mat_id);
|
||||
std::set<int> getGPULights();
|
||||
|
||||
void addBvh(std::vector<Triangle> &triangles);
|
||||
|
||||
const std::vector<GPUObject> &getObjectData() const;
|
||||
const std::vector<GPUTriangle> &getTriangleData() const;
|
||||
|
||||
std::vector<GPUMaterial> &getMaterialData();
|
||||
std::vector<GPUBvh> &getBVH();
|
||||
|
||||
std::vector<GPUBvhData> &getBvhData();
|
||||
std::vector<GPUBvh> &getBvh();
|
||||
|
||||
GPUVolume &getVolume();
|
||||
GPUDebug &getDebug();
|
||||
@ -116,6 +128,7 @@ class Scene
|
||||
GPUMaterial getMaterial(int material_index);
|
||||
|
||||
private:
|
||||
std::vector<GPUBvhData> _gpu_bvh_data;
|
||||
std::vector<GPUBvh> _gpu_bvh;
|
||||
|
||||
std::vector<GPUObject> _gpu_objects;
|
||||
|
@ -46,6 +46,7 @@ class Triangle : public Object
|
||||
// _vertex3 -= _position; //optimization
|
||||
|
||||
_normal = glm::normalize(glm::cross(_vertex2 - _position, _vertex3 - _position)); //optimization
|
||||
_centroid = (_position + _vertex2 + _vertex3) / 3.0f;
|
||||
|
||||
_mat_index = mat_index;
|
||||
}
|
||||
@ -55,11 +56,14 @@ class Triangle : public Object
|
||||
// _vertex3 -= _position; //optimization
|
||||
|
||||
_normal = glm::normalize(glm::cross(_vertex2 - _position, _vertex3 - _position)); //optimization
|
||||
_centroid = (_position + _vertex2 + _vertex3) / 3.0f;
|
||||
}
|
||||
|
||||
const glm::vec3 &getVertex2() const { return (_vertex2); }
|
||||
const glm::vec3 &getVertex3() const { return (_vertex3); }
|
||||
const glm::vec3 &getNormal() const { return (_normal); }
|
||||
const glm::vec3 &getCentroid() const { return (_centroid); }
|
||||
|
||||
|
||||
Type getType() const override { return Type::TRIANGLE; }
|
||||
|
||||
@ -68,6 +72,8 @@ class Triangle : public Object
|
||||
glm::vec3 _vertex3;
|
||||
|
||||
glm::vec3 _normal;
|
||||
|
||||
glm::vec3 _centroid;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user