aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorladevieq <ladevie.quentin@gmail.com>2021-07-25 16:52:28 +0200
committerladevieq <ladevie.quentin@gmail.com>2021-07-25 16:52:28 +0200
commit3bfd2d67e1c2d7e2d77c431f54dd68356c94d787 (patch)
treec3fbd47d8d273c08c64c363342fff35c04f780d0
parent3dd870b001bef62aaa501257352d968d1346c7f2 (diff)
Slowly rendering sponza
-rw-r--r--include/bvh-node.hpp97
-rw-r--r--include/scene.hpp14
-rw-r--r--include/triangle.hpp4
-rw-r--r--shaders/compute.comp54
-rw-r--r--src/gltf.cpp7
-rw-r--r--src/main.cpp11
-rw-r--r--src/scene.cpp154
7 files changed, 171 insertions, 170 deletions
diff --git a/include/bvh-node.hpp b/include/bvh-node.hpp
index 805edf2..4821fc7 100644
--- a/include/bvh-node.hpp
+++ b/include/bvh-node.hpp
@@ -27,54 +27,21 @@ struct temp_node : public bvh_node {
class bvh {
public:
- bvh(std::vector<sphere>& spheres, std::vector<bvh_node>& nodes)
- :spheres(spheres), nodes(nodes) {
- nodes = std::vector<bvh_node>(2 * spheres.size() - 1);
- temp_nodes = std::vector<temp_node>(2 * spheres.size() - 1);
- leafs = std::vector<temp_node>(spheres.size());
+ // bvh(std::vector<sphere>& spheres, std::vector<bvh_node>& nodes)
+ // :spheres(spheres), nodes(nodes) {
+ // nodes = std::vector<bvh_node>(2 * spheres.size() - 1);
+ // temp_nodes = std::vector<temp_node>(2 * spheres.size() - 1);
+ // leafs = std::vector<temp_node>(spheres.size());
- for (uint32_t id = 0; id < spheres.size(); id++) {
- leafs[id].bounding_box = spheres[id].bounding_box;
- leafs[id].primitive_id = id;
- }
-
- temp_nodes[0] = temp_node();
-
- temp_nodes[0].bounding_box = compute_bounds(0, spheres.size());
- subdivide(0, 0, spheres.size());
-
- set_depth_first_order();
-
- for (uint32_t id = 0; id < temp_nodes.size(); id++) {
- auto old_node = temp_nodes[id];
- auto &node = nodes[old_node.df_id];
-
- node.primitive_id = old_node.primitive_id;
- node.bounding_box = old_node.bounding_box;
-
- if (old_node.next_id != -1) {
- node.next_id = temp_nodes[old_node.next_id].df_id;
- }
- }
-
- // exporter();
- }
-
- // bvh(std::vector<triangle>& triangles, std::vector<bvh_node>& nodes)
- // :triangles(triangles), nodes(nodes) {
- // nodes.resize(2 * triangles.size() - 1);
- // temp_nodes = std::vector<temp_node>(2 * triangles.size() - 1);
- // leafs = std::vector<temp_node>(triangles.size());
-
- // for (uint32_t id = 0; id < triangles.size(); id++) {
- // leafs[id].bounding_box = triangles[id].bounding_box;
+ // for (uint32_t id = 0; id < spheres.size(); id++) {
+ // leafs[id].bounding_box = spheres[id].bounding_box;
// leafs[id].primitive_id = id;
// }
// temp_nodes[0] = temp_node();
- // temp_nodes[0].bounding_box = compute_bounds(0, triangles.size());
- // subdivide(0, 0, triangles.size());
+ // temp_nodes[0].bounding_box = compute_bounds(0, spheres.size());
+ // subdivide(0, 0, spheres.size());
// set_depth_first_order();
@@ -93,6 +60,39 @@ public:
// // exporter();
// }
+ bvh(std::vector<triangle>& triangles, std::vector<bvh_node>& nodes)
+ :triangles(triangles), nodes(nodes) {
+ nodes.resize(2 * triangles.size() - 1);
+ temp_nodes = std::vector<temp_node>(2 * triangles.size() - 1);
+ leafs = std::vector<temp_node>(triangles.size());
+
+ for (uint32_t id = 0; id < triangles.size(); id++) {
+ leafs[id].bounding_box = triangles[id].bounding_box;
+ leafs[id].primitive_id = id;
+ }
+
+ temp_nodes[0] = temp_node();
+
+ temp_nodes[0].bounding_box = compute_bounds(0, triangles.size());
+ subdivide(0, 0, triangles.size());
+
+ set_depth_first_order();
+
+ for (uint32_t id = 0; id < temp_nodes.size(); id++) {
+ auto old_node = temp_nodes[id];
+ auto &node = nodes[old_node.df_id];
+
+ node.primitive_id = old_node.primitive_id;
+ node.bounding_box = old_node.bounding_box;
+
+ if (old_node.next_id != -1) {
+ node.next_id = temp_nodes[old_node.next_id].df_id;
+ }
+ }
+
+ // exporter();
+ }
+
//-------------------------
// BVH exporter for graphviz
//-------------------------
@@ -153,8 +153,8 @@ private:
for (uint32_t box_id = begin; box_id < end; box_id++) {
auto leaf = leafs[box_id];
- global_box = aabb::surrounding_box(global_box, spheres[leaf.primitive_id].bounding_box);
- // global_box = aabb::surrounding_box(global_box, triangles[leaf.primitive_id].bounding_box);
+ // global_box = aabb::surrounding_box(global_box, spheres[leaf.primitive_id].bounding_box);
+ global_box = aabb::surrounding_box(global_box, triangles[leaf.primitive_id].bounding_box);
}
return global_box;
@@ -195,8 +195,11 @@ private:
int32_t split_axis = find_split_axis(temp_nodes[parent_id].bounding_box);
std::sort(leafs.begin() + begin, leafs.begin() + end,
+ // [&](const bvh_node& a, const bvh_node& b) {
+ // return spheres[a.primitive_id].center[split_axis] < spheres[b.primitive_id].center[split_axis];
+ // }
[&](const bvh_node& a, const bvh_node& b) {
- return spheres[a.primitive_id].center[split_axis] < spheres[b.primitive_id].center[split_axis];
+ return triangles[a.primitive_id].center()[split_axis] < triangles[b.primitive_id].center()[split_axis];
}
);
@@ -230,8 +233,8 @@ public:
std::vector<temp_node> temp_nodes;
std::vector<temp_node> leafs;
- std::vector<sphere>& spheres;
- // std::vector<triangle>& triangles;
+ // std::vector<sphere>& spheres;
+ std::vector<triangle>& triangles;
uint32_t next_node_id = 0;
};
diff --git a/include/scene.hpp b/include/scene.hpp
index 364e3a7..2a9ebf2 100644
--- a/include/scene.hpp
+++ b/include/scene.hpp
@@ -15,7 +15,8 @@ class scene {
camera cam;
- uint32_t max_bounce = 50;
+ // uint32_t max_bounce = 50;
+ uint32_t max_bounce = 1;
// Output image resolution
uint32_t width;
@@ -23,9 +24,9 @@ class scene {
uint32_t sample_index = 0;
- uint32_t spheres_count = 0;
- // uint32_t triangles_count = 0;
- uint32_t enable_dof = true;
+ // uint32_t spheres_count = 0;
+ uint32_t triangles_count = 0;
+ uint32_t enable_dof = false;
uint32_t debug_bvh = false;
uint32_t padding;
@@ -40,10 +41,9 @@ public:
metadata meta;
-
// Geometry & BVH
- std::vector<sphere> spheres;
- // std::vector<triangle> triangles;
+ // std::vector<sphere> spheres;
+ std::vector<triangle> triangles;
std::vector<bvh_node> nodes;
};
diff --git a/include/triangle.hpp b/include/triangle.hpp
index 12c0b69..57b42ca 100644
--- a/include/triangle.hpp
+++ b/include/triangle.hpp
@@ -15,6 +15,10 @@ struct triangle {
: v1(v1), v2(v2), v3(v3), bounding_box(v1.position, v2.position, v3.position)
{}
+ vec3 center() {
+ return (v2.position + v1.position + v3.position) / 3.f;
+ }
+
vertex v1;
vertex v2;
vertex v3;
diff --git a/shaders/compute.comp b/shaders/compute.comp
index 75b7696..060d213 100644
--- a/shaders/compute.comp
+++ b/shaders/compute.comp
@@ -11,8 +11,6 @@ const uint METAL_MATERIAL = 1;
const uint DIELECTRIC_MATERIAL = 2;
const uint EMISSIVE_MATERIAL = 3;
-const vec3 light_position = vec3(10, -25, 0);
-
struct material {
vec4 albedo;
vec4 emissive;
@@ -86,16 +84,16 @@ layout(set = 0, binding = 0) buffer scene_metadata {
uint height;
uint sample_index;
- uint spheres_count;
- // uint triangles_count;
+ // uint spheres_count;
+ uint triangles_count;
bool enable_dof;
bool debug_bvh;
uint padding;
};
layout(set = 0, binding = 1) buffer geometry {
- sphere[] spheres;
- // triangle[] triangles;
+ // sphere[] spheres;
+ triangle[] triangles;
};
layout(set = 0, binding = 2) buffer bvh {
@@ -162,13 +160,13 @@ bool hit_aabb(aabb b, ray r, float min_t, float max_t) {
uint hit_aabbs(ray r, float min_t, float max_t) {
uint hit_count = 0;
- for (uint idx = 0; idx <= spheres_count * 2; idx++) {
- // for (uint idx = 0; idx <= triangles_count * 2; idx++) {
+ // for (uint idx = 0; idx <= spheres_count * 2; idx++) {
+ for (uint idx = 0; idx <= triangles_count * 2; idx++) {
hit_count += uint(hit_aabb(nodes[idx].bb, r, min_t, max_t));
if (nodes[idx].primitive_id >= 0) {
- hit_count += uint(hit_aabb(spheres[nodes[idx].primitive_id].bb, r, min_t, max_t));
- // hit_count += uint(hit_aabb(triangles[nodes[idx].primitive_id].bb, r, min_t, max_t));
+ // hit_count += uint(hit_aabb(spheres[nodes[idx].primitive_id].bb, r, min_t, max_t));
+ hit_count += uint(hit_aabb(triangles[nodes[idx].primitive_id].bb, r, min_t, max_t));
}
}
@@ -215,22 +213,23 @@ bool hit_triangle(triangle tri, ray r, float min_t, float max_t, out hit_info in
vec3 originv1 = r.origin - tri.v1.position.xyz;
vec3 normal = cross(v2v1, v3v1);
vec3 q = cross(originv1, r.direction);
- float d = 1 / dot(r.direction, normal);
+ float d = 1.0 / dot(r.direction, normal);
float u = d * dot(-q, v3v1);
float v = d * dot(q, v2v1);
float t = d * dot(-normal, originv1);
- if (u < 0 || u > 1 || v < 0|| u + v > 1) {
+ if (u < 0.0 || u > 1.0 || v < 0.0 || u + v > 1.0) {
return false;
}
info.t = t;
- info.point = at(r, info.t);
+ // info.point = at(r, info.t);
vec3 outward_normal = normal;
info.front_face = dot(outward_normal, r.direction) < 0.0;
- info.normal = info.front_face ? outward_normal : -outward_normal;
- info.mat = material(vec4(1.0), vec4(0.0), 1.0, 1.5, LAMBERTIAN_MATERIAL, 0);
+ // info.normal = info.front_face ? outward_normal : -outward_normal;
+ info.normal = vec3(u, v, 0.0);
+ // info.mat = material(vec4(u, v, 0.0, 0.0), vec4(0.0), 1.0, 1.5, LAMBERTIAN_MATERIAL, 0);
return true;
}
@@ -244,16 +243,16 @@ bool hit_node(ray r, float min_t, float max_t, out hit_info info) {
while(id != -1) {
// Leafs
if (nodes[id].primitive_id != -1) {
- if (hit_sphere(spheres[nodes[id].primitive_id], r, min_t, closest_t, temp_info)) {
- info = temp_info;
- closest_t = temp_info.t;
- hit = true;
- }
- // if (hit_triangle(triangles[nodes[id].primitive_id], r, min_t, closest_t, temp_info)) {
+ // if (hit_sphere(spheres[nodes[id].primitive_id], r, min_t, closest_t, temp_info)) {
// info = temp_info;
// closest_t = temp_info.t;
// hit = true;
// }
+ if (hit_triangle(triangles[nodes[id].primitive_id], r, min_t, closest_t, temp_info)) {
+ info = temp_info;
+ closest_t = temp_info.t;
+ hit = true;
+ }
id = nodes[id].next_id;
} else { // Internal nodes
if (hit_aabb(nodes[id].bb, r, min_t, closest_t)) {
@@ -267,14 +266,6 @@ bool hit_node(ray r, float min_t, float max_t, out hit_info info) {
return hit;
}
-bool hit_spheres(ray r, float min_t, float max_t, out hit_info info) {
- return hit_node(r, min_t, max_t, info);
-}
-
-bool hit_triangles(ray r, float min_t, float max_t, out hit_info info) {
- return hit_node(r, min_t, max_t, info);
-}
-
bool lambertian_scattering(material mat, ray incident, inout uint seed, hit_info info, out vec4 attenuation, out ray scattered) {
attenuation = mat.albedo;
scattered = ray(info.point, normalize(info.normal + unit_vec(seed)));
@@ -326,8 +317,7 @@ vec4 ray_color(ray r, uint seed) {
vec4 final_color = vec4(0.0);
vec4 throughput = vec4(1.0);
ray current_ray = r;
- while (hit_spheres(current_ray, 0.001, 1e15, info) && bounces < max_bounce) {
- // while (hit_triangles(current_ray, 0.001, 1e15, info) && bounces < max_bounce) {
+ while (hit_node(current_ray, 0.001, 1e15, info) && bounces < max_bounce) {
ray scattered;
vec4 attenuation = vec4(0.0);
// if ((info.mat.type == LAMBERTIAN_MATERIAL && lambertian_scattering(info.mat, current_ray, seed, info, attenuation, scattered)) ||
@@ -335,7 +325,7 @@ vec4 ray_color(ray r, uint seed) {
// (info.mat.type == DIELECTRIC_MATERIAL && dielectric_scattering(info.mat, current_ray, seed, info, attenuation, scattered)) ||
// info.mat.type == EMISSIVE_MATERIAL) {
lambertian_scattering(info.mat, current_ray, seed, info, attenuation, scattered);
- final_color += info.mat.emissive * throughput;
+ // final_color += info.mat.emissive * throughput;
throughput *= attenuation;
// float NdotR = dot(info.normal, scattered.direction);
diff --git a/src/gltf.cpp b/src/gltf.cpp
index 0e74aaf..72219d6 100644
--- a/src/gltf.cpp
+++ b/src/gltf.cpp
@@ -78,11 +78,14 @@ void gltf::load_primitive(json &gltf_json, json &primitive, std::vector<std::vec
auto positions_length = positions_view["byteLength"].get<size_t>();
auto positions_buffer = buffers_content[positions_buffer_index];
- void* positions_start = positions_buffer.data() + positions_offset;
+ float* positions_start = (float*)(positions_buffer.data() + positions_offset);
mesh_part.positions.resize(positions_length / (sizeof(float) * 3));
- std::memcpy(mesh_part.positions.data(), positions_start, positions_length);
+ for (size_t i = 0; i < positions_length / (sizeof(float) * 3); i++) {
+ mesh_part.positions[i] = vec3(positions_start[i * 3], positions_start[i * 3 + 1], positions_start[i * 3 + 2]);
+ }
+ // std::memcpy(mesh_part.positions.data(), positions_start, positions_length);
}
{
diff --git a/src/main.cpp b/src/main.cpp
index 875527f..2634371 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -55,7 +55,7 @@ int main() {
auto start = std::chrono::high_resolution_clock::now();
auto end = std::chrono::high_resolution_clock::now();
- point3 position = { 13.0, 2.0, 3.0 };
+ point3 position = { 13.0, 2.0, -3.0 };
point3 target = { 0.0, 0.0, 0.0 };
auto v_fov = 20;
auto aperture = 0.1;
@@ -63,12 +63,13 @@ int main() {
auto cam = camera(position, target, v_fov, (float)width / (float)height, aperture, focus_distance);
auto main_scene = scene(cam, width, height);
auto can_render = true;
- // vkrenderer renderer { wnd, sizeof(main_scene.meta), sizeof(main_scene.triangles[0]) * main_scene.triangles.size(), sizeof(main_scene.nodes[0]) * main_scene.nodes.size() };
- vkrenderer renderer { wnd, sizeof(main_scene.meta), sizeof(main_scene.spheres[0]) * main_scene.spheres.size(), sizeof(main_scene.nodes[0]) * main_scene.nodes.size() };
+ vkrenderer renderer { wnd, sizeof(main_scene.meta), sizeof(main_scene.triangles[1]) * main_scene.triangles.size(), sizeof(main_scene.nodes[0]) * main_scene.nodes.size() };
+ // vkrenderer renderer { wnd, sizeof(main_scene.meta), sizeof(main_scene.spheres[0]) * main_scene.spheres.size(), sizeof(main_scene.nodes[0]) * main_scene.nodes.size() };
// Upload scene content
std::memcpy(renderer.scene_buffer_ptr(), &main_scene.meta, sizeof(main_scene.meta));
- std::memcpy(renderer.geometry_buffer_ptr(), main_scene.spheres.data(), sizeof(main_scene.spheres[0]) * main_scene.spheres.size());
+ // std::memcpy(renderer.geometry_buffer_ptr(), main_scene.spheres.data(), sizeof(main_scene.spheres[0]) * main_scene.spheres.size());
+ std::memcpy(renderer.geometry_buffer_ptr(), main_scene.triangles.data(), sizeof(main_scene.triangles[0]) * main_scene.triangles.size());
std::memcpy(renderer.bvh_buffer_ptr(), main_scene.nodes.data(), sizeof(main_scene.nodes[0]) * main_scene.nodes.size());
ImGuiIO& io = ImGui::GetIO();
@@ -216,7 +217,7 @@ int main() {
reset_accumulation = true;
}
- ImGui::SliderInt("bounces", (int32_t*)&((scene*) renderer.scene_buffer_ptr())->meta.max_bounce, 2, 250);
+ ImGui::SliderInt("bounces", (int32_t*)&((scene*) renderer.scene_buffer_ptr())->meta.max_bounce, 1, 250);
if (ImGui::Checkbox("debug bvh", (bool*)&((scene*) renderer.scene_buffer_ptr())->meta.debug_bvh)) {
reset_accumulation = true;
diff --git a/src/scene.cpp b/src/scene.cpp
index 9fd57eb..8e25be7 100644
--- a/src/scene.cpp
+++ b/src/scene.cpp
@@ -6,92 +6,92 @@
#include "gltf.hpp"
// Return the number of instantiated spheres
-void scene::random_scene() {
- material ground_material = { { 0.5, 0.5, 0.5 } };
- ground_material.type = MATERIAL_TYPE::LAMBERTIAN;
- spheres.emplace_back(vec3 { 0, -1000, 0 }, ground_material, 1000);
-
- int32_t spheres_count = 11;
- for (int a = -spheres_count; a < spheres_count; a++) {
- for (int b = -spheres_count; b < spheres_count; b++) {
- auto choose_mat = randd();
- point3 center(a + 0.9 * randd(), 0.2, b + 0.9 * randd());
-
- if ((center - point3{ 4, 0.2, 0 }).length() > 0.9) {
- material sphere_material = {};
-
- if (choose_mat < 0.8) {
- // diffuse
- sphere_material.albedo = color::random() * color::random();
- sphere_material.type = MATERIAL_TYPE::LAMBERTIAN;
- } else if (choose_mat < 0.95) {
- // metal
- sphere_material.albedo = color::random(0.5, 1);
- sphere_material.fuzz = randd(0, 0.5);
- sphere_material.type = MATERIAL_TYPE::METAL;
- } else {
- // glass
- sphere_material.ior = 1.5;
- sphere_material.type = MATERIAL_TYPE::DIELECTRIC;
- }
-
- spheres.emplace_back(center, sphere_material, 0.2);
- }
- }
- }
-
- material material1 = {};
- material1.ior = 1.5;
- material1.type = MATERIAL_TYPE::DIELECTRIC;
- spheres.emplace_back(vec3 { 0, 1, 0 }, material1, 1.0);
-
- material material2 = {};
- material2.albedo = color{ 0.4, 0.2, 0.1 };
- material2.type = MATERIAL_TYPE::LAMBERTIAN;
- spheres.emplace_back(vec3 { -4, 1, 0 }, material2, 1.0);
-
- material material3 = {};
- material3.albedo = color{ 0.7, 0.6, 0.5 };
- material3.fuzz = 0.0;
- material3.type = MATERIAL_TYPE::METAL;
- spheres.emplace_back(vec3 { 4, 1, 0 }, material3, 1.0);
-
- material material4 = {};
- material4.albedo = color{ 0.0, 0.0, 0.0 };
- material4.emissive = color{ 1.0, 1.0, 1.0 } * 1000.0;
- material4.fuzz = 0.0;
- material4.type = MATERIAL_TYPE::EMISSIVE;
- spheres.emplace_back(vec3 { 2, 1.5, 2 }, material4, 0.5);
-
- spheres_count = spheres.size();
-}
+// void scene::random_scene() {
+// material ground_material = { { 0.5, 0.5, 0.5 } };
+// ground_material.type = MATERIAL_TYPE::LAMBERTIAN;
+// spheres.emplace_back(vec3 { 0, -1000, 0 }, ground_material, 1000);
+//
+// int32_t spheres_count = 11;
+// for (int a = -spheres_count; a < spheres_count; a++) {
+// for (int b = -spheres_count; b < spheres_count; b++) {
+// auto choose_mat = randd();
+// point3 center(a + 0.9 * randd(), 0.2, b + 0.9 * randd());
+//
+// if ((center - point3{ 4, 0.2, 0 }).length() > 0.9) {
+// material sphere_material = {};
+//
+// if (choose_mat < 0.8) {
+// // diffuse
+// sphere_material.albedo = color::random() * color::random();
+// sphere_material.type = MATERIAL_TYPE::LAMBERTIAN;
+// } else if (choose_mat < 0.95) {
+// // metal
+// sphere_material.albedo = color::random(0.5, 1);
+// sphere_material.fuzz = randd(0, 0.5);
+// sphere_material.type = MATERIAL_TYPE::METAL;
+// } else {
+// // glass
+// sphere_material.ior = 1.5;
+// sphere_material.type = MATERIAL_TYPE::DIELECTRIC;
+// }
+//
+// spheres.emplace_back(center, sphere_material, 0.2);
+// }
+// }
+// }
+//
+// material material1 = {};
+// material1.ior = 1.5;
+// material1.type = MATERIAL_TYPE::DIELECTRIC;
+// spheres.emplace_back(vec3 { 0, 1, 0 }, material1, 1.0);
+//
+// material material2 = {};
+// material2.albedo = color{ 0.4, 0.2, 0.1 };
+// material2.type = MATERIAL_TYPE::LAMBERTIAN;
+// spheres.emplace_back(vec3 { -4, 1, 0 }, material2, 1.0);
+//
+// material material3 = {};
+// material3.albedo = color{ 0.7, 0.6, 0.5 };
+// material3.fuzz = 0.0;
+// material3.type = MATERIAL_TYPE::METAL;
+// spheres.emplace_back(vec3 { 4, 1, 0 }, material3, 1.0);
+//
+// material material4 = {};
+// material4.albedo = color{ 0.0, 0.0, 0.0 };
+// material4.emissive = color{ 1.0, 1.0, 1.0 } * 1000.0;
+// material4.fuzz = 0.0;
+// material4.type = MATERIAL_TYPE::EMISSIVE;
+// spheres.emplace_back(vec3 { 2, 1.5, 2 }, material4, 0.5);
+//
+// spheres_count = spheres.size();
+// }
scene::scene(camera cam, uint32_t width, uint32_t height)
:meta(cam, width, height){
- // auto sponza_path = std::filesystem::path("../models/sponza");
- // auto sponza_filename = std::string("Sponza.gltf");
- // auto mesh = gltf::load(sponza_path, sponza_filename);
+ auto sponza_path = std::filesystem::path("../models/sponza");
+ auto sponza_filename = std::string("Sponza.gltf");
+ auto mesh = gltf::load(sponza_path, sponza_filename);
- // auto node = mesh.nodes[0];
- // for (auto& mesh_part: node) {
- // for (size_t i = 0; i < mesh_part.indices.size(); i += 3) {
- // auto i1 = mesh_part.indices[i];
- // auto i2 = mesh_part.indices[i + 1];
- // auto i3 = mesh_part.indices[i + 2];
+ auto node = mesh.nodes[0];
+ for (auto& mesh_part: node) {
+ for (size_t i = 0; i < mesh_part.indices.size(); i += 3) {
+ auto i1 = mesh_part.indices[i];
+ auto i2 = mesh_part.indices[i + 1];
+ auto i3 = mesh_part.indices[i + 2];
- // auto v1 = vertex { .position = mesh_part.positions[i1], .normal = mesh_part.normals[i1] };
- // auto v2 = vertex { .position = mesh_part.positions[i2], .normal = mesh_part.normals[i2] };
- // auto v3 = vertex { .position = mesh_part.positions[i3], .normal = mesh_part.normals[i3] };
+ auto v1 = vertex { .position = mesh_part.positions[i1], .normal = mesh_part.normals[i1] };
+ auto v2 = vertex { .position = mesh_part.positions[i2], .normal = mesh_part.normals[i2] };
+ auto v3 = vertex { .position = mesh_part.positions[i3], .normal = mesh_part.normals[i3] };
- // triangles.emplace_back(v1, v2, v3);
- // }
- // }
+ triangles.emplace_back(v1, v2, v3);
+ }
+ }
- random_scene();
+ // random_scene();
- // bvh builder(triangles, nodes);
- bvh builder(spheres, nodes);
+ bvh builder(triangles, nodes);
+ // bvh builder(spheres, nodes);
// builder.exporter();
for (uint32_t idx = 0; idx < builder.nodes.size(); idx++) {