35 lines
1.1 KiB
C
35 lines
1.1 KiB
C
#ifndef BVH_H
|
|
#define BVH_H
|
|
|
|
#include "Geometry/AABB.h"
|
|
#include "Geometry/Triangle.h"
|
|
|
|
#define SAH_BIN_COUNT 8 // Number of bins for SAH
|
|
#define SAH_TRAVERSAL_COST 1.0f // Cost of traversing a node
|
|
#define SAH_INTERSECTION_COST 10.0f // Cost of intersecting a triangle
|
|
|
|
typedef struct
|
|
{
|
|
aabb_t bounds;
|
|
uint32_t start_index;
|
|
uint32_t primitive_count;
|
|
uint32_t left_child_offset;
|
|
uint32_t right_child_offset;
|
|
} bvh_node_t;
|
|
|
|
typedef struct bvh_tree_t
|
|
{
|
|
bvh_node_t* nodes;
|
|
uint32_t* primitive_indices; // Buffer of indices mapping to the original triangle_collection_t buffer
|
|
const triangle_list_t* triangles; // Pointer to the original triangle data (read-only access)
|
|
uint32_t node_count; // Current number of nodes used
|
|
uint32_t node_capacity; // Allocated capacity for nodes
|
|
uint32_t primitive_count; // Total number of primitives (should match triangles->count)
|
|
} bvh_tree_t;
|
|
|
|
bool bvh_tree_init(bvh_tree_t* bvh_tree, const triangle_list_t* triangles);
|
|
bool bvh_tree_build(bvh_tree_t* bvh_tree);
|
|
void bvh_tree_free(bvh_tree_t* bvh_tree);
|
|
|
|
#endif // BVH_H
|