mirror of
https://github.com/TheRedShip/RT_GPU.git
synced 2025-09-27 10:48:34 +02:00
~ | Working toplevel with transformed obj
This commit is contained in:
@ -342,8 +342,7 @@ vec3 debugColor(vec2 uv)
|
||||
Ray ray = initRay(uv);
|
||||
Stats stats = Stats(0, 0);
|
||||
|
||||
// hitInfo hit = traceBVH(ray, BvhData[0], stats);
|
||||
// hitInfo hit = traverseBVHs(ray, BvhData[0], stats);
|
||||
// hitInfo hit = traverseBVHs(ray, BvhData[0], stats); //working with scaling offset transfo
|
||||
hitInfo hit = traceTopBVH(ray, stats);
|
||||
|
||||
float box_display = float(stats.box_count) / float(debug.box_treshold);
|
||||
@ -354,6 +353,8 @@ vec3 debugColor(vec2 uv)
|
||||
case 0:
|
||||
return (hit.normal * 0.5 + 0.5) * int(hit.obj_index != -1);
|
||||
case 1:
|
||||
if (hit.obj_index != -1)
|
||||
return (hit.normal * 0.5 + 0.5);
|
||||
return (box_display < 1. ? vec3(box_display) : vec3(1., 0., 0.));
|
||||
case 2:
|
||||
return (triangle_display < 1. ? vec3(triangle_display) : vec3(1., 0., 0.));
|
||||
|
@ -20,8 +20,8 @@ int main(int argc, char **argv)
|
||||
return (1);
|
||||
|
||||
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/debug.glsl");
|
||||
// Shader shader("shaders/vertex.vert", "shaders/frag.frag", "shaders/compute.glsl");
|
||||
Shader shader("shaders/vertex.vert", "shaders/frag.frag", "shaders/debug.glsl");
|
||||
|
||||
GLint max_gpu_size;
|
||||
glGetIntegerv(GL_MAX_SHADER_STORAGE_BLOCK_SIZE, &max_gpu_size);
|
||||
|
@ -29,16 +29,34 @@ TopBVH::TopBVH(std::vector<GPUBvhData> &bvhs_data, std::vector<GPUBvh> &bvhs, in
|
||||
void TopBVH::updateBounds(std::vector<GPUBvhData> &bvhs_data, std::vector<GPUBvh> &bvhs)
|
||||
{
|
||||
for (int i = 0; i < _bvh_count; i++)
|
||||
{
|
||||
GPUBvhData bvh_data = bvhs_data[_first_bvh + i];
|
||||
GPUBvh root_bvh = bvhs[bvh_data.bvh_start_index];
|
||||
{
|
||||
GPUBvhData bvh_data = bvhs_data[_first_bvh + i];
|
||||
GPUBvh root_bvh = bvhs[bvh_data.bvh_start_index];
|
||||
|
||||
glm::vec3 min = root_bvh.min + bvh_data.offset;
|
||||
glm::vec3 max = root_bvh.max + bvh_data.offset;
|
||||
|
||||
_aabb.min = glm::min(_aabb.min, min);
|
||||
_aabb.max = glm::max(_aabb.max, max);
|
||||
}
|
||||
glm::vec3 corners[8] = {
|
||||
glm::vec3(root_bvh.min.x, root_bvh.min.y, root_bvh.min.z),
|
||||
glm::vec3(root_bvh.max.x, root_bvh.min.y, root_bvh.min.z),
|
||||
glm::vec3(root_bvh.min.x, root_bvh.max.y, root_bvh.min.z),
|
||||
glm::vec3(root_bvh.max.x, root_bvh.max.y, root_bvh.min.z),
|
||||
glm::vec3(root_bvh.min.x, root_bvh.min.y, root_bvh.max.z),
|
||||
glm::vec3(root_bvh.max.x, root_bvh.min.y, root_bvh.max.z),
|
||||
glm::vec3(root_bvh.min.x, root_bvh.max.y, root_bvh.max.z),
|
||||
glm::vec3(root_bvh.max.x, root_bvh.max.y, root_bvh.max.z)
|
||||
};
|
||||
|
||||
glm::vec3 transformed_min(1e30);
|
||||
glm::vec3 transformed_max(-1e30);
|
||||
|
||||
for (glm::vec3 corner : corners)
|
||||
{
|
||||
glm::vec3 transformed = glm::vec3(glm::inverse(bvh_data.transform) * glm::vec4(corner, 1.0)) + bvh_data.offset;
|
||||
transformed_min = glm::min(transformed_min, transformed);
|
||||
transformed_max = glm::max(transformed_max, transformed);
|
||||
}
|
||||
|
||||
_aabb.min = glm::min(_aabb.min, transformed_min);
|
||||
_aabb.max = glm::max(_aabb.max, transformed_max);
|
||||
}
|
||||
}
|
||||
|
||||
float TopBVH::evaluateSah(std::vector<GPUBvhData> &bvhs_data, std::vector<GPUBvh> &bvhs, int axis, float pos)
|
||||
|
Reference in New Issue
Block a user