Path Tracing
Loading...
Searching...
No Matches
bvh.hpp File Reference

Bounding Volume Hierarchy construction and upload. More...

#include <vector>
#include <cstddef>
#include <GL/glew.h>
#include <glm/glm.hpp>
#include "mesh.hpp"
Include dependency graph for bvh.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  BVHNode
 A single node of the BVH, structured following the std430. More...

Functions

bool buildBVH (vector< GPUTriangle > &triangles, vector< BVHNode > &bvh_nodes)
 Builds the BVH using a triangle list. Recursively splits each triangle node at median along the longest axis of its AABB, reorders triangles in place so each leaf references a range. The resulting array is written to bvh_noes with root at index 0.
bool uploadBVH (const vector< BVHNode > &bvh_nodes, GLuint &ssbo)
 Uploads the BVH node array to GPU SSBO. Creates the buffer on first use and fills it with bvh_nodes. The shader reads this buffer starting from the root idx 0.

Variables

const float AABB_EPS = 1e-4f
 Smap epsilon used to pad AABBs and avoid near-zero thickness.

Detailed Description

Bounding Volume Hierarchy construction and upload.

Author
Leonel Matos
Date
2026-04-02

Function Documentation

◆ buildBVH()

bool buildBVH ( vector< GPUTriangle > & triangles,
vector< BVHNode > & bvh_nodes )

Builds the BVH using a triangle list. Recursively splits each triangle node at median along the longest axis of its AABB, reorders triangles in place so each leaf references a range. The resulting array is written to bvh_noes with root at index 0.

Parameters
trianglesIn-out triangle buffer
bvh_nodesOutput flattened node array
Returns
true on success

◆ uploadBVH()

bool uploadBVH ( const vector< BVHNode > & bvh_nodes,
GLuint & ssbo )

Uploads the BVH node array to GPU SSBO. Creates the buffer on first use and fills it with bvh_nodes. The shader reads this buffer starting from the root idx 0.

Parameters
bvh_nodesThe node array produced by buildBVH
ssboIn-out SSBO handle, created if zero
Returns
true on success
See also
buildBVH

Variable Documentation

◆ AABB_EPS

const float AABB_EPS = 1e-4f

Smap epsilon used to pad AABBs and avoid near-zero thickness.