change GPUBvh struct to have only one index

This commit is contained in:
2025-01-25 15:19:53 +01:00
parent 6378ed0737
commit e1e53b99fe
5 changed files with 21 additions and 32 deletions

View File

@ -78,10 +78,7 @@ struct GPUBvh
vec3 min;
vec3 max;
int left_index;
int right_index;
int first_primitive;
int index;
int primitive_count;
};

View File

@ -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);
}
}