~ | Small fix

This commit is contained in:
TheRedShip
2025-01-23 00:25:18 +01:00
parent bdcafaf4f0
commit 1783037bdf
3 changed files with 25 additions and 13 deletions

View File

@ -24,8 +24,17 @@ pl 0 -2 0 0 1 0 2 // floor
qu -1 1.999 -1 2 0 0 0 0 2 6 qu -1 1.999 -1 2 0 0 0 0 2 6
OBJ scenes/obj/Dragon_800K.obj -0.5 0 0.55 5 0 90 0 OBJ scenes/obj/Dragon_80K.obj -0.5 0 0.55 5 0 0 0
OBJ scenes/obj/Dragon_800K.obj 0.5 0 -0.55 5 0 -90 0 OBJ scenes/obj/Dragon_80K.obj 0.5 0 -0.55 1 0 0 0
OBJ scenes/obj/Dragon_80K.obj -1.5 0 1.5 1 0 0 0
OBJ scenes/obj/Dragon_80K.obj 1.5 0 -1.5 1 0 0 0
OBJ scenes/obj/Dragon_80K.obj -0.5 1 0.55 1 0 0 0
OBJ scenes/obj/Dragon_80K.obj 0.5 1 -0.55 1 0 0 0
OBJ scenes/obj/Dragon_80K.obj -3.5 3 3.5 1 0 0 0
OBJ scenes/obj/Dragon_80K.obj 3.5 3 -3.5 1 0 0 0
# OBJ obj/Model.obj # OBJ obj/Model.obj

View File

@ -233,7 +233,7 @@ hitInfo traceBVH(Ray ray, GPUBvhData bvh_data, inout Stats stats)
hitInfo traverseBVHs(Ray ray, GPUBvhData bvh_data, inout Stats stats) hitInfo traverseBVHs(Ray ray, GPUBvhData bvh_data, inout Stats stats)
{ {
hitInfo hit; hitInfo hit;
hit.t = 1e30; hit.t = 1e30;
hit.obj_index = -1; hit.obj_index = -1;
@ -245,16 +245,17 @@ hitInfo traverseBVHs(Ray ray, GPUBvhData bvh_data, inout Stats stats)
transformedRay.origin = transformMatrix * (ray.origin - bvh_data.offset); transformedRay.origin = transformMatrix * (ray.origin - bvh_data.offset);
transformedRay.inv_direction = (1. / transformedRay.direction); transformedRay.inv_direction = (1. / transformedRay.direction);
hitInfo temp_hit = traceBVH(transformedRay, bvh_data, stats); hit = traceBVH(transformedRay, bvh_data, stats);
temp_hit.t = temp_hit.t / bvh_data.scale; if (hit.obj_index == -1)
return (hit);
if (temp_hit.t < hit.t)
{ hit.t = hit.t / bvh_data.scale;
hit.t = temp_hit.t; hit.last_t = hit.last_t / bvh_data.scale;
hit.obj_index = temp_hit.obj_index; hit.obj_index = hit.obj_index;
hit.normal = normalize(inverseTransformMatrix * temp_hit.normal); hit.mat_index = hit.mat_index;
} hit.position = inverseTransformMatrix * hit.position + bvh_data.offset;
hit.normal = normalize(inverseTransformMatrix * hit.normal);
return (hit); return (hit);
} }

View File

@ -57,7 +57,9 @@ float TopBVH::evaluateSah(std::vector<GPUBvhData> &bvhs_data, std::vector<GPUBvh
glm::vec3 min = bvh_root.min + bvh_data.offset; glm::vec3 min = bvh_root.min + bvh_data.offset;
glm::vec3 max = bvh_root.max + bvh_data.offset; glm::vec3 max = bvh_root.max + bvh_data.offset;
if (min[axis] < pos) glm::vec3 centroid = (min + max) * 0.5f;
if (centroid[axis] < pos)
{ {
left_count++; left_count++;
left_box.grow( min ); left_box.grow( min );