Added new files for BVH, AABB, and Debug functionalities. Added new utility functions in Common.h. Added gamma correction function in PostProcessing.h. Changed the return type of path_trace to vec4s for alpha blending. Changed BSDF function signatures to include sample index and bounce. Changed the BSDF.h to replace inline functions with declarations. Changed the Light and SkyLight evaluation functions to include throughput and sample index. Changed the sphere creation function in GeometryUtilities.h for better quality. Changed the scene structure to include a BVH tree for improved ray intersection. Changed the scene initialization parameters for better performance. Created new Debug functions for ray intersection counting. Created new functions for triangle collection management in Triangle.c. Improved pixel updating logic in Window.c. Improved ray intersection performance with new BVH implementation. Removed unused includes from Common.h. Removed old library linking methods in CMakeLists.txt.
53 lines
1.6 KiB
C
53 lines
1.6 KiB
C
#ifndef TRIANGLE_H
|
|
#define TRIANGLE_H
|
|
|
|
#include "Common.h"
|
|
#include "Geometry/AABB.h"
|
|
#include <stdint.h>
|
|
|
|
typedef struct
|
|
{
|
|
vec3s point_1;
|
|
vec3s point_2;
|
|
vec3s point_3;
|
|
vec3s normal_1;
|
|
vec3s normal_2;
|
|
vec3s normal_3;
|
|
vec3s normal_face; // Interpolated normal, not used in the triangle itself, but for ray intersection.
|
|
|
|
uint8_t material_id;
|
|
}triangle_t;
|
|
|
|
//TODO: Handle triangle remove, we can use something like sparse set.
|
|
typedef struct
|
|
{
|
|
uint64_t count;
|
|
uint64_t size;
|
|
|
|
triangle_t* buffer;
|
|
}triangle_collection_t;
|
|
|
|
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);
|
|
|
|
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);
|
|
}
|
|
|
|
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));
|
|
return bounds;
|
|
}
|
|
|
|
#endif // TRIANGLE_H
|