Add HDR sky lighting support and improve rendering

Added support for HDR sky lighting, including sampling environment maps with a hierarchical CDF.
Added new utility functions for handling HDR sky data, including memory management and sampling functions.
Added functions to improve texture handling, including pixel data retrieval and texture coordinate management.
Changed the path tracing algorithm to enhance light evaluation from HDR skies and adjust light contribution calculations.
Changed BSDF sampling functions to utilize constants from Common.h for better readability.
Changed the main application logic to load HDR textures and configure the scene with improved lighting settings.
Refactored ray intersection logic to enhance accuracy and performance in triangle intersections.
Adjusted the sample count in the rendering configuration to optimize performance.
Updated the README.md to document new features and example renders.
This commit is contained in:
2025-05-04 01:33:00 +09:00
parent 9a1069db90
commit 4c62b3ecde
13 changed files with 381 additions and 320 deletions

View File

@@ -12,7 +12,8 @@
#include "Window.h"
#define TITLE "Path Tracing"
#define SPONZA_PATH "./assets/sponza.fbx"
#define SCENE_PATH "./assets/sponza.fbx"
#define HDRI_PATH "./assets/hdri/rogland_sunset_1k.hdr"
static bool scene_setup(scene_t* scene)
{
@@ -27,9 +28,9 @@ static bool scene_setup(scene_t* scene)
// 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.6f, 1.0f, 0.25f});
sun_light->color = (vec3s){1.0f, 0.93f, 0.87f};
sun_light->intensity = 1.0f;
sun_light->intensity = 0.0f;
sun_light->angular_diameter = 0.53f;
//scene->lights.sky_light = sky_create_constant_sky(&(constant_sky_data_t)
@@ -37,8 +38,7 @@ static bool scene_setup(scene_t* scene)
// .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);
texture_entity_t hdri = texture_load(HDRI_PATH, false, FLOAT_32, &scene->textures);
scene->lights.sky_light = sky_create_hdr_sky(&scene->textures, hdri, 1.0f);
return true;
@@ -46,18 +46,18 @@ static bool scene_setup(scene_t* scene)
static bool load_assets(scene_t* scene)
{
mesh_load(SPONZA_PATH, scene);
//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);
mesh_load(SCENE_PATH, scene);
// 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);
}
@@ -169,7 +169,7 @@ int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance,
rendering_config_t config = {
.width = 1920 / 1,
.height = 1080 / 1,
.sample_count = 16 * 8,
.sample_count = 16 * 4,
.max_depth = 4,
.bucket_size = 64,
};