From 13acb0321b5f2ed392c94e1f7c64069d4242971a Mon Sep 17 00:00:00 2001 From: ladevieq Date: Mon, 11 Jul 2022 09:08:45 +0200 Subject: Refactor bvh file --- include/bvh.hpp | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 include/bvh.hpp (limited to 'include/bvh.hpp') diff --git a/include/bvh.hpp b/include/bvh.hpp new file mode 100644 index 0000000..ba847c1 --- /dev/null +++ b/include/bvh.hpp @@ -0,0 +1,60 @@ +#pragma once + +#include + +#include "aabb.hpp" +// #include "sphere.hpp" +#include "triangle.hpp" + +struct bvh_node { + aabb bounding_box; + + int32_t next_id = -1; + int32_t primitive_id = -1; + uint32_t padding[2]; +}; + +struct packed_bvh_node { + float min[3]; + int32_t next_id = -1; + float max[3]; + int32_t primitive_id = -1; +}; + +struct temp_node : public bvh_node { + int32_t left_id; + int32_t df_id; // depth firt id +}; + +class bvh { +public: + // bvh(std::vector& spheres, std::vector& packed_nodes); + + bvh(std::vector& triangles, std::vector& packed_nodes); + + void exporter(); + + static bool traverse_depth_first(std::vector& nodes, int32_t id); + + static int32_t traverse_depth_first_ordered(std::vector& nodes, int32_t parent_id, int32_t id); + + std::vector temp_nodes; + std::vector leafs; + + // std::vector& spheres; + std::vector& triangles; + + uint32_t next_node_id = 0; + +private: + + static constexpr uint32_t buckets_count = 12; + + aabb compute_bounds(uint32_t begin, uint32_t end); + + void subdivide(uint32_t parent_id, uint32_t begin, uint32_t end); + + void set_depth_first_order(); + + void depth_first_order(int32_t id, int32_t next_id, int32_t &new_id); +}; -- cgit v1.3