Set C standard to C11 and add new assets
Changed CMakeLists.txt to set the C standard to C11. Added multiple binary image files for new visual assets. Added several new image files to enhance rendering capabilities. Changed stb_image.h to improve support for various image formats. Changed ray tracing engine to enhance ray creation and intersection. Changed triangle structure to use a vertex array for better attribute handling. Changed scene initialization to accommodate new texture management.
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
#include "Material/Material.h"
|
||||
#include <string.h>
|
||||
|
||||
bool material_collection_init(size_t size, material_collection_t* materials)
|
||||
|
||||
|
||||
bool material_collection_init(uint8_t size, material_collection_t* materials)
|
||||
{
|
||||
if (size > 254)
|
||||
{
|
||||
@@ -41,21 +43,12 @@ void material_collection_free(material_collection_t* materials)
|
||||
{
|
||||
if (materials->buffer != NULL)
|
||||
{
|
||||
for (uint8_t i = 0; i < materials->count; i++)
|
||||
{
|
||||
void* data = materials->buffer[i].data;
|
||||
if (data != NULL)
|
||||
{
|
||||
free(data);
|
||||
}
|
||||
}
|
||||
|
||||
free(materials->buffer);
|
||||
materials->buffer = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
material_entity_t material_create(sample_bsdf_f sample, sample_bsdf_pdf_f sample_pdf, evaluate_bsdf_f evaluate, void* data, size_t size_of_data, material_collection_t* collection)
|
||||
material_entity_t material_create(const void* properties, size_t properties_size, compute_surface_data_f surface_data, sample_bsdf_f sample, sample_bsdf_pdf_f sample_pdf, evaluate_bsdf_f evaluate, material_collection_t* collection)
|
||||
{
|
||||
material_t material = {0};
|
||||
|
||||
@@ -64,16 +57,11 @@ material_entity_t material_create(sample_bsdf_f sample, sample_bsdf_pdf_f sample
|
||||
material_collection_resize(collection, collection->size * 2);
|
||||
}
|
||||
|
||||
memcpy(material.properties, properties, properties_size);
|
||||
material.compute_surface_data = surface_data;
|
||||
material.sample_bsdf = sample;
|
||||
material.sample_bsdf_pdf = sample_pdf;
|
||||
material.evaluate_bsdf = evaluate;
|
||||
material.data = malloc(size_of_data);
|
||||
if (material.data == NULL)
|
||||
{
|
||||
return (material_entity_t){.id = 255};
|
||||
}
|
||||
|
||||
memcpy(material.data, data, size_of_data);
|
||||
|
||||
material_entity_t entity = {.id = collection->count};
|
||||
|
||||
@@ -83,23 +71,36 @@ material_entity_t material_create(sample_bsdf_f sample, sample_bsdf_pdf_f sample
|
||||
return entity;
|
||||
}
|
||||
|
||||
vec3s sample_material_bsdf(const material_t* material, vec3s normal, vec3s wo, uint32_t sample_index, uint32_t bounce, float* pdf_out)
|
||||
vec3s sample_material_bsdf(const material_t* material, vec3s normal, vec3s wo, vec2s uv, uint32_t sample_index, uint32_t bounce, float* pdf_out)
|
||||
{
|
||||
vec3s wi = glms_vec3_zero();
|
||||
if (material->sample_bsdf != NULL)
|
||||
if (material->compute_surface_data != NULL && material->sample_bsdf != NULL)
|
||||
{
|
||||
wi = material->sample_bsdf(material->data, normal, wo, sample_index, bounce, pdf_out);
|
||||
shading_context_t context =
|
||||
{
|
||||
.normal = normal,
|
||||
.wo = wo,
|
||||
.uv = uv,
|
||||
};
|
||||
wi = material->sample_bsdf(&context, material->properties, material->compute_surface_data, sample_index, bounce, pdf_out);
|
||||
}
|
||||
|
||||
return wi;
|
||||
}
|
||||
|
||||
float sample_material_bsdf_pdf(const material_t* material, vec3s normal, vec3s wo, vec3s wi)
|
||||
float sample_material_bsdf_pdf(const material_t* material, vec3s normal, vec3s wo, vec3s wi, vec2s uv)
|
||||
{
|
||||
float pdf = 0.0f;
|
||||
if (material->sample_bsdf_pdf != NULL)
|
||||
if (material->compute_surface_data != NULL && material->sample_bsdf_pdf != NULL)
|
||||
{
|
||||
pdf = material->sample_bsdf_pdf(material->data, normal, wo, wi);
|
||||
shading_context_t context =
|
||||
{
|
||||
.normal = normal,
|
||||
.wo = wo,
|
||||
.wi = wi,
|
||||
.uv = uv,
|
||||
};
|
||||
pdf = material->sample_bsdf_pdf(&context, material->properties, material->compute_surface_data);
|
||||
}
|
||||
|
||||
return pdf;
|
||||
@@ -108,9 +109,9 @@ float sample_material_bsdf_pdf(const material_t* material, vec3s normal, vec3s w
|
||||
vec3s evaluate_material_bsdf(const material_t* material, const shading_context_t* context)
|
||||
{
|
||||
vec3s bsdf_color = glms_vec3_zero();
|
||||
if (material->evaluate_bsdf != NULL)
|
||||
if (material->compute_surface_data != NULL && material->evaluate_bsdf != NULL)
|
||||
{
|
||||
bsdf_color = material->evaluate_bsdf(context, material->data);
|
||||
bsdf_color = material->evaluate_bsdf(context, material->properties, material->compute_surface_data);
|
||||
}
|
||||
|
||||
return bsdf_color;
|
||||
|
||||
Reference in New Issue
Block a user