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:
2025-05-02 01:25:56 +09:00
parent 0061609267
commit 9a1069db90
18 changed files with 378 additions and 82 deletions

View File

@@ -3,10 +3,10 @@
#include <svpng.inc>
#include "Algorithm/Sobol.h"
// #include "Geometry/GeometryUtilities.h"
#include "Geometry/GeometryUtilities.h"
#include "Geometry/Mesh.h"
#include "Lighting/SkyLight.h"
// #include "Material/SimpleLit.h"
#include "Material/SimpleLit.h"
#include "Rendering/PostProcessing.h"
#include "Rendering/Scene.h"
#include "Window.h"
@@ -21,22 +21,25 @@ static bool scene_setup(scene_t* scene)
return false;
}
scene->camera.position = (vec3s){-7.5f, 2.0f, 0.0f};
scene->camera.rotation = euler_to_quat(10.0f, -90.0f, 0.0f);
scene->camera.position = (vec3s){7.5f, 2.0f, 0.0f};
scene->camera.rotation = euler_to_quat(10.0f, 90.0f, 0.0f);
// TODO: Standardize light unit
light_entity_t sun = light_create_directional_light(&scene->lights);
directional_light_t* sun_light = &scene->lights.directional_lights[sun.id];
sun_light->direction = glms_vec3_normalize((vec3s){-0.5f, 1.0f, 0.25f});
sun_light->direction = glms_vec3_normalize((vec3s){0.5f, 1.0f, -0.25f});
sun_light->color = (vec3s){1.0f, 0.93f, 0.87f};
sun_light->intensity = 2.0f;
sun_light->intensity = 1.0f;
sun_light->angular_diameter = 0.53f;
scene->lights.sky_light = sky_create_constant_sky(&(constant_sky_data_t)
{
.color = (vec3s){0.73f, 0.82f, 1.0f},
.intensity = 1.0f,
});
//scene->lights.sky_light = sky_create_constant_sky(&(constant_sky_data_t)
//{
// .color = (vec3s){0.73f, 0.82f, 1.0f},
// .intensity = 1.0f,
//});
// NOTE: Not sure it's my problem or stb_image's, but the peek value of HDRI is way much lower than actual. Need to double cheeck the cdf.
texture_entity_t hdri = texture_load("./assets/hdri/rogland_sunset_1k.hdr", false, FLOAT_32, &scene->textures);
scene->lights.sky_light = sky_create_hdr_sky(&scene->textures, hdri, 1.0f);
return true;
}
@@ -44,7 +47,17 @@ static bool scene_setup(scene_t* scene)
static bool load_assets(scene_t* scene)
{
mesh_load(SPONZA_PATH, scene);
// quad_create((vec3s){0.0f, 0.0f, 0.0f}, (vec3s){0.0f, 1.0f, 0.0f}, (vec3s){1.0f, 0.0f, 0.0f}, 10.0f, floor_material.id, &scene->triangles);
//material_entity_t floor_material = material_create_simple_lit_default(&(simple_lit_properties_t)
//{
// .albedo = (vec3s){0.8f, 0.8f, 0.8f},
// .roughness = 0.95f,
// .metallic = 0.0f,
// .albedo_texture = invalid_texture_entity(),
// .metallic_texture = invalid_texture_entity(),
// .roughness_texture = invalid_texture_entity(),
//}, &scene->materials);
//quad_create((vec3s){0.0f, 0.0f, 0.0f}, (vec3s){0.0f, 1.0f, 0.0f}, (vec3s){1.0f, 0.0f, 0.0f}, 10.0f, floor_material.id, &scene->triangles);
//quad_create((vec3s){0.0f, 0.5f, 0.0f}, (vec3s){1.0f, 0.0f, 0.0f}, (vec3s){0.0f, 1.0f, 0.0f}, 1.0f, floor_material.id, &scene->triangles);
return scene_build_bvh(scene);
}
@@ -53,7 +66,6 @@ static bool initialize_renderer(const rendering_config_t* config, render_job_t**
{
if (!scene_setup(outScene)
|| !load_assets(outScene)
|| !scene_build_bvh(outScene)
|| !render_target_init(config->width, config->height, outImg))
{
return false;
@@ -155,9 +167,9 @@ int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance,
render_job_t* job = NULL;
rendering_config_t config = {
.width = 1920 / 2,
.height = 1080 / 2,
.sample_count = 16 * 1,
.width = 1920 / 1,
.height = 1080 / 1,
.sample_count = 16 * 8,
.max_depth = 4,
.bucket_size = 64,
};