Path Tracing
Loading...
Searching...
No Matches
bvh.hpp
Go to the documentation of this file.
1
10
11#pragma once
12
13#include <vector>
14#include <cstddef>
15#include <GL/glew.h>
16#include <glm/glm.hpp>
17#include "mesh.hpp"
18
20const float AABB_EPS = 1e-4f;
21
32struct BVHNode {
33 vec3 aabb_min;
34 float _pad0;
35 vec3 aabb_max;
36 float _pad1;
37 int left_child;
38 int right_child;
39 int first_tri;
40 int tri_count;
41};
42static_assert(sizeof(BVHNode) == 48, "BVHNode must match the std430 layout in globals.glsl");
43static_assert(offsetof(BVHNode, aabb_max) == 16, "BVHNode.aabb_max offset must match globals.glsl");
44static_assert(offsetof(BVHNode, left_child) == 32, "BVHNode.left_child offset must match globals.glsl");
45
56bool buildBVH(vector<GPUTriangle>& triangles, vector<BVHNode>& bvh_nodes);
57
67bool uploadBVH(const vector<BVHNode>& bvh_nodes, GLuint& ssbo);
const float AABB_EPS
Smap epsilon used to pad AABBs and avoid near-zero thickness.
Definition bvh.hpp:20
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....
Definition bvh.cpp:120
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 longe...
Definition bvh.cpp:97
unsigned int GLuint
Definition imgui_impl_opengl3_loader.h:147
Loads 3D models through ASSIMP into CPU-side geometry and material data, defines the GPUVertex/GPUTri...
A single node of the BVH, structured following the std430.
Definition globals.glsl:323
float _pad0
Definition globals.glsl:325
int right_child
Definition globals.glsl:329
vec3 aabb_max
Definition globals.glsl:326
int first_tri
Definition globals.glsl:330
vec3 aabb_min
Definition globals.glsl:324
int tri_count
Definition globals.glsl:331
float _pad1
Definition globals.glsl:327
int left_child
Definition globals.glsl:328