Set C standard to C11 and add new assets

Changed CMakeLists.txt to set the C standard to C11.
Added multiple binary image files for new visual assets.
Added several new image files to enhance rendering capabilities.
Changed stb_image.h to improve support for various image formats.
Changed ray tracing engine to enhance ray creation and intersection.
Changed triangle structure to use a vertex array for better attribute handling.
Changed scene initialization to accommodate new texture management.
This commit is contained in:
2025-04-29 01:43:52 +09:00
parent 4db14ffdb0
commit 3de6b83d32
53 changed files with 8939 additions and 162671 deletions

View File

@@ -19,57 +19,62 @@ inline void quad_create(vec3s center, vec3s forward, vec3s up, float size, uint8
vec3s bottom_right = glms_vec3_sub(temp_add, scaled_up);
vec3s bottom_left = glms_vec3_sub(temp_sub, scaled_up);
triangle_create(top_left, top_right, bottom_left, material_id, collection);
triangle_create(top_right, bottom_right, bottom_left, material_id, collection);
vertex_t vertex_1 = {.position = top_left, .normal = forward, .uv = {0.0f, 0.0f}};
vertex_t vertex_2 = {.position = top_right, .normal = forward, .uv = {1.0f, 0.0f}};
vertex_t vertex_3 = {.position = bottom_right, .normal = forward, .uv = {1.0f, 1.0f}};
vertex_t vertex_4 = {.position = bottom_left, .normal = forward, .uv = {0.0f, 1.0f}};
triangle_create(vertex_1, vertex_2, vertex_4, material_id, collection);
triangle_create(vertex_2, vertex_3, vertex_4, material_id, collection);
}
inline void sphere_create(vec3s center, float radius, uint8_t material_id, triangle_collection_t* collection)
{
int segments = 16;
int rings = 16;
for (int i = 0; i < rings; i++)
{
float theta1 = (float)i / (float)rings * (float)M_PI;
float theta2 = (float)(i + 1) / (float)rings * (float)M_PI;
for (int j = 0; j < segments; j++)
{
float phi1 = (float)j / (float)segments * 2.0f * (float)M_PI;
float phi2 = (float)(j + 1) / (float)segments * 2.0f * (float)M_PI;
vec3s p1 = {
center.x + radius * sinf(theta1) * cosf(phi1),
center.y + radius * cosf(theta1),
center.z + radius * sinf(theta1) * sinf(phi1)
};
vec3s p2 = {
center.x + radius * sinf(theta2) * cosf(phi1),
center.y + radius * cosf(theta2),
center.z + radius * sinf(theta2) * sinf(phi1)
};
vec3s p3 = {
center.x + radius * sinf(theta2) * cosf(phi2),
center.y + radius * cosf(theta2),
center.z + radius * sinf(theta2) * sinf(phi2)
};
vec3s p4 = {
center.x + radius * sinf(theta1) * cosf(phi2),
center.y + radius * cosf(theta1),
center.z + radius * sinf(theta1) * sinf(phi2)
};
// vec3s n1 = glms_vec3_normalize(glms_vec3_sub(p1, center));
// vec3s n2 = glms_vec3_normalize(glms_vec3_sub(p2, center));
// vec3s n3 = glms_vec3_normalize(glms_vec3_sub(p3, center));
// vec3s n4 = glms_vec3_normalize(glms_vec3_sub(p4, center));
// triangle_create_with_normals(p3, p2, p1, n3, n2, n1, material_id, collection);
// triangle_create_with_normals(p3, p1, p4, n3, n1, n4, material_id, collection);
triangle_create(p3, p2, p1, material_id, collection);
triangle_create(p3, p1, p4, material_id, collection);
}
}
}
// inline void sphere_create(vec3s center, float radius, uint8_t material_id, triangle_collection_t* collection)
// {
// int segments = 16;
// int rings = 16;
//
// for (int i = 0; i < rings; i++)
// {
// float theta1 = (float)i / (float)rings * (float)M_PI;
// float theta2 = (float)(i + 1) / (float)rings * (float)M_PI;
//
// for (int j = 0; j < segments; j++)
// {
// float phi1 = (float)j / (float)segments * 2.0f * (float)M_PI;
// float phi2 = (float)(j + 1) / (float)segments * 2.0f * (float)M_PI;
//
// vec3s p1 = {
// center.x + radius * sinf(theta1) * cosf(phi1),
// center.y + radius * cosf(theta1),
// center.z + radius * sinf(theta1) * sinf(phi1)
// };
// vec3s p2 = {
// center.x + radius * sinf(theta2) * cosf(phi1),
// center.y + radius * cosf(theta2),
// center.z + radius * sinf(theta2) * sinf(phi1)
// };
// vec3s p3 = {
// center.x + radius * sinf(theta2) * cosf(phi2),
// center.y + radius * cosf(theta2),
// center.z + radius * sinf(theta2) * sinf(phi2)
// };
// vec3s p4 = {
// center.x + radius * sinf(theta1) * cosf(phi2),
// center.y + radius * cosf(theta1),
// center.z + radius * sinf(theta1) * sinf(phi2)
// };
//
// // vec3s n1 = glms_vec3_normalize(glms_vec3_sub(p1, center));
// // vec3s n2 = glms_vec3_normalize(glms_vec3_sub(p2, center));
// // vec3s n3 = glms_vec3_normalize(glms_vec3_sub(p3, center));
// // vec3s n4 = glms_vec3_normalize(glms_vec3_sub(p4, center));
//
// // triangle_create_with_normals(p3, p2, p1, n3, n2, n1, material_id, collection);
// // triangle_create_with_normals(p3, p1, p4, n3, n1, n4, material_id, collection);
// triangle_create(p3, p2, p1, material_id, collection);
// triangle_create(p3, p1, p4, material_id, collection);
// }
// }
// }
#endif // GEOMETRY_UTILITIES_H

View File

@@ -3,22 +3,25 @@
#include "Material/Material.h"
#include "Geometry/Triangle.h"
#include "Rendering/Scene.h"
#include <stdint.h>
// TODO: Currently transformation does not work because we store every triangle in to the same buffer and when bulding the bvh, we only consider that triangle buffer.
// One solution for this is we can have two levels of bvh, one for scene and one for each mesh. The mesh level bvh will apply the transformation to the triangles.
// The scene level bvh onlt tells the ray which mesh to check and the mesh level bvh will tell the ray which triangle to check.
// The scene level bvh only tells the ray which mesh to check and the mesh level bvh will tell the ray which triangle to check.
// For instancing, we may need another mesh_model_t struct to store the actual bvh and triangle data(like id and size), and each mesh_entity_t will have a transformation matrix and the id to that mesh_model_t.
// This way we can share the same triangle and bvh for multiple instances of the same mesh, and we can also apply different transformations to each instance.
typedef struct
{
mat4s local_to_world;
uint64_t id;
uint64_t size;
uint64_t triangle_id;
uint64_t triangle_count;
uint16_t material_id;
uint16_t material_count;
} mesh_entity_t;
//HACK: We should handle the material from mesh, not user input.
mesh_entity_t mesh_load(const char* filename, uint8_t material_id, triangle_collection_t* triangles, material_collection_t* materials);
mesh_entity_t mesh_load(const char* filename, scene_t* scene);
#endif // MESH_H

View File

@@ -7,16 +7,19 @@
typedef struct
{
vec3s point_1;
vec3s point_2;
vec3s point_3;
vec3s normal_1;
vec3s normal_2;
vec3s normal_3;
vec3s normal_face;
vec3s position;
vec3s normal;
vec3s color;
vec2s uv;
} vertex_t;
typedef struct
{
vertex_t vertices[3];
vec3s face_normal;
uint8_t material_id;
}triangle_t;
} triangle_t;
//TODO: Handle triangle remove, we can use something like sparse set.
typedef struct
@@ -25,27 +28,24 @@ typedef struct
uint64_t size;
triangle_t* buffer;
}triangle_collection_t;
} triangle_collection_t;
bool triangle_collection_init(triangle_collection_t* triangles, size_t size);
bool triangle_collection_init(size_t size, triangle_collection_t* triangles);
void triangle_collection_resize(triangle_collection_t* collection, size_t size);
void triangle_collection_free(triangle_collection_t* collection);
void triangle_create_with_normals(vec3s point1, vec3s point2, vec3s point3,
vec3s normal1, vec3s normal2, vec3s normal3,
uint8_t material_id, triangle_collection_t* collection);
void triangle_create(vec3s point1, vec3s point2, vec3s point3, uint8_t material_id, triangle_collection_t* collection);
void triangle_create(vertex_t v1, vertex_t v2, vertex_t v3, uint8_t material_id, triangle_collection_t* collection);
inline vec3s triangle_centroid(const triangle_t triangle)
{
return glms_vec3_scale(glms_vec3_add(glms_vec3_add(triangle.point_1, triangle.point_2), triangle.point_3), 1.0f / 3.0f);
return glms_vec3_scale(glms_vec3_add(glms_vec3_add(triangle.vertices[0].position, triangle.vertices[1].position), triangle.vertices[2].position), 1.0f / 3.0f);
}
inline aabb_t compute_bounds_triangle(triangle_t triangle)
{
aabb_t bounds;
bounds.min = glms_vec3_minv(triangle.point_1, glms_vec3_minv(triangle.point_2, triangle.point_3));
bounds.max = glms_vec3_maxv(triangle.point_1, glms_vec3_maxv(triangle.point_2, triangle.point_3));
bounds.min = glms_vec3_minv(triangle.vertices[0].position, glms_vec3_minv(triangle.vertices[1].position, triangle.vertices[2].position));
bounds.max = glms_vec3_maxv(triangle.vertices[0].position, glms_vec3_maxv(triangle.vertices[1].position, triangle.vertices[2].position));
return bounds;
}