Files
SimpleRayTracing/header/Geometry/AABB.h
Misaki 6800810369 Update project structure and improve performance
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.
2025-04-21 15:56:19 +09:00

76 lines
1.6 KiB
C

#ifndef AABB_H
#define AABB_H
#include "cglm/struct/vec3.h"
typedef struct
{
vec3s min;
vec3s max;
} aabb_t;
inline aabb_t invalid_aabb()
{
return (aabb_t){
.min = {FLT_MAX, FLT_MAX, FLT_MAX},
.max = {-FLT_MAX, -FLT_MAX, -FLT_MAX},
};
}
inline void aabb_growth(aabb_t* aabb, vec3s point)
{
aabb->min = glms_vec3_minv(aabb->min, point);
aabb->max = glms_vec3_maxv(aabb->max, point);
}
inline void aabb_growth_min_max(aabb_t* aabb, vec3s min, vec3s max)
{
aabb->min = glms_vec3_minv(aabb->min, min);
aabb->max = glms_vec3_maxv(aabb->max, max);
}
inline bool aabb_eq(aabb_t a, aabb_t b)
{
return glms_vec3_eqv(a.min, b.min) && glms_vec3_eqv(a.max, b.max);
}
inline bool aabb_is_valid(aabb_t aabb)
{
return aabb.max.x >= aabb.min.x && aabb.max.y >= aabb.min.y && aabb.max.z >= aabb.min.z;
}
inline aabb_t aabb_union(aabb_t a, aabb_t b)
{
if (!aabb_is_valid(a) && !aabb_is_valid(b))
{
return invalid_aabb();
}
else if (!aabb_is_valid(a))
{
return b;
}
else if (!aabb_is_valid(b))
{
return a;
}
aabb_t result;
result.min = glms_vec3_minv(a.min, b.min);
result.max = glms_vec3_maxv(a.max, b.max);
return result;
}
inline float aabb_surface_area(aabb_t aabb)
{
vec3s extent = glms_vec3_sub(aabb.max, aabb.min);
return 2.0f * (extent.x * extent.y + extent.x * extent.z + extent.y * extent.z);
}
inline float aabb_volume(aabb_t aabb)
{
vec3s extent = glms_vec3_sub(aabb.max, aabb.min);
return extent.x * extent.y * extent.z;
}
#endif // AABB_H