aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorladevieq <ladevie.quentin@gmail.com>2021-09-26 23:57:26 +0200
committerladevieq <ladevie.quentin@gmail.com>2021-09-26 23:57:26 +0200
commitc5119193ffaedf4ac94fecfb434a3292a4746259 (patch)
tree398031c5d1e920fec21e53feacd1d55ba8a79dad /include
parentbbba71cfe5a9545f1a87c70eb3cab3b6b08b1b25 (diff)
Refactor gltf loading and triangles attributes
Diffstat (limited to 'include')
-rw-r--r--include/aabb.hpp24
-rw-r--r--include/gltf.hpp10
-rw-r--r--include/scene.hpp20
-rw-r--r--include/triangle.hpp21
-rw-r--r--include/vk-api.hpp1
-rw-r--r--include/vk-renderer.hpp25
6 files changed, 44 insertions, 57 deletions
diff --git a/include/aabb.hpp b/include/aabb.hpp
index 5f819db..475c04e 100644
--- a/include/aabb.hpp
+++ b/include/aabb.hpp
@@ -12,22 +12,15 @@ class aabb {
aabb(vec3 &min_point, vec3 &max_point): minimum(min_point), maximum(max_point) {}
aabb(vec3 &position, float radius): minimum(position - vec3(radius)), maximum(position + vec3(radius)) {}
aabb(triangle &tri) {
- auto &v1 = tri.v1.position;
- auto &v2 = tri.v2.position;
- auto &v3 = tri.v3.position;
-
- // minimum.x = fmin(fmin(v1.x, v2.x), v3.x);
- // minimum.y = fmin(fmin(v1.y, v2.y), v3.y);
- // minimum.z = fmin(fmin(v1.z, v2.z), v3.z);
+ auto &v1 = tri.p1;
+ auto &v2 = tri.p2;
+ auto &v3 = tri.p3;
+ // TODO: Use vector 3 functions
minimum.v[0] = fmin(fmin(v1.v[0], v2.v[0]), v3.v[0]);
minimum.v[1] = fmin(fmin(v1.v[1], v2.v[1]), v3.v[1]);
minimum.v[2] = fmin(fmin(v1.v[2], v2.v[2]), v3.v[2]);
- // maximum.x = fmax(fmax(v1.x, v2.x), v3.x);
- // maximum.y = fmax(fmax(v1.y, v2.y), v3.y);
- // maximum.z = fmax(fmax(v1.z, v2.z), v3.z);
-
maximum.v[0] = fmax(fmax(v1.v[0], v2.v[0]), v3.v[0]);
maximum.v[1] = fmax(fmax(v1.v[1], v2.v[1]), v3.v[1]);
maximum.v[2] = fmax(fmax(v1.v[2], v2.v[2]), v3.v[2]);
@@ -46,14 +39,6 @@ class aabb {
int32_t maximum_axis() {
vec3 diag = diagonal();
- // if (diag.x > diag.y && diag.x > diag.z) {
- // return 0;
- // } else if (diag.y > diag.z) {
- // return 1;
- // } else {
- // return 2;
- // }
-
if (diag.v[0] > diag.v[1] && diag.v[0] > diag.v[2]) {
return 0;
} else if (diag.v[1] > diag.v[2]) {
@@ -73,7 +58,6 @@ class aabb {
float surface_area() {
auto diag = diagonal();
- // return 2.f * (diag.x * diag.y + diag.x * diag.z + diag.y * diag.z);
return 2.f * (diag.v[0] * diag.v[1] + diag.v[0] * diag.v[2] + diag.v[1] * diag.v[2]);
}
diff --git a/include/gltf.hpp b/include/gltf.hpp
index 0a63ba6..7df5e7a 100644
--- a/include/gltf.hpp
+++ b/include/gltf.hpp
@@ -16,14 +16,18 @@ using json = nlohmann::json;
struct mesh_part {
std::vector<uint16_t> indices;
- std::vector<vec3> positions;
- std::vector<vec3> normals;
- std::vector<vec3> uvs;
+ std::vector<float> positions;
+ std::vector<float> normals;
+ std::vector<float> uvs;
material mat;
+ uint32_t triangles_count = 0;
+ uint32_t vertices_count = 0;
};
struct mesh {
std::vector<mesh_part> parts;
+ uint32_t triangles_count = 0;
+ uint32_t vertices_count = 0;
};
struct node {
diff --git a/include/scene.hpp b/include/scene.hpp
index 82ffb3d..2c945d4 100644
--- a/include/scene.hpp
+++ b/include/scene.hpp
@@ -34,11 +34,27 @@ class scene {
public:
scene(camera cam, uint32_t width, uint32_t height, vkrenderer &renderer);
+ void* scene_buffer_ptr() {
+ return scene_buffer.alloc_info.pMappedData;
+ }
+
metadata meta;
// Geometry & BVH
- // std::vector<sphere> spheres;
- std::vector<triangle> triangles;
+ std::vector<uint32_t> indices;
+ std::vector<float> positions;
+ std::vector<float> normals;
+ std::vector<float> uvs;
+ std::vector<material> materials;
+
+ Buffer scene_buffer;
+ Buffer indices_buffer;
+ Buffer positions_buffer;
+ Buffer normals_buffer;
+ Buffer uvs_buffer;
+ Buffer bvh_buffer;
+ Buffer materials_buffer;
+
std::vector<packed_bvh_node> packed_nodes;
};
diff --git a/include/triangle.hpp b/include/triangle.hpp
index 5a62aec..4d3550b 100644
--- a/include/triangle.hpp
+++ b/include/triangle.hpp
@@ -1,28 +1,21 @@
#ifndef __TRIANGLE_HPP_
#define __TRIANGLE_HPP_
-#include "material.hpp"
-
-struct vertex {
- vec3 position;
- vec3 normal;
- vec3 uv;
-};
+#include "vec3.hpp"
struct triangle {
triangle() = default;
- triangle(vertex v1, vertex v2, vertex v3, material mat)
- : v1(v1), v2(v2), v3(v3), mat(mat)
+ triangle(vec3 p1, vec3 p2, vec3 p3)
+ : p1(p1), p2(p2), p3(p3)
{}
vec3 center() {
- return (v1.position + v2.position + v3.position) / 3.f;
+ return (p1 + p2 + p3) / 3.f;
}
- vertex v1;
- vertex v2;
- vertex v3;
- material mat;
+ vec3 p1;
+ vec3 p2;
+ vec3 p3;
};
#endif // !__TRIANGLE_HPP_
diff --git a/include/vk-api.hpp b/include/vk-api.hpp
index 8612e00..7953817 100644
--- a/include/vk-api.hpp
+++ b/include/vk-api.hpp
@@ -49,7 +49,6 @@ struct global_descriptor {
VkPipelineLayout pipeline_layout;
VkDescriptorSet set;
- // TODO: Use constant here
std::vector<uint32_t> index_pool[3];
global_descriptor() {
diff --git a/include/vk-renderer.hpp b/include/vk-renderer.hpp
index 78d7028..dada742 100644
--- a/include/vk-renderer.hpp
+++ b/include/vk-renderer.hpp
@@ -27,24 +27,18 @@ class vkrenderer {
void recreate_swapchain();
- void create_scene_buffer(size_t size);
-
- void create_geometry_buffer(size_t size);
-
- void create_bvh_buffer(size_t size);
-
- inline void* scene_buffer_ptr() {
- return scene_buffer.alloc_info.pMappedData;
- }
-
- void update_geometry_buffer(void* data);
-
- void update_bvh_buffer(void* data);
-
void update_image(image img, void* data, size_t size);
vkapi api;
+ VkDeviceAddress scene_buffer_addr;
+ VkDeviceAddress indices_buffer_addr;
+ VkDeviceAddress positions_buffer_addr;
+ VkDeviceAddress normals_buffer_addr;
+ VkDeviceAddress uvs_buffer_addr;
+ VkDeviceAddress bvh_buffer_addr;
+ VkDeviceAddress materials_buffer_addr;
+
private:
void handle_swapchain_result(VkResult function_result);
@@ -62,9 +56,6 @@ class vkrenderer {
Pipeline compute_pipeline;
- Buffer scene_buffer;
- Buffer geometry_buffer;
- Buffer bvh_buffer;
Buffer staging_buffer;