Added LICENSE file with MIT License and copyright notice. Added preview.png binary file for project assets. Changed CMakeLists.txt to include asset copying command. Changed mesh loading in Mesh.c to support smooth normals. Changed ray origin biasing in PathTracing.c and shadow rays. Changed ray-triangle intersection logic in RayIntersection.c. Changed ray_intersect_bvh_count function in Debug.c to static. Changed rendering functions in Scene.c with TODO for optimization. Updated README.md with project description and build instructions. Updated window dimensions in main.c for testing purposes.
45 lines
1.6 KiB
C
45 lines
1.6 KiB
C
#include "Lighting/LightEvaluation.h"
|
|
#include "Algorithm/BSDF.h"
|
|
#include "Algorithm/RayIntersection.h"
|
|
|
|
vec3s evaluate_bsdf_directional(directional_light_t light, const light_shading_context_t* context, vec3s throughput, uint32_t sample_index)
|
|
{
|
|
float angular_radius = glm_rad(light.angular_diameter / 2.0f);
|
|
|
|
uint16_t d1 = sobol_get_dimension(context->bounce_depth, PRNG_LIGHT_U);
|
|
uint16_t d2 = sobol_get_dimension(context->bounce_depth, PRNG_LIGHT_V);
|
|
|
|
vec3s wi = random_uniform_cdf_direction_angular(light.direction, sample_index, angular_radius, d1, d2);
|
|
|
|
float n_dot_l = glms_vec3_dot(context->normal, wi);
|
|
if (n_dot_l <= 0.0f)
|
|
{
|
|
return glms_vec3_zero();
|
|
}
|
|
|
|
ray_t shadow_ray = {
|
|
.origin = BIAS_RAY_ORIGION(context->hit_point, context->normal),
|
|
.direction = wi,
|
|
};
|
|
|
|
float closest = FLT_MAX;
|
|
hit_result_t shadow_hit = {1};
|
|
ray_intersect_bvh(shadow_ray, context->bvh_tree->nodes, context->bvh_tree->primitive_indices, context->bvh_tree->triangles, 0,
|
|
&closest, &shadow_hit);
|
|
if (shadow_hit.hit)
|
|
{
|
|
return glms_vec3_zero();
|
|
}
|
|
|
|
shading_context_t shading_context = {
|
|
.normal = context->normal,
|
|
.wi = wi,
|
|
.wo = glms_vec3_negate(context->wo)
|
|
};
|
|
vec3s bsdf = evaluate_material_bsdf(context->material, &shading_context);
|
|
|
|
vec3s light_radiance = glms_vec3_scale(light.color, light.intensity);
|
|
vec3s light_contribute = glms_vec3_scale(glms_vec3_mul(throughput, bsdf), fmaxf(0.0f, n_dot_l));
|
|
return glms_vec3_mul(light_radiance, light_contribute);
|
|
}
|