mirror of
https://github.com/TheRedShip/RT_GPU.git
synced 2025-09-27 10:48:34 +02:00
change GPUBvh struct to have only one index
This commit is contained in:
@ -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
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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
|
||||
#endif
|
||||
|
@ -78,10 +78,7 @@ struct GPUBvh
|
||||
vec3 min;
|
||||
vec3 max;
|
||||
|
||||
int left_index;
|
||||
int right_index;
|
||||
|
||||
int first_primitive;
|
||||
int index;
|
||||
int primitive_count;
|
||||
|
||||
};
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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<GPUBvh> &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};
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user