Add HDR files and improve light handling
Added three binary files: `golden_gate_hills_1k.hdr`, `rogland_sunset_1k.hdr`, and `studio_small_03_1k.hdr`. Added a new inline function `weight_nee_light` in `BSDF.h` to compute the weighted contribution of light based on the next event estimation (NEE). Added a new function pointer type `sky_free_f` in `Light.h` for freeing sky light data. Added a new structure `hdr_sky_data_t` in `SkyLight.h` to hold HDR sky data, including texture and intensity. Changed the `RAY_EPSILON` definition in `Common.h` to a new value. Changed the `light_collection_free` function in `Light.h` to include freeing sky light data if it exists. Changed the `sky_create_hdr_sky` function in `SkyLight.h` to initialize HDR sky data and compute marginal and conditional distributions. Changed the `texture_load` function in `Texture.h` to accept a `stride` parameter for different texture formats. Changed the `evaluate_bsdf_directional` function in `LightEvaluation.c` to handle light intensity checks. Changed the `evaluate_bsdf_const_sky` function in `SkyLight.c` to use a pointer for sky data and added checks for intensity. Removed TODO comments related to handling triangle and material removal in `Triangle.h` and `Light.h`. Removed the old `weight_sky_light` function in `SkyLight.h` and replaced it with the new `weight_nee_light` function. Updated the `scene_setup` function in `main.c` to change camera position and light direction, and to load HDR textures. Increased the sample count in the rendering configuration in `main.c` for better quality rendering.
This commit is contained in:
@@ -2,12 +2,11 @@
|
||||
#include "Algorithm/BSDF.h"
|
||||
#include "Algorithm/Sobol.h"
|
||||
#include "Lighting/LightEvaluation.h"
|
||||
#include "Lighting/SkyLight.h"
|
||||
|
||||
#include <float.h>
|
||||
|
||||
static float DIELECTRIC_REFLECTIVE_F0 = 0.04f; // Standard dielectric reflectivity coef at incident angle (= 4%)
|
||||
static vec3s DIELECTRIC_REFLECTIVE = {0.04f, 0.04f, 0.04f}; // Standard dielectric reflectivity coef at incident angle (= 4%)
|
||||
static float DIELECTRIC_REFLECTIVE_F0 = 0.04f; // Standard dielectric reflectivity coef at incident angle (= 4%)
|
||||
static vec3s DIELECTRIC_REFLECTIVE = {0.04f, 0.04f, 0.04f};
|
||||
|
||||
static void get_surface_data(const shading_context_t* context, const void* properties, surface_data_t* data_out)
|
||||
{
|
||||
@@ -20,16 +19,13 @@ static void get_surface_data(const shading_context_t* context, const void* prope
|
||||
data_out->albedo = glms_vec3_mul(data_out->albedo, glms_vec3(texture_sample(albedo_texture, context->uv.x, context->uv.y)));
|
||||
}
|
||||
|
||||
data_out->normal = context->normal;
|
||||
const texture_t* normal_texture = get_texture(context->textures, prop->normal_texture);
|
||||
if (normal_texture != NULL && normal_texture->data != NULL)
|
||||
{
|
||||
vec3s normal_sample = glms_vec3(texture_sample(normal_texture, context->uv.x, context->uv.y));
|
||||
normal_sample = normal_unpack(normal_sample);
|
||||
data_out->normal = normal_ts_to_ws(normal_sample, context->tangent);
|
||||
}
|
||||
else
|
||||
{
|
||||
data_out->normal = context->normal;
|
||||
data_out->normal = glms_vec3_add(data_out->normal, normal_ts_to_ws(normal_sample, context->tangent));
|
||||
}
|
||||
|
||||
data_out->roughness = prop->roughness;
|
||||
@@ -160,7 +156,7 @@ static float sample_bsdf_pdf_simple_lit(const shading_context_t* context, const
|
||||
float pdf_diff = pdf_cosine_weighted_hemisphere(context->normal, wi);
|
||||
float diffuse_pdf_component = prob_diffuse * pdf_diff;
|
||||
|
||||
// HACK: Check this.
|
||||
// When computing specular PDF, L is the wi and wi is the view direction
|
||||
float pdf_spec = pdf_blinn_phong_lobe(context->normal, L, wi, surface_data->roughness);
|
||||
float specular_pdf_component = prob_specular * pdf_spec;
|
||||
|
||||
@@ -199,6 +195,7 @@ static vec3s evaluate_bsdf_simple_lit(const shading_context_t* context, const su
|
||||
return glms_vec3_add(diffuse_term, specular_term);
|
||||
}
|
||||
|
||||
// NOTE: Need to double check is this physically correct, especially the nee and mis.
|
||||
path_output simple_lit_render_loop(const void* properties, const shading_context_t* context)
|
||||
{
|
||||
surface_data_t surface_data = {0};
|
||||
@@ -233,7 +230,7 @@ path_output simple_lit_render_loop(const void* properties, const shading_context
|
||||
path_output light_output = evaluate_bsdf_directional(context->lights->directional_lights[i], &light_context, context->throughput, context->sample_index);
|
||||
if (light_output.state == NORMAL)
|
||||
{
|
||||
vec3s bsdf_dir_light = evaluate_bsdf_simple_lit(context, &surface_data, light_output.wi);
|
||||
vec3s bsdf_dir_light = evaluate_bsdf_simple_lit(context, &surface_data, light_output.wi);
|
||||
vec3s light_contribute = glms_vec3_mul(light_output.direct_lighting, bsdf_dir_light);
|
||||
output.direct_lighting = glms_vec3_add(output.direct_lighting, light_contribute);
|
||||
}
|
||||
@@ -245,7 +242,7 @@ path_output simple_lit_render_loop(const void* properties, const shading_context
|
||||
{
|
||||
vec3s bsdf_sky_light = evaluate_bsdf_simple_lit(context, &surface_data, sky_output.wi);
|
||||
float pdf_bsdf = sample_bsdf_pdf_simple_lit(context, &surface_data, sky_output.wi);
|
||||
vec3s sky_light = weight_sky_light(bsdf_sky_light, sky_output.direct_lighting, pdf_bsdf, sky_output.pdf);
|
||||
vec3s sky_light = weight_nee_light(bsdf_sky_light, sky_output.direct_lighting, sky_output.pdf, pdf_bsdf);
|
||||
output.direct_lighting = glms_vec3_add(output.direct_lighting, sky_light);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user