Enhance graphics library functionality and structure

Added new function signatures in `assimp-vc143-mt.lib` for improved logging, parsing, and vector operations.
Added new metadata and configuration information in `assimp-vc143-mt.dll` for versioning and licensing compliance.
Added Sobol sequence generation in `Sobol.c` for quasi-random sampling.
Added window message handling in `Window.c` for rendering graphics.
Added ray-triangle intersection tests in `RayIntersection.c` for collision detection.
Added functions for loading mesh data in `Mesh.c` to support 3D model import.
Added functions for managing triangle collections in `Triangle.c` to enhance geometric data handling.
Added light evaluation functions in `LightEvaluation.c` and `SkyLight.c` for realistic rendering.
Added sampling and evaluation functions for simple lit materials in `SimpleLit.c`.
Changed various header files to include copyright and licensing information.
Changed existing functions in multiple files to improve performance and clarity.
Removed unused code in several files to streamline the library.
This commit is contained in:
2025-04-18 01:54:26 +09:00
parent b915d56f73
commit bfc94f0008
138 changed files with 28915 additions and 534 deletions

View File

@@ -0,0 +1,114 @@
#include "algorithm/RayIntersection.h"
hit_result_t ray_intersect(const triangle_t triangle, const ray_t ray)
{
hit_result_t result = {0};
vec3s normal_face = triangle.normal_face;
float n_dot_r = glms_vec3_dot(normal_face, ray.direction);
if (n_dot_r > 0.0f)
{
normal_face = glms_vec3_negate(normal_face);
}
// triangle is parallel to the ray
if (fabsf(n_dot_r) < FLT_EPSILON)
{
result.hit = false;
return result;
}
// Get distance from ray origin to triangle plane
float distance = (glms_vec3_dot(normal_face, triangle.point_1) - glms_vec3_dot(normal_face, ray.origin)) / glms_vec3_dot(normal_face, ray.direction);
if (distance < FLT_EPSILON)
{
result.hit = false;
return result;
}
vec3s intersection_point = glms_vec3_add(ray.origin, glms_vec3_scale(ray.direction, distance));
// Check if the intersection point is inside the triangle using barycentric coordinates
vec3s edge1 = glms_vec3_sub(triangle.point_2, triangle.point_1);
vec3s edge2 = glms_vec3_sub(triangle.point_3, triangle.point_2);
vec3s edge3 = glms_vec3_sub(triangle.point_1, triangle.point_3);
vec3s vp = glms_vec3_sub(intersection_point, triangle.point_1);
vec3s vp2 = glms_vec3_sub(intersection_point, triangle.point_2);
vec3s vp3 = glms_vec3_sub(intersection_point, triangle.point_3);
vec3s c1 = glms_vec3_cross(edge1, vp);
vec3s c2 = glms_vec3_cross(edge2, vp2);
vec3s c3 = glms_vec3_cross(edge3, vp3);
if (glms_vec3_dot(triangle.normal_face, c1) < 0.0f
|| glms_vec3_dot(triangle.normal_face, c2) < 0.0f
|| glms_vec3_dot(triangle.normal_face, c3) < 0.0f)
{
result.hit = false;
return result;
}
// Normal interpolation
float d00 = glms_vec3_dot(edge1, edge1);
float d01 = glms_vec3_dot(edge1, edge2);
float d11 = glms_vec3_dot(edge2, edge2);
float d20 = glms_vec3_dot(vp, edge1);
float d21 = glms_vec3_dot(vp, edge2);
float denom = d00 * d11 - d01 * d01;
float v = (d11 * d20 - d01 * d21) / denom;
float w = (d00 * d21 - d01 * d20) / denom;
float u = 1.0f - v - w;
vec3s normal_interp = glms_vec3_addadd(
glms_vec3_scale(triangle.normal_1, u),
glms_vec3_scale(triangle.normal_2, v),
glms_vec3_scale(triangle.normal_3, w));
normal_interp = glms_vec3_normalize(normal_interp);
if (n_dot_r > 0.0f)
{
normal_interp = glms_vec3_negate(normal_interp);
}
result.hit = true;
result.point = intersection_point;
result.normal = normal_interp;
result.distance = distance;
return result;
}
hit_result_t ray_intersect_closest(const triangle_collection_t* triangles, const ray_t ray)
{
hit_result_t closest_hit = {0};
closest_hit.distance = FLT_MAX;
for (uint64_t i = 0; i < triangles->count; i++)
{
hit_result_t hit_result = ray_intersect(triangles->buffer[i], ray);
if (hit_result.hit && hit_result.distance < closest_hit.distance)
{
closest_hit = hit_result;
closest_hit.triangle_id = i;
}
}
return closest_hit;
}
hit_result_t ray_intersect_any(const triangle_collection_t* triangles, const ray_t ray)
{
for (uint64_t i = 0; i < triangles->count; i++)
{
hit_result_t hit_result = ray_intersect(triangles->buffer[i], ray);
if (hit_result.hit)
{
hit_result.triangle_id = i;
return hit_result;
}
}
return (hit_result_t){0};
}