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,4 +1,5 @@
#include "Rendering/Texture.h"
#include "Common/String.h"
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
@@ -8,7 +9,7 @@
bool texture_collection_init(uint16_t size, texture_collection_t* textures)
{
texture_collection_t temp = {0};
temp.buffer = (texture_t*)malloc(size * sizeof(texture_t));
temp.buffer = (texture_asset_t*)malloc(size * sizeof(texture_asset_t));
if (temp.buffer == NULL)
{
return false;
@@ -23,7 +24,17 @@ bool texture_collection_init(uint16_t size, texture_collection_t* textures)
void texture_collection_resize(texture_collection_t* textures, uint16_t size)
{
texture_t* temp = (texture_t*)realloc(textures->buffer, size * sizeof(texture_t));
if (size == INVALID_TEXTURE_ID)
{
size = INVALID_TEXTURE_ID - 1;
}
if (size == textures->size)
{
return;
}
texture_asset_t* temp = (texture_asset_t*)realloc(textures->buffer, size * sizeof(texture_asset_t));
if (temp != NULL)
{
textures->buffer = temp;
@@ -40,7 +51,13 @@ void texture_collection_free(texture_collection_t* textures)
for (uint16_t i = 0; i < textures->count; i++)
{
texture_free(&textures->buffer[i]);
texture_free(&textures->buffer[i].texture);
char* full_name = textures->buffer[i].full_name;
if (full_name != NULL)
{
free(full_name);
}
}
free(textures->buffer);
@@ -49,6 +66,16 @@ void texture_collection_free(texture_collection_t* textures)
texture_entity_t texture_load(const char* filename, bool srgb, texture_collection_t* textures)
{
// TODO: This hurts performance, consider using a hash map or similar structure for faster lookups
// for (uint16_t i = 0; i < textures->count; i++)
// {
// if (strcmp(textures->buffer[i].full_name, filename) == 0)
// {
// return (texture_entity_t){.id = i};
// }
// }
int width, height, channels;
uint8_t* data = stbi_load(filename, &width, &height, &channels, 0);
if (data == NULL)
@@ -80,7 +107,7 @@ texture_entity_t texture_load(const char* filename, bool srgb, texture_collectio
texture_entity_t entity = {.id = textures->count};
textures->buffer[textures->count] = texture;
textures->buffer[textures->count] = (texture_asset_t){.full_name = string_copy(filename), .texture = texture};
textures->count++;
return entity;