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

@@ -1,8 +1,6 @@
#include "Material/Material.h"
#include <string.h>
bool material_collection_init(uint8_t size, material_collection_t* materials)
{
if (size > 254)
@@ -26,9 +24,14 @@ bool material_collection_init(uint8_t size, material_collection_t* materials)
void material_collection_resize(material_collection_t* materials, size_t size)
{
if (size > 254)
if (size == INVALID_MATERIAL_ID)
{
size = 254; // Limit the count to 254 to fit in a uint8_t
size = INVALID_MATERIAL_ID - 1;
}
if (size == materials->size)
{
return;
}
material_t* temp = (material_t*)realloc(materials->buffer, size * sizeof(material_t));

View File

@@ -11,16 +11,27 @@ void simple_lit_data_default(const shading_context_t* context, const void* prope
const simple_lit_properties_t* prop = (simple_lit_properties_t*)properties;
simple_lit_data_t* data = (simple_lit_data_t*)data_out;
data->albedo = prop->albedo;
data->albedo = prop->albedo;
const texture_t* albedo_texture = get_texture(context->textures, prop->albedo_texture);
if (albedo_texture != NULL && albedo_texture->data != NULL)
{
data->albedo = glms_vec3_mul(data->albedo, glms_vec3(texture_sample(albedo_texture, context->uv.x, context->uv.y)));
}
data->roughness = prop->roughness;
const texture_t* normal_texture = get_texture(context->textures, prop->normal_texture);
if (normal_texture != NULL && normal_texture->data != NULL)
{
vec3s normal_sample = glms_vec3(texture_sample(normal_texture, context->uv.x, context->uv.y));
normal_sample = normal_unpack(normal_sample);
data->normal = normal_ts_to_ws(normal_sample, context->tangent);
}
else
{
data->normal = context->normal;
}
data->roughness = prop->roughness;
const texture_t* roughness_texture = get_texture(context->textures, prop->roughness_texture);
if (roughness_texture != NULL && roughness_texture->data != NULL)
{
@@ -28,7 +39,6 @@ void simple_lit_data_default(const shading_context_t* context, const void* prope
}
data->metallic = prop->metallic;
const texture_t* metallic_texture = get_texture(context->textures, prop->metallic_texture);
if (metallic_texture != NULL && metallic_texture->data != NULL)
{