mirror of
https://github.com/TheRedShip/RT_GPU.git
synced 2025-09-27 18:48:36 +02:00
~ | BVH sent to gpu
This commit is contained in:
@ -15,6 +15,9 @@
|
||||
|
||||
# include "RT.hpp"
|
||||
|
||||
struct GPUObject;
|
||||
struct GPUBvh;
|
||||
|
||||
struct AABB
|
||||
{
|
||||
glm::vec3 min;
|
||||
@ -23,7 +26,6 @@ struct AABB
|
||||
AABB(glm::vec3 min, glm::vec3 max) : min(min), max(max) {}
|
||||
};
|
||||
|
||||
struct GPUObject;
|
||||
|
||||
class BVH
|
||||
{
|
||||
@ -36,7 +38,13 @@ class BVH
|
||||
void updateBounds(std::vector<GPUObject> primitives);
|
||||
void subdivide(std::vector<GPUObject> primitives);
|
||||
|
||||
const AABB &getAABB() const;
|
||||
int size();
|
||||
|
||||
void flatten(std::vector<GPUBvh> &bvhs, int ¤tIndex);
|
||||
GPUBvh toGPUBvh();
|
||||
|
||||
const AABB &getAABB() const;
|
||||
std::vector<GPUBvh> getGPUBvhs();
|
||||
|
||||
|
||||
private:
|
||||
|
@ -54,6 +54,20 @@ struct GPUVolume
|
||||
int enabled;
|
||||
};
|
||||
|
||||
struct GPUBvh
|
||||
{
|
||||
alignas(16) glm::vec3 min;
|
||||
alignas(16) glm::vec3 max;
|
||||
|
||||
int left_index;
|
||||
int right_index;
|
||||
|
||||
int is_leaf;
|
||||
|
||||
int first_primitive;
|
||||
int primitive_count;
|
||||
};
|
||||
|
||||
class Sphere;
|
||||
class Camera;
|
||||
|
||||
@ -74,11 +88,14 @@ class Scene
|
||||
const std::vector<GPUObject> &getObjectData() const;
|
||||
std::vector<GPUMaterial> &getMaterialData();
|
||||
GPUVolume &getVolume();
|
||||
std::vector<GPUBvh> &getBVH();
|
||||
|
||||
Camera *getCamera(void) const;
|
||||
GPUMaterial getMaterial(int material_index);
|
||||
|
||||
private:
|
||||
std::vector<GPUBvh> _gpu_bvh;
|
||||
|
||||
std::vector<GPUObject> _gpu_objects;
|
||||
std::vector<GPUMaterial> _gpu_materials;
|
||||
|
||||
|
@ -25,8 +25,6 @@ class Shader
|
||||
void setupVertexBuffer(const Vertex* vertices, size_t size);
|
||||
void drawTriangles(size_t size);
|
||||
|
||||
|
||||
|
||||
// void setBool(const std::string &name, bool value) const;
|
||||
void set_int(const std::string &name, int value) const;
|
||||
void set_float(const std::string &name, float value) const;
|
||||
|
@ -42,8 +42,8 @@ class Triangle : public Object
|
||||
_vertex2 = glm::vec3(x2, y2, z2);
|
||||
_vertex3 = glm::vec3(x3, y3, z3);
|
||||
|
||||
_vertex2 -= _position; //optimization
|
||||
_vertex3 -= _position; //optimization
|
||||
// _vertex2 -= _position; //optimization
|
||||
// _vertex3 -= _position; //optimization
|
||||
|
||||
_normal = glm::normalize(glm::cross(_vertex2, _vertex3)); //optimization
|
||||
|
||||
@ -51,8 +51,8 @@ class Triangle : public Object
|
||||
}
|
||||
Triangle(const glm::vec3& position, const glm::vec3& vertex2, const glm::vec3& vertex3, const int mat_index)
|
||||
: Object(position, mat_index), _vertex2(vertex2), _vertex3(vertex3) {
|
||||
_vertex2 -= _position; //optimization
|
||||
_vertex3 -= _position; //optimization
|
||||
// _vertex2 -= _position; //optimization
|
||||
// _vertex3 -= _position; //optimization
|
||||
|
||||
_normal = glm::normalize(glm::cross(_vertex2, _vertex3)); //optimization
|
||||
}
|
||||
|
Reference in New Issue
Block a user