~ | small fix in topbvh stats calculation

This commit is contained in:
TheRedShip
2025-01-23 16:04:34 +01:00
parent 6b7523724d
commit baf8d9cbd3
2 changed files with 9 additions and 10 deletions

View File

@ -20,8 +20,8 @@ int main(int argc, char **argv)
return (1); return (1);
Window window(&scene, WIDTH, HEIGHT, "RT_GPU", 0); Window window(&scene, WIDTH, HEIGHT, "RT_GPU", 0);
Shader shader("shaders/vertex.vert", "shaders/frag.frag", "shaders/compute.glsl"); // Shader shader("shaders/vertex.vert", "shaders/frag.frag", "shaders/compute.glsl");
// Shader shader("shaders/vertex.vert", "shaders/frag.frag", "shaders/debug.glsl"); Shader shader("shaders/vertex.vert", "shaders/frag.frag", "shaders/debug.glsl");
GLint max_gpu_size; GLint max_gpu_size;
glGetIntegerv(GL_MAX_SHADER_STORAGE_BLOCK_SIZE, &max_gpu_size); glGetIntegerv(GL_MAX_SHADER_STORAGE_BLOCK_SIZE, &max_gpu_size);

View File

@ -237,21 +237,20 @@ TopBVHStats TopBVH::analyzeBVHLeaves()
// Get stats from left and right subtrees // Get stats from left and right subtrees
TopBVHStats left = _left->analyzeBVHLeaves(); TopBVHStats left = _left->analyzeBVHLeaves();
TopBVHStats right = _left->analyzeBVHLeaves(); TopBVHStats right = _right->analyzeBVHLeaves();
// Combine the results // Combine the results
int min_count = std::min(left.min_bvh, right.min_bvh); int min_count = std::min(left.min_bvh, right.min_bvh);
int max_count = std::max(left.max_bvh, right.max_bvh); int max_count = std::max(left.max_bvh, right.max_bvh);
// Calculate weighted average based on number of leaves in each subtree // Calculate weighted average based on number of leaves in each subtree
float left_leaf_count = (left.average_bvh > 0) ? 1.0f : 0.0f; float left_weighted = left.average_bvh * (left.max_bvh - left.min_bvh + 1);
float right_leaf_count = (right.average_bvh > 0) ? 1.0f : 0.0f; float right_weighted = right.average_bvh * (right.max_bvh - right.min_bvh + 1);
float total_leaf_count = left_leaf_count + right_leaf_count; int total_count = (left.max_bvh - left.min_bvh + 1) + (right.max_bvh - right.min_bvh + 1);
float avg_count = 0.0f; float avg_count = 0.0f;
if (total_leaf_count > 0) if (total_count > 0)
avg_count = (left.average_bvh * left_leaf_count + avg_count = (left_weighted + right_weighted) / total_count;
right.average_bvh * right_leaf_count) / total_leaf_count;
return {min_count, max_count, avg_count}; return {min_count, max_count, avg_count};
} }