mirror of
https://github.com/TheRedShip/RT_GPU.git
synced 2025-09-27 18:48:36 +02:00
+ | Opti bvh on compute.glsl
This commit is contained in:
@ -22,4 +22,4 @@ pl 0 -10 0 0 1 0 2 // floor
|
|||||||
|
|
||||||
qu -20 59 -20 40 0 0 0 0 40 6
|
qu -20 59 -20 40 0 0 0 0 40 6
|
||||||
|
|
||||||
OBJ obj/Model.obj
|
OBJ obj/audi.obj
|
||||||
|
@ -77,32 +77,49 @@ hitInfo traceBVH(Ray ray)
|
|||||||
GPUBvh node = bvh[current_index];
|
GPUBvh node = bvh[current_index];
|
||||||
|
|
||||||
hitInfo temp_hit;
|
hitInfo temp_hit;
|
||||||
if (intersectRayBVH(ray, node, temp_hit) && temp_hit.t < hit.t)
|
if (node.is_leaf != 0)
|
||||||
{
|
{
|
||||||
if (node.is_leaf != 0)
|
for (int i = 0; i < node.primitive_count; i++)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < node.primitive_count; i++)
|
GPUTriangle obj = triangles[node.first_primitive + i];
|
||||||
{
|
|
||||||
GPUTriangle obj = triangles[node.first_primitive + i];
|
hitInfo temp_hit;
|
||||||
|
if (intersectTriangle(ray, obj, temp_hit) && temp_hit.t > 0.0f && temp_hit.t < hit.t + 0.0001)
|
||||||
hitInfo temp_hit;
|
{
|
||||||
if (intersectTriangle(ray, obj, temp_hit) && temp_hit.t > 0.0f && temp_hit.t < hit.t + 0.0001)
|
hit.t = temp_hit.t;
|
||||||
{
|
hit.last_t = temp_hit.last_t;
|
||||||
hit.t = temp_hit.t;
|
hit.obj_index = node.first_primitive + i;
|
||||||
hit.last_t = temp_hit.last_t;
|
hit.mat_index = obj.mat_index;
|
||||||
hit.obj_index = node.first_primitive + i;
|
hit.position = temp_hit.position;
|
||||||
hit.mat_index = obj.mat_index;
|
hit.normal = temp_hit.normal;
|
||||||
hit.position = temp_hit.position;
|
}
|
||||||
hit.normal = temp_hit.normal;
|
}
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
}
|
{
|
||||||
else
|
GPUBvh left_node = bvh[node.left_index];
|
||||||
{
|
GPUBvh right_node = bvh[node.right_index];
|
||||||
stack[++stack_ptr] = node.left_index;
|
|
||||||
stack[++stack_ptr] = node.right_index;
|
hitInfo left_hit;
|
||||||
}
|
hitInfo right_hit;
|
||||||
}
|
|
||||||
|
left_hit.t = 1e30;
|
||||||
|
right_hit.t = 1e30;
|
||||||
|
|
||||||
|
bool left_bool = intersectRayBVH(ray, left_node, left_hit);
|
||||||
|
bool right_bool = intersectRayBVH(ray, right_node, right_hit);
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (hit);
|
return (hit);
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
|
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/09/27 14:51:49 by TheRed #+# #+# */
|
/* Created: 2024/09/27 14:51:49 by TheRed #+# #+# */
|
||||||
/* Updated: 2025/01/18 19:28:58 by ycontre ### ########.fr */
|
/* Updated: 2025/01/18 21:10:23 by ycontre ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -20,8 +20,8 @@ int main(int argc, char **argv)
|
|||||||
return (1);
|
return (1);
|
||||||
|
|
||||||
Window window(&scene, WIDTH, HEIGHT, "RT_GPU", 0);
|
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/compute.glsl");
|
||||||
// Shader shader("shaders/vertex.vert", "shaders/frag.frag", "shaders/debug.glsl");
|
Shader shader("shaders/vertex.vert", "shaders/frag.frag", "shaders/debug.glsl");
|
||||||
|
|
||||||
GLint max_gpu_size;
|
GLint max_gpu_size;
|
||||||
glGetIntegerv(GL_MAX_SHADER_STORAGE_BLOCK_SIZE, &max_gpu_size);
|
glGetIntegerv(GL_MAX_SHADER_STORAGE_BLOCK_SIZE, &max_gpu_size);
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
|
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/01/16 21:48:48 by TheRed #+# #+# */
|
/* Created: 2025/01/16 21:48:48 by TheRed #+# #+# */
|
||||||
/* Updated: 2025/01/18 19:16:45 by ycontre ### ########.fr */
|
/* Updated: 2025/01/18 21:11:35 by ycontre ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -165,7 +165,6 @@ std::vector<GPUBvh> BVH::getGPUBvhs()
|
|||||||
int currentIndex = 0;
|
int currentIndex = 0;
|
||||||
flatten(bvhs, currentIndex);
|
flatten(bvhs, currentIndex);
|
||||||
|
|
||||||
std::cout << "BVH Done: " << bvhs.size() << std::endl;
|
|
||||||
|
|
||||||
return (bvhs);
|
return (bvhs);
|
||||||
}
|
}
|
@ -3,10 +3,10 @@
|
|||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* ObjParser.cpp :+: :+: :+: */
|
/* ObjParser.cpp :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/01/16 15:00:33 by tomoron #+# #+# */
|
/* Created: 2025/01/16 15:00:33 by tomoron #+# #+# */
|
||||||
/* Updated: 2025/01/18 18:57:31 by tomoron ### ########.fr */
|
/* Updated: 2025/01/18 21:07:12 by ycontre ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -154,7 +154,8 @@ void ObjParser::addFace(std::stringstream &line, Scene &scene)
|
|||||||
|
|
||||||
while(faceVertices.size() > 3)
|
while(faceVertices.size() > 3)
|
||||||
if (!addTriangleFromPolygon(faceVertices, scene, 0))
|
if (!addTriangleFromPolygon(faceVertices, scene, 0))
|
||||||
addTriangleFromPolygon(faceVertices, scene, 1);
|
if(!addTriangleFromPolygon(faceVertices, scene, 1))
|
||||||
|
return ;
|
||||||
|
|
||||||
if(!line.eof())
|
if(!line.eof())
|
||||||
throw std::runtime_error("OBJ: an error occured while parsing face");
|
throw std::runtime_error("OBJ: an error occured while parsing face");
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
|
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/12/23 18:29:41 by ycontre #+# #+# */
|
/* Created: 2024/12/23 18:29:41 by ycontre #+# #+# */
|
||||||
/* Updated: 2025/01/17 19:05:53 by ycontre ### ########.fr */
|
/* Updated: 2025/01/18 21:04:56 by ycontre ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -58,9 +58,15 @@ bool Scene::parseScene(char *name)
|
|||||||
}
|
}
|
||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
|
std::cout << "Parsing done" << std::endl;
|
||||||
|
std::cout << "Starting BVH" << std::endl;
|
||||||
|
|
||||||
BVH *bvh = new BVH(_gpu_triangles, 0, _gpu_triangles.size());
|
BVH *bvh = new BVH(_gpu_triangles, 0, _gpu_triangles.size());
|
||||||
_gpu_bvh = bvh->getGPUBvhs();
|
_gpu_bvh = bvh->getGPUBvhs();
|
||||||
|
|
||||||
|
std::cout << "BVH Done: " << bvh->size() << std::endl;
|
||||||
|
|
||||||
|
|
||||||
return (true);
|
return (true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user