Update rendering, material handling, and shading logic

Changed README.md to update rendering settings and build instructions.
Changed BSDF.h to add functions for normal unpacking and tangent transformation.
Changed RayIntersection.h to include tangent vector in hit_result_t.
Changed Common.h to include vec2.h for 2D vector handling.
Changed String.h to add string_copy function and improve is_absolute_path.
Changed GeometryUtilities.h to enhance quad creation with tangent calculations.
Changed Mesh.h to include tangents in the vertex structure.
Changed Triangle.h to add tangents in the vertex structure for better normal mapping.
Changed Light.h to include tangents in the light shading context.
Changed SkyLight.h to introduce a new structure for sky lights.
Changed Material.h to include tangents in the shading context.
Changed SimpleLit.h to add normal and tangent textures for detailed shading.
Changed Texture.h to introduce a new structure for texture assets.
Changed BSDF.c to add functions for unpacking normals and transforming tangents.
Changed PathTracing.c to include tangents in the shading context.
Changed RayIntersection.c to calculate normals and tangents in ray-triangle intersections.
Changed Mesh.c to improve material texture loading and handle tangents.
Changed Material.c to enhance material collection initialization and resizing.
Changed SimpleLit.c to incorporate normal mapping with normal textures.
Changed Texture.c to improve management of texture assets and resources.
This commit is contained in:
2025-04-29 17:58:10 +09:00
parent 3c3168af7a
commit fb1ff5cac6
21 changed files with 257 additions and 145 deletions

View File

@@ -2,17 +2,37 @@
#define STRING_H
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
static inline bool is_absolute_path(const char* path)
inline char* string_copy(const char* source)
{
if (!path || !*path) return false;
if (source == NULL)
{
return NULL;
}
size_t len = strlen(source) + 1;
char* copy = (char*)malloc(len);
if (copy == NULL)
{
return NULL;
}
strcpy_s(copy, len, source);
return copy;
}
inline bool is_absolute_path(const char* path)
{
if (path == NULL)
{
return false;
}
#ifdef _WIN32
// 1) Drive-letter paths: "C:\…", "D:/…"
if (isalpha((unsigned char)path[0]) &&
path[1] == ':' &&
(path[2] == '\\' || path[2] == '/'))
if (isalpha((unsigned char)path[0]) && path[1] == ':' && (path[2] == '\\' || path[2] == '/'))
{
return true;
}
@@ -29,7 +49,7 @@ static inline bool is_absolute_path(const char* path)
#endif
}
static inline void get_path_directory(const char* path, char* out, size_t out_size)
inline void get_path_directory(const char* path, char* out, size_t out_size)
{
if (path == NULL || out == NULL || out_size == 0)
{
@@ -42,14 +62,16 @@ static inline void get_path_directory(const char* path, char* out, size_t out_si
const char* last_slash = strrchr(path, '/');
if (!last_slash)
if (last_slash == NULL)
{
if (out_size > 0)
{
out[0] = '\0';
}
return;
}
size_t dir_len = (size_t)(last_slash - path);
size_t dir_len = (size_t)(last_slash - path + 1);
if (dir_len >= out_size)
{
@@ -57,21 +79,27 @@ static inline void get_path_directory(const char* path, char* out, size_t out_si
}
memcpy(out, path, dir_len);
out[dir_len] = '/';
out[dir_len + 1] = '\0';
out[dir_len - 1] = '/';
out[dir_len] = '\0';
}
static inline void string_join(const char* a, const char* b, char* out, size_t out_size)
inline void string_join(const char* a, const char* b, char* out, size_t out_size)
{
if (a == NULL || b == NULL || out == NULL || out_size == 0) return;
if (a == NULL || b == NULL || out == NULL || out_size == 0)
{
return;
}
size_t a_len = strlen(a);
size_t b_len = strlen(b);
if (a_len + b_len + 1 >= out_size) return; // +1 for null terminator
if (a_len + b_len + 1 >= out_size)
{
return;
}
strcpy(out, a);
strcat(out, b);
strcpy_s(out, out_size, a);
strcat_s(out, out_size, b);
}
#endif // STRING_H