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:
@@ -1,3 +1,4 @@
|
||||
#include <time.h>
|
||||
#include <omp.h>
|
||||
#include <stdint.h>
|
||||
#include <svpng.inc>
|
||||
@@ -7,6 +8,7 @@
|
||||
#include "Geometry/Mesh.h"
|
||||
#include "Lighting/SkyLight.h"
|
||||
#include "Material/SimpleLit.h"
|
||||
#include "Rendering/AOV.h"
|
||||
#include "Rendering/PostProcessing.h"
|
||||
#include "Rendering/Scene.h"
|
||||
#include "Window.h"
|
||||
@@ -23,7 +25,7 @@ static bool scene_setup(scene_t* scene)
|
||||
}
|
||||
|
||||
scene->camera.position = (vec3s){7.5f, 2.0f, 0.0f};
|
||||
scene->camera.rotation = euler_to_quat(10.0f, 90.0f, 0.0f);
|
||||
scene->camera.rotation = euler_to_quat(-10.0f, 90.0f, 0.0f);
|
||||
|
||||
// TODO: Standardize light unit
|
||||
light_entity_t sun = light_create_directional_light(&scene->lights);
|
||||
@@ -41,32 +43,32 @@ static bool scene_setup(scene_t* scene)
|
||||
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;
|
||||
return scene->lights.sky_light.data != NULL;
|
||||
}
|
||||
|
||||
static bool load_assets(scene_t* scene)
|
||||
{
|
||||
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);
|
||||
//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(),
|
||||
// .normal_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);
|
||||
}
|
||||
|
||||
static bool initialize_renderer(const rendering_config_t* config, render_job_t** outJob, render_target_t* outImg, scene_t* outScene)
|
||||
static bool initialize_renderer(const rendering_config_t* config, render_job_t** outJob, scene_t* outScene)
|
||||
{
|
||||
if (!scene_setup(outScene)
|
||||
|| !load_assets(outScene)
|
||||
|| !render_target_init(config->width, config->height, outImg))
|
||||
|| !load_assets(outScene))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -79,29 +81,31 @@ static bool initialize_renderer(const rendering_config_t* config, render_job_t**
|
||||
|
||||
*job = (render_job_t){
|
||||
.scene = outScene,
|
||||
.render_target = outImg,
|
||||
.config = config,
|
||||
|
||||
.rendering_type = TILE_BASED,
|
||||
.debug_flag = DEBUG_NONE,
|
||||
.rendering_mode = RENDER_TILE_BASED,
|
||||
.aov_flags = AOV_BEAUTY,
|
||||
.is_done = false,
|
||||
};
|
||||
|
||||
if (!renderer_aov_target_init(job, job->aov_flags))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
sobol_init();
|
||||
srand((unsigned int)time(NULL));
|
||||
|
||||
*outJob = job;
|
||||
return true;
|
||||
}
|
||||
|
||||
static void shutdown_renderer(render_job_t* job, render_target_t* img, scene_t* scene)
|
||||
static void shutdown_renderer(render_job_t* job, scene_t* scene)
|
||||
{
|
||||
if (job != NULL)
|
||||
{
|
||||
free(job);
|
||||
}
|
||||
|
||||
render_target_free(img);
|
||||
render_job_free(job);
|
||||
scene_free(scene);
|
||||
|
||||
free(job);
|
||||
}
|
||||
|
||||
static void update_pixel_buffer(render_target_t* render_target)
|
||||
@@ -125,10 +129,11 @@ static void update_pixel_buffer(render_target_t* render_target)
|
||||
window_refresh_region(0, 0, render_target->width, render_target->height);
|
||||
}
|
||||
|
||||
static int run_main_loop(render_job_t* job, render_target_t* img)
|
||||
static int run_main_loop(render_job_t* job, uint8_t aov_index)
|
||||
{
|
||||
MSG msg;
|
||||
bool running = true;
|
||||
render_target_t* render_target = job->aov_target[aov_index];
|
||||
|
||||
while (running)
|
||||
{
|
||||
@@ -150,7 +155,7 @@ static int run_main_loop(render_job_t* job, render_target_t* img)
|
||||
|
||||
if (!job->is_done && running)
|
||||
{
|
||||
update_pixel_buffer(img);
|
||||
update_pixel_buffer(render_target);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,28 +168,27 @@ int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance,
|
||||
omp_set_num_threads(16);
|
||||
|
||||
scene_t scene = {0};
|
||||
render_target_t img = {0};
|
||||
render_job_t* job = NULL;
|
||||
|
||||
rendering_config_t config = {
|
||||
.width = 1920 / 1,
|
||||
.height = 1080 / 1,
|
||||
.sample_count = 16 * 4,
|
||||
.width = 1920 / 2,
|
||||
.height = 1080 / 2,
|
||||
.sample_count = 16 * 1,
|
||||
.max_depth = 4,
|
||||
.bucket_size = 64,
|
||||
};
|
||||
|
||||
if (!initialize_renderer(&config, &job, &img, &scene)
|
||||
if (!initialize_renderer(&config, &job, &scene)
|
||||
|| !window_create(TITLE, hInstance, config.width, config.height, job))
|
||||
{
|
||||
shutdown_renderer(job, &img, &scene);
|
||||
shutdown_renderer(job, &scene);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int result = run_main_loop(job, &img);
|
||||
int result = run_main_loop(job, AOV_BEAUTY_INDEX);
|
||||
|
||||
window_close();
|
||||
shutdown_renderer(job, &img, &scene);
|
||||
shutdown_renderer(job, &scene);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user