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:
2025-05-01 01:21:39 +09:00
parent 2c0d5a2364
commit 0061609267
13 changed files with 240 additions and 201 deletions

View File

@@ -4,7 +4,7 @@
#include "Algorithm/BVH.h"
#include "Algorithm/Sobol.h"
#include "Geometry/Triangle.h"
#include "Material/Material.h"
#include "Rendering/Texture.h"
#include "cglm/struct/vec3.h"
#define SKY_DATA_CAPACITY 64
@@ -20,7 +20,6 @@ typedef struct
uint16_t bounce_depth;
const bvh_tree_t* bvh_tree;
const material_t* material;
const texture_collection_t* textures;
} light_shading_context_t;
@@ -30,7 +29,7 @@ typedef struct
#define SKY_ALIGN (sizeof(void*))
#endif
typedef vec3s (*evaluate_bsdf_sky_f) (const void* data, const light_shading_context_t* context, vec3s throughput, uint32_t index);
typedef path_output (*evaluate_bsdf_sky_f) (const void* data, const light_shading_context_t* context, vec3s throughput, uint32_t sample_index);
typedef struct
{

View File

@@ -6,17 +6,17 @@
#include "Geometry/Triangle.h"
#include "Rendering/Scene.h"
vec3s evaluate_bsdf_directional( directional_light_t light, const light_shading_context_t* context, vec3s throughput, uint32_t sample_index);
path_output evaluate_bsdf_directional( directional_light_t light, const light_shading_context_t* context, vec3s throughput, uint32_t sample_index);
inline vec3s evaluate_bsdf_sky(const scene_t* scene, const light_shading_context_t* context, vec3s throughput, uint32_t sample_index)
inline path_output evaluate_bsdf_sky(const light_collection_t* lights, const light_shading_context_t* context, vec3s throughput, uint32_t sample_index)
{
vec3s ske_color = glms_vec3_zero();
if (scene->lights.sky_light.evaluate_bsdf_sky != NULL)
path_output output = {0};
if (lights->sky_light.evaluate_bsdf_sky != NULL)
{
ske_color = scene->lights.sky_light.evaluate_bsdf_sky(scene->lights.sky_light.data, context, throughput, sample_index);
output = lights->sky_light.evaluate_bsdf_sky(lights->sky_light.data, context, throughput, sample_index);
}
return ske_color;
return output;
}
#endif // LIGHT_EVALUATION_H

View File

@@ -1,7 +1,9 @@
#ifndef SKY_LIGHT_H
#define SKY_LIGHT_H
#include "Algorithm/BSDF.h"
#include "Light.h"
#include <string.h>
typedef struct
@@ -10,7 +12,15 @@ typedef struct
float intensity;
} constant_sky_data_t;
vec3s evaluate_bsdf_const_sky(const void* data, const light_shading_context_t* context, vec3s throughput, uint32_t sample_index);
path_output evaluate_bsdf_const_sky(const void* data, const light_shading_context_t* context, vec3s throughput, uint32_t sample_index);
// Must use this function to weight the sky light contribution because of nee.
inline vec3s weight_sky_light(vec3s bsdf, vec3s sky_light, float pdf_bsdf, float pdf_sky)
{
bsdf = glms_vec3_mul(bsdf, sky_light);
float weight = power_heuristic(pdf_sky, pdf_bsdf);
return glms_vec3_scale(bsdf, weight);
}
inline sky_light_t sky_create_constant_sky(const constant_sky_data_t* data)
{