Files
SimpleRayTracing/source/Material/Material.c
Misaki 0061609267 Refactor path tracing and material rendering system
Added a new enum `path_state` and a struct `path_output` in `Common.h` to manage path tracing states and outputs.
Added a new `simple_lit_render_loop` function in `SimpleLit.c` to handle rendering for simple lit materials, integrating light contributions and BSDF evaluations.

Changed the function signatures in `Light.h` to use `path_output` instead of `vec3s` for BSDF evaluations.
Changed the `evaluate_bsdf_directional` function in `LightEvaluation.h` to return `path_output` instead of `vec3s`.
Changed the `evaluate_bsdf_sky` function in `LightEvaluation.h` to return `path_output` and updated its implementation accordingly.
Changed the function signature of `evaluate_bsdf_const_sky` in `SkyLight.h` to return `path_output` and modified its implementation to match.

Removed several old BSDF-related functions in `Material.c` that are no longer needed due to the new structure.

Updated the `material_create` function in `Material.c` to accept the new render loop function pointer.
Updated the `path_trace` function in `PathTracing.c` to utilize the new `path_output` structure for managing light contributions and state transitions during path tracing.
Updated the `evaluate_bsdf_directional` function in `LightEvaluation.c` to return `path_output` and adjusted its internal logic to populate the output structure.
Updated the `evaluate_bsdf_const_sky` function in `SkyLight.c` to return `path_output` and modified its logic to handle light contributions correctly.
Updated the intensity of the sky light to `0.0f` during scene setup in `main.c`, effectively disabling it.
2025-05-01 01:21:48 +09:00

73 lines
1.6 KiB
C

#include "Material/Material.h"
#include <string.h>
bool material_collection_init(uint8_t size, material_collection_t* materials)
{
if (size > 254)
{
size = 254;
}
material_collection_t temp = {0};
temp.buffer = (material_t*)malloc(size * sizeof(material_t));
if (temp.buffer == NULL)
{
return false;
}
temp.size = (uint8_t)size;
temp.count = 0;
*materials = temp;
return true;
}
void material_collection_resize(material_collection_t* materials, size_t size)
{
if (size == INVALID_MATERIAL_ID)
{
size = INVALID_MATERIAL_ID - 1;
}
if (size == materials->size)
{
return;
}
material_t* temp = (material_t*)realloc(materials->buffer, size * sizeof(material_t));
if (temp != NULL)
{
materials->buffer = temp;
materials->size = (uint8_t)size;
}
}
void material_collection_free(material_collection_t* materials)
{
if (materials->buffer != NULL)
{
free(materials->buffer);
materials->buffer = NULL;
}
}
material_entity_t material_create(const void* properties, size_t properties_size, material_render_loop_f render_loop, material_collection_t* collection)
{
material_t material = {0};
if (collection->count >= collection->size)
{
material_collection_resize(collection, collection->size * 2);
}
memcpy(material.properties, properties, properties_size);
material.render_loop = render_loop;
material_entity_t entity = {.id = collection->count};
collection->buffer[collection->count] = material;
collection->count++;
return entity;
}