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

@@ -57,7 +57,7 @@ vec3s normal_ts_to_ws(vec3s normal, vec3s tangent)
float pdf_cosine_weighted_hemisphere(vec3s normal, vec3s wi)
{
return fmaxf(glms_vec3_dot(wi, normal), 0.0f) / (float)M_PI;
return fmaxf(glms_vec3_dot(wi, normal), 0.0f) / PI;
}
float pdf_blinn_phong_lobe(vec3s normal, vec3s wi, vec3s wo, float roughness)
@@ -85,7 +85,7 @@ float pdf_blinn_phong_lobe(vec3s normal, vec3s wi, vec3s wo, float roughness)
// PDF of sampling h (Blinn-Phong distribution)
// D(h) = (specular_exponent + 1) / (2 * PI) * pow(max(0, dot(n, h)), specular_exponent)
float n_dot_h = fmaxf(0.0f, glms_vec3_dot(normal, h));
float pdf_h = (specular_exponent + 1.0f) / (2.0f * (float)M_PI) * powf(n_dot_h, specular_exponent);
float pdf_h = (specular_exponent + 1.0f) / (2.0f * PI) * powf(n_dot_h, specular_exponent);
// Jacobian of the transformation from h to wi
// jacobian = 1 / (4 * dot(wo, h))
@@ -103,7 +103,7 @@ vec3s sample_cosine_weighted_hemisphere_z_angular(float angular, uint32_t index,
float r1 = sobol_sample(index, d1);
float r2 = sobol_sample(index, d2);
float phi = 2.0f * (float)M_PI * r1;
float phi = 2.0f * PI * r1;
float cos_angular = cosf(angular);
// Correctly sample cos(theta) for cosine weighting within the cone [cos_angular, 1]
@@ -128,7 +128,7 @@ vec3s sample_cosine_weighted_hemisphere_z(uint32_t index, uint32_t d1, uint32_t
float r2 = sobol_sample(index, d2);
float r = sqrtf(r1);
float phi = 2.0f * (float)M_PI * r2;
float phi = 2.0f * PI * r2;
float disk_x = r * cosf(phi);
float disk_y = r * sinf(phi);
@@ -198,7 +198,7 @@ vec3s random_uniform_cdf_direction(vec3s direction, uint32_t index, uint32_t d1,
float r1 = sobol_sample(index, d1);
float r2 = sobol_sample(index, d2);
float phi = 2.0f * (float)M_PI * r1;
float phi = 2.0f * PI * r1;
float cos_theta = 1.0f - r2 * 2.0f;
float sin_theta = sqrtf(fmaxf(0.0f, 1.0f - cos_theta * cos_theta));
@@ -226,7 +226,7 @@ vec3s random_uniform_cdf_direction_angular(vec3s direction, uint32_t index, floa
float cos_theta = 1.0f - r1 * (1.0f - cos_alpha);
float sin_theta = sqrtf(fmaxf(0.0f, 1.0f - cos_theta * cos_theta));
float phi = 2.0f * (float)M_PI * r2;
float phi = 2.0f * PI * r2;
float x = sin_theta * cosf(phi);
float y = sin_theta * sinf(phi);