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.
This commit is contained in:
@@ -51,7 +51,7 @@ void material_collection_free(material_collection_t* materials)
|
||||
}
|
||||
}
|
||||
|
||||
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_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};
|
||||
|
||||
@@ -61,10 +61,7 @@ material_entity_t material_create(const void* properties, size_t properties_size
|
||||
}
|
||||
|
||||
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.render_loop = render_loop;
|
||||
|
||||
material_entity_t entity = {.id = collection->count};
|
||||
|
||||
@@ -73,36 +70,3 @@ material_entity_t material_create(const void* properties, size_t properties_size
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
vec3s sample_material_bsdf(const material_t* material, const shading_context_t* context, uint32_t sample_index, uint32_t bounce, float* pdf_out)
|
||||
{
|
||||
vec3s wi = glms_vec3_zero();
|
||||
if (material->compute_surface_data != NULL && material->sample_bsdf != NULL)
|
||||
{
|
||||
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, const shading_context_t* context)
|
||||
{
|
||||
float pdf = 0.0f;
|
||||
if (material->compute_surface_data != NULL && material->sample_bsdf_pdf != NULL)
|
||||
{
|
||||
pdf = material->sample_bsdf_pdf(context, material->properties, material->compute_surface_data);
|
||||
}
|
||||
|
||||
return pdf;
|
||||
}
|
||||
|
||||
vec3s evaluate_material_bsdf(const material_t* material, const shading_context_t* context)
|
||||
{
|
||||
vec3s bsdf_color = glms_vec3_zero();
|
||||
if (material->compute_surface_data != NULL && material->evaluate_bsdf != NULL)
|
||||
{
|
||||
bsdf_color = material->evaluate_bsdf(context, material->properties, material->compute_surface_data);
|
||||
}
|
||||
|
||||
return bsdf_color;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user