diff --git a/imgui.ini b/imgui.ini index e0f3220..159791e 100644 --- a/imgui.ini +++ b/imgui.ini @@ -3,17 +3,16 @@ Pos=60,60 Size=400,400 [Window][Camera] -Pos=1643,7 +Pos=1277,16 Size=259,200 -Collapsed=1 [Window][Material] -Pos=1642,29 +Pos=927,29 Size=266,299 Collapsed=1 [Window][Fog settings] -Pos=1641,52 +Pos=927,52 Size=247,130 Collapsed=1 @@ -22,7 +21,7 @@ Pos=1642,668 Size=260,143 [Window][Debug BVH] -Pos=1641,72 +Pos=927,72 Size=274,205 Collapsed=1 diff --git a/includes/RT/Scene.hpp b/includes/RT/Scene.hpp index b415627..9a8d2df 100644 --- a/includes/RT/Scene.hpp +++ b/includes/RT/Scene.hpp @@ -6,7 +6,7 @@ /* By: ycontre +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/12/23 18:30:18 by ycontre #+# #+# */ -/* Updated: 2025/01/24 19:35:52 by ycontre ### ########.fr */ +/* Updated: 2025/01/25 14:10:19 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -77,10 +77,7 @@ struct GPUBvh alignas(16) glm::vec3 min; alignas(16) glm::vec3 max; - int left_index; - int right_index; - - int first_primitive; + int index; int primitive_count; }; @@ -146,4 +143,4 @@ class Scene Camera *_camera; }; -#endif \ No newline at end of file +#endif diff --git a/shaders/compute.glsl b/shaders/compute.glsl index 6aa1f85..87886fa 100644 --- a/shaders/compute.glsl +++ b/shaders/compute.glsl @@ -78,10 +78,7 @@ struct GPUBvh vec3 min; vec3 max; - int left_index; - int right_index; - - int first_primitive; + int index; int primitive_count; }; diff --git a/shaders/trace.glsl b/shaders/trace.glsl index 8616d0c..a8bfa15 100644 --- a/shaders/trace.glsl +++ b/shaders/trace.glsl @@ -75,14 +75,14 @@ hitInfo traceBVH(Ray ray, GPUBvhData bvh_data) { for (int i = 0; i < node.primitive_count; i++) { - GPUTriangle obj = triangles[bvh_data.triangle_start_index + node.first_primitive + i]; + GPUTriangle obj = triangles[bvh_data.triangle_start_index + node.index + i]; hitInfo temp_hit; if (intersectTriangle(ray, obj, temp_hit) && temp_hit.t < hit.t) { hit.t = temp_hit.t; hit.last_t = temp_hit.last_t; - hit.obj_index = bvh_data.triangle_start_index + node.first_primitive + i; + hit.obj_index = bvh_data.triangle_start_index + node.index + i; hit.mat_index = obj.mat_index; hit.position = temp_hit.position; hit.normal = temp_hit.normal; @@ -91,8 +91,8 @@ hitInfo traceBVH(Ray ray, GPUBvhData bvh_data) } else { - GPUBvh left_node = Bvh[bvh_data.bvh_start_index + node.left_index]; - GPUBvh right_node = Bvh[bvh_data.bvh_start_index + node.right_index]; + GPUBvh left_node = Bvh[bvh_data.bvh_start_index + current_index + 1]; + GPUBvh right_node = Bvh[bvh_data.bvh_start_index + node.index]; hitInfo left_hit; hitInfo right_hit; @@ -105,13 +105,13 @@ hitInfo traceBVH(Ray ray, GPUBvhData bvh_data) if (left_hit.t > right_hit.t) { - if (left_hit.t < hit.t && left_bool) stack[++stack_ptr] = node.left_index; - if (right_hit.t < hit.t && right_bool) stack[++stack_ptr] = node.right_index; + if (left_hit.t < hit.t && left_bool) stack[++stack_ptr] = current_index + 1; + if (right_hit.t < hit.t && right_bool) stack[++stack_ptr] = node.index; } else { - if (right_hit.t < hit.t && right_bool) stack[++stack_ptr] = node.right_index; - if (left_hit.t < hit.t && left_bool) stack[++stack_ptr] = node.left_index; + if (right_hit.t < hit.t && right_bool) stack[++stack_ptr] = node.index; + if (left_hit.t < hit.t && left_bool) stack[++stack_ptr] = current_index + 1; } } } @@ -179,4 +179,4 @@ hitInfo traceRay(Ray ray) } return (hit); -} \ No newline at end of file +} diff --git a/srcs/class/BVH.cpp b/srcs/class/BVH.cpp index e1f156b..718fc3a 100644 --- a/srcs/class/BVH.cpp +++ b/srcs/class/BVH.cpp @@ -6,7 +6,7 @@ /* By: ycontre +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/01/16 21:48:48 by TheRed #+# #+# */ -/* Updated: 2025/01/24 19:36:07 by ycontre ### ########.fr */ +/* Updated: 2025/01/25 14:25:57 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -146,7 +146,7 @@ GPUBvh BVH::toGPUBvh() { GPUBvh bvh; - bvh.first_primitive = _first_primitive; + bvh.index = _first_primitive; bvh.primitive_count = _primitive_count; bvh.max = _aabb.max; bvh.min = _aabb.min; @@ -159,15 +159,11 @@ void BVH::flatten(std::vector &bvhs, int ¤tIndex) GPUBvh self_bvh = toGPUBvh(); int self_index = currentIndex++; - self_bvh.left_index = -1; - self_bvh.right_index = -1; - if (!_is_leaf) { - self_bvh.left_index = currentIndex; _left->flatten(bvhs, currentIndex); - self_bvh.right_index = currentIndex; + self_bvh.index = currentIndex; _right->flatten(bvhs, currentIndex); } @@ -244,4 +240,4 @@ BVHStats BVH::analyzeBVHLeaves(BVH *root) right.average_triangles * right_leaf_count) / total_leaf_count; return {min_count, max_count, avg_count}; -} \ No newline at end of file +}