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:
@@ -1,6 +1,5 @@
|
||||
#include "Algorithm/PathTracing.h"
|
||||
#include "Algorithm/RayIntersection.h"
|
||||
#include "Algorithm/BSDF.h"
|
||||
#include "Lighting/LightEvaluation.h"
|
||||
|
||||
// TODO: Split the diffuse and specular into different Monte Carlo, so we can decide the sample count for each one
|
||||
@@ -10,7 +9,6 @@ vec4s path_trace(const scene_t* scene, ray_t ray, uint32_t sample_index, uint16_
|
||||
vec3s throughput = glms_vec3_one();
|
||||
|
||||
ray_t active_ray = ray;
|
||||
vec3s prev_normal = glms_vec3_zero();
|
||||
float pdf_bsdf = 1.0f;
|
||||
|
||||
uint16_t depth = 0;
|
||||
@@ -27,12 +25,6 @@ vec4s path_trace(const scene_t* scene, ray_t ray, uint32_t sample_index, uint16_
|
||||
.textures = &scene->textures,
|
||||
};
|
||||
path_output sky_output = evaluate_bsdf_sky(&scene->lights, &light_context, throughput, sample_index);
|
||||
if (depth > 0)
|
||||
{
|
||||
// Have to multiply the weight since we evaluate the sky at each bounce
|
||||
float weight = power_heuristic(pdf_bsdf, sky_output.pdf);
|
||||
sky_output.direct_lighting = glms_vec3_scale(sky_output.direct_lighting, weight);
|
||||
}
|
||||
accumulated_color = glms_vec4_add(accumulated_color, glms_vec4(sky_output.direct_lighting, 0.0f));
|
||||
break;
|
||||
}
|
||||
@@ -58,21 +50,11 @@ vec4s path_trace(const scene_t* scene, ray_t ray, uint32_t sample_index, uint16_
|
||||
|
||||
path_output material_output = render_material(hit_material, &shading_context);
|
||||
accumulated_color = glms_vec4_add(accumulated_color, glms_vec4(material_output.direct_lighting, 0.0f));
|
||||
pdf_bsdf = material_output.pdf;
|
||||
|
||||
float cos_theta = fmaxf(0.0f, glms_vec3_dot(material_output.wi, closest_hit.normal));
|
||||
throughput = glms_vec3_mul(throughput, material_output.bsdf);
|
||||
|
||||
switch (material_output.state)
|
||||
{
|
||||
case TERMINATE:
|
||||
goto end_path_trace;
|
||||
case PATH_THROUGH:
|
||||
active_ray = ray_create(BIAS_RAY_ORIGION(closest_hit.point, glms_vec3_negate(closest_hit.normal)), active_ray.direction);
|
||||
continue;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
// We do Russian roulette to decide whether to continue tracing or terminate the path
|
||||
if (depth > 1)
|
||||
{
|
||||
@@ -86,11 +68,18 @@ vec4s path_trace(const scene_t* scene, ray_t ray, uint32_t sample_index, uint16_
|
||||
throughput = glms_vec3_scale(throughput, 1.0f / q);
|
||||
}
|
||||
|
||||
active_ray = ray_create(BIAS_RAY_ORIGION(closest_hit.point, closest_hit.normal), material_output.wi);
|
||||
prev_normal = closest_hit.normal;
|
||||
pdf_bsdf = material_output.pdf;
|
||||
|
||||
depth++;
|
||||
switch (material_output.state)
|
||||
{
|
||||
case TERMINATE:
|
||||
goto end_path_trace;
|
||||
//case PATH_THROUGH:
|
||||
// active_ray = ray_create(BIAS_RAY_ORIGION(closest_hit.point, glms_vec3_negate(closest_hit.normal)), active_ray.direction);
|
||||
// continue;
|
||||
default:
|
||||
active_ray = ray_create(BIAS_RAY_ORIGION(closest_hit.point, closest_hit.normal), material_output.wi);
|
||||
depth++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
end_path_trace:
|
||||
|
||||
Reference in New Issue
Block a user