Refactor the codebase and add aov support.
This commit is contained in:
@@ -32,6 +32,9 @@ bool renderer_aov_target_init(render_job_t* job, aov_flags_t aov_flags)
|
||||
create_target_if_required(aov_flags, AOV_DEPTH, &job->aov_target[AOV_DEPTH_INDEX], job->config->width, job->config->height);
|
||||
create_target_if_required(aov_flags, AOV_POSITION, &job->aov_target[AOV_POSITION_INDEX], job->config->width, job->config->height);
|
||||
|
||||
create_target_if_required(aov_flags, AOV_DIRECT, &job->aov_target[AOV_DIRECT_INDEX], job->config->width, job->config->height);
|
||||
create_target_if_required(aov_flags, AOV_INDIRECT, &job->aov_target[AOV_INDIRECT_INDEX], job->config->width, job->config->height);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -57,15 +60,9 @@ static inline vec2s compute_ndc(float x, float y, uint32_t width, uint32_t heigh
|
||||
};
|
||||
}
|
||||
|
||||
static inline uint16_t get_sample_count(uint16_t sample_count, aov_index_t index)
|
||||
static inline bool aov_needs_lighting_samples(aov_flags_t flags)
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
case AOV_BEAUTY_INDEX:
|
||||
return sample_count;
|
||||
default:
|
||||
return 1;
|
||||
}
|
||||
return has_flag(flags, AOV_BEAUTY) || has_flag(flags, AOV_DIRECT) || has_flag(flags, AOV_INDIRECT);
|
||||
}
|
||||
|
||||
static void render_pixel(const rendering_config_t* config, scene_t* scene, vec3s coord, uint32_t x, uint32_t y, aov_flags_t aov_flags, aov_output_t* pixel_output)
|
||||
@@ -73,7 +70,7 @@ static void render_pixel(const rendering_config_t* config, scene_t* scene, vec3s
|
||||
aov_output_t accumulated_color = {0};
|
||||
|
||||
uint32_t pixel_id = y * config->width + x;
|
||||
uint16_t sample_count = config->sample_count;
|
||||
uint16_t sample_count = aov_needs_lighting_samples(aov_flags) ? (uint16_t)config->sample_count : 1;
|
||||
float inv_sample = 1.0f / (float)sample_count;
|
||||
|
||||
vec3s camera_right = quat_get_right(scene->camera.rotation);
|
||||
@@ -82,7 +79,7 @@ static void render_pixel(const rendering_config_t* config, scene_t* scene, vec3s
|
||||
for (uint16_t k = 0; k < sample_count; k++)
|
||||
{
|
||||
// TODO: Hash it
|
||||
uint32_t sobol_idx = pixel_id * config->sample_count + (k + 1);
|
||||
uint32_t sobol_idx = pixel_id * (uint32_t)sample_count + (k + 1);
|
||||
|
||||
// Apply AA
|
||||
float du = sobol_sample(sobol_idx, PRNG_FILTER_U);
|
||||
@@ -105,15 +102,7 @@ static void render_pixel(const rendering_config_t* config, scene_t* scene, vec3s
|
||||
ray_t ray = ray_create(scene->camera.position, glms_vec3_normalize(glms_vec3_sub(image_plane_point, scene->camera.position)), 0.0f, spread_angle);
|
||||
|
||||
aov_output_t aov_output = {0};
|
||||
if (has_flag(aov_flags, AOV_BEAUTY))
|
||||
{
|
||||
aov_output.beauty = path_trace(scene, ray, sobol_idx, config->max_depth);
|
||||
}
|
||||
|
||||
if (aov_flags != AOV_BEAUTY)
|
||||
{
|
||||
render_aov(scene, ray, sobol_idx, config->max_depth, &aov_output);
|
||||
}
|
||||
path_trace_aov(scene, ray, sobol_idx, config->max_depth, aov_flags, &aov_output);
|
||||
|
||||
accumulate_aov(&accumulated_color, &aov_output, inv_sample);
|
||||
}
|
||||
@@ -138,6 +127,9 @@ static inline void update_aov(render_target_t** target, const aov_output_t* aov,
|
||||
update_aov_pixel_if_exist(&target[AOV_NORMAL_INDEX], aov->normal, x, y);
|
||||
update_aov_pixel_if_exist(&target[AOV_DEPTH_INDEX], (vec4s){aov->depth, aov->depth, aov->depth, 1.0f}, x, y);
|
||||
update_aov_pixel_if_exist(&target[AOV_POSITION_INDEX], aov->position, x, y);
|
||||
|
||||
update_aov_pixel_if_exist(&target[AOV_DIRECT_INDEX], aov->direct, x, y);
|
||||
update_aov_pixel_if_exist(&target[AOV_INDIRECT_INDEX], aov->indirect, x, y);
|
||||
}
|
||||
|
||||
// TODO: Progressive rendering
|
||||
|
||||
@@ -419,7 +419,7 @@ float texture_get_sample_lod(const texture_t* texture, const texture_sample_cont
|
||||
// 4. Convert to LOD
|
||||
// LOD 0 = 1 texel. LOD 1 = 2 texels. LOD 2 = 4 texels.
|
||||
// log2(texels_covered) gives the mip level.
|
||||
return log2f(texels_covered);
|
||||
return log2f(texels_covered) * 0.5f;
|
||||
}
|
||||
|
||||
static vec4s nearest_filter(const texture_t* texture, vec2s uv, uint8_t lod)
|
||||
|
||||
Reference in New Issue
Block a user