Add AOV rendering support and related enhancements
Added support for rendering Arbitrary Output Variables (AOVs) for detailed outputs like beauty, albedo, normal, depth, and position. Added new functions `render_aov` and `accumulate_aov` for AOV data management during rendering. Added AOV rendering capabilities to the `SimpleLit` material with specific functions. Changed the material system to include new function pointers for AOV rendering. Changed the renderer to initialize and update AOV targets during the rendering process. Changed the main rendering loop to handle AOVs and update render targets accordingly. Fixed various minor issues, including function signature updates, variable name changes, and improved error handling for memory allocations.
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
path_output evaluate_bsdf_directional(directional_light_t light, const light_shading_context_t* context, vec3s throughput, uint32_t sample_index)
|
||||
{
|
||||
path_output output = {0.0f};
|
||||
output.state = TERMINATE;
|
||||
output.state = PS_TERMINATE;
|
||||
output.pdf = 1.0f;
|
||||
|
||||
if (light.intensity <= 0.0f)
|
||||
@@ -26,7 +26,7 @@ path_output evaluate_bsdf_directional(directional_light_t light, const light_sha
|
||||
return output;
|
||||
}
|
||||
|
||||
ray_t shadow_ray = ray_create(BIAS_RAY_ORIGION(context->hit_point, context->normal), wi);
|
||||
ray_t shadow_ray = ray_create(BIAS_RAY_ORIGION(context->position, context->normal), wi);
|
||||
|
||||
float closest = FLT_MAX;
|
||||
hit_result_t shadow_hit = {1};
|
||||
@@ -42,6 +42,6 @@ path_output evaluate_bsdf_directional(directional_light_t light, const light_sha
|
||||
|
||||
output.direct_lighting = glms_vec3_mul(light_radiance, light_contribute);
|
||||
output.wi = wi;
|
||||
output.state = NORMAL;
|
||||
output.state = PS_NORMAL;
|
||||
return output;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#include "Lighting/SkyLight.h"
|
||||
#include "Common.h"
|
||||
|
||||
// Constant Sky
|
||||
|
||||
sky_light_t sky_create_constant_sky(const constant_sky_data_t* data)
|
||||
{
|
||||
sky_light_t light = {
|
||||
@@ -23,7 +25,7 @@ path_output evaluate_bsdf_const_sky(const void* data, const light_shading_contex
|
||||
const constant_sky_data_t* sky_data = (const constant_sky_data_t*)data;
|
||||
|
||||
path_output output = {0.0f};
|
||||
output.state = TERMINATE;
|
||||
output.state = PS_TERMINATE;
|
||||
|
||||
if (sky_data->intensity <= 0.0f)
|
||||
{
|
||||
@@ -45,7 +47,7 @@ path_output evaluate_bsdf_const_sky(const void* data, const light_shading_contex
|
||||
|
||||
vec3s wi = random_uniform_cdf_direction(context->normal, sample_index, d1, d2);
|
||||
|
||||
ray_t shadow_ray = ray_create(BIAS_RAY_ORIGION(context->hit_point, context->normal), wi);
|
||||
ray_t shadow_ray = ray_create(BIAS_RAY_ORIGION(context->position, context->normal), wi);
|
||||
|
||||
float closest = FLT_MAX;
|
||||
hit_result_t shadow_hit = {1};
|
||||
@@ -59,7 +61,7 @@ path_output evaluate_bsdf_const_sky(const void* data, const light_shading_contex
|
||||
output.direct_lighting = glms_vec3_scale(glms_vec3_mul(sky_light, throughput), cos_theta / pdf);
|
||||
|
||||
output.wi = wi;
|
||||
output.state = NORMAL;
|
||||
output.state = PS_NORMAL;
|
||||
return output;
|
||||
}
|
||||
|
||||
@@ -84,6 +86,8 @@ static uint32_t lower_bound_float(const float* arr, uint32_t n, float target)
|
||||
return low; // This is the index where target would be inserted to maintain order
|
||||
}
|
||||
|
||||
// HDR Sky
|
||||
|
||||
sky_light_t sky_create_hdr_sky(const texture_collection_t* textures, texture_entity_t hdri_entity, float intensity)
|
||||
{
|
||||
sky_light_t light = {
|
||||
@@ -98,12 +102,6 @@ sky_light_t sky_create_hdr_sky(const texture_collection_t* textures, texture_ent
|
||||
return light;
|
||||
}
|
||||
|
||||
light.data = malloc(sizeof(hdr_sky_data_t));
|
||||
if (light.data == NULL)
|
||||
{
|
||||
return light;
|
||||
}
|
||||
|
||||
hdr_sky_data_t data = {
|
||||
.width = hdri->width,
|
||||
.height = hdri->height,
|
||||
@@ -256,6 +254,13 @@ sky_light_t sky_create_hdr_sky(const texture_collection_t* textures, texture_ent
|
||||
|
||||
free(intermediate_buffer);
|
||||
|
||||
light.data = malloc(sizeof(hdr_sky_data_t));
|
||||
if (light.data == NULL)
|
||||
{
|
||||
free(cache);
|
||||
return light;
|
||||
}
|
||||
|
||||
data.total_weight = lumSum;
|
||||
data.cdf_cache = cache;
|
||||
|
||||
@@ -283,7 +288,7 @@ path_output evaluate_bsdf_hdr_sky(const void* data, const light_shading_context_
|
||||
const hdr_sky_data_t* sky_data = (const hdr_sky_data_t*)data;
|
||||
|
||||
path_output output = {0.0f};
|
||||
output.state = TERMINATE;
|
||||
output.state = PS_TERMINATE;
|
||||
|
||||
if (sky_data->intensity <= 0.0f)
|
||||
{
|
||||
@@ -303,21 +308,7 @@ path_output evaluate_bsdf_hdr_sky(const void* data, const light_shading_context_
|
||||
// TODO: Should we also use sobol numbers for the sky sampling?
|
||||
uv_to_index((vec2s){random_float(), random_float()}, sky_data->width, sky_data->height, &j, &i);
|
||||
vec3s cdf = sky_data->cdf_cache[i * sky_data->width + j];
|
||||
|
||||
float theta = -cdf.y * PI;
|
||||
float phi = cdf.x * TWO_PI;
|
||||
|
||||
float sin_theta = sinf(theta);
|
||||
float cos_theta = cosf(theta);
|
||||
float sin_phi = sinf(phi);
|
||||
float cos_phi = cosf(phi);
|
||||
|
||||
vec3s wi = glms_vec3_normalize((vec3s)
|
||||
{
|
||||
sin_theta * cos_phi,
|
||||
cos_theta,
|
||||
sin_theta * sin_phi,
|
||||
});
|
||||
vec3s wi = equirectangular_to_direction(cdf.x,-cdf.y);
|
||||
|
||||
float n_dot_l = glms_vec3_dot(wi, context->normal);
|
||||
if (n_dot_l <= 0.0f)
|
||||
@@ -325,7 +316,7 @@ path_output evaluate_bsdf_hdr_sky(const void* data, const light_shading_context_
|
||||
return output;
|
||||
}
|
||||
|
||||
ray_t shadow_ray = ray_create(BIAS_RAY_ORIGION(context->hit_point, context->normal), wi);
|
||||
ray_t shadow_ray = ray_create(BIAS_RAY_ORIGION(context->position, context->normal), wi);
|
||||
|
||||
float closest = FLT_MAX;
|
||||
hit_result_t shadow_hit = {1};
|
||||
@@ -346,7 +337,7 @@ path_output evaluate_bsdf_hdr_sky(const void* data, const light_shading_context_
|
||||
|
||||
output.wi = wi;
|
||||
output.pdf = pdf;
|
||||
output.state = NORMAL;
|
||||
output.state = PS_NORMAL;
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user