From 4e2c6aed63d8ba39da7fef8004f2417836a9ea6e Mon Sep 17 00:00:00 2001 From: Fabio Pellacini Date: Wed, 9 Sep 2020 10:13:23 +0200 Subject: [PATCH 01/11] updayed --- apps/ysceneitrace/ysceneitrace.cpp | 30 ++++++++++++++++------------ apps/ysceneitraces/ysceneitraces.cpp | 13 +++++++----- apps/yscenetrace/yscenetrace.cpp | 13 +++++++----- libs/yocto/yocto_trace.h | 6 ------ 4 files changed, 33 insertions(+), 29 deletions(-) diff --git a/apps/ysceneitrace/ysceneitrace.cpp b/apps/ysceneitrace/ysceneitrace.cpp index 814a7e962..bd9c81083 100644 --- a/apps/ysceneitrace/ysceneitrace.cpp +++ b/apps/ysceneitrace/ysceneitrace.cpp @@ -137,11 +137,14 @@ void init_scene(trace_scene* scene, sceneio_scene* ioscene, for (auto iocamera : ioscene->cameras) { if (progress_cb) progress_cb("converting cameras", progress.x++, progress.y); - auto camera = add_camera(scene); - set_frame(camera, iocamera->frame); - set_lens(camera, iocamera->lens, iocamera->aspect, iocamera->film, - iocamera->orthographic); - set_focus(camera, iocamera->aperture, iocamera->focus); + auto camera = add_camera(scene); + camera->frame = iocamera->frame; + camera->lens = iocamera->lens; + camera->aspect = iocamera->aspect; + camera->film = iocamera->film; + camera->orthographic = iocamera->orthographic; + camera->aperture = iocamera->aperture; + camera->focus = iocamera->focus; camera_map[iocamera] = camera; } @@ -573,10 +576,13 @@ void draw_widgets(gui_window* win, app_states* apps, const gui_input& input) { auto iocamera = app->selected_camera; auto camera = get_element( iocamera, app->ioscene->cameras, app->scene->cameras); - set_frame(camera, iocamera->frame); - set_lens(camera, iocamera->lens, iocamera->aspect, iocamera->film, - iocamera->orthographic); - set_focus(camera, iocamera->aperture, iocamera->focus); + camera->frame = iocamera->frame; + camera->lens = iocamera->lens; + camera->aspect = iocamera->aspect; + camera->film = iocamera->film; + camera->orthographic = iocamera->orthographic; + camera->aperture = iocamera->aperture; + camera->focus = iocamera->focus; reset_display(app); } end_header(win); @@ -803,10 +809,8 @@ int main(int argc, const char* argv[]) { stop_display(app); std::tie(app->iocamera->frame, app->iocamera->focus) = camera_turntable( app->iocamera->frame, app->iocamera->focus, rotate, dolly, pan); - set_frame(app->camera, app->iocamera->frame); - set_lens(app->camera, app->iocamera->lens, app->iocamera->aspect, - app->iocamera->film, app->iocamera->orthographic); - set_focus(app->camera, app->iocamera->aperture, app->iocamera->focus); + app->camera->frame = app->iocamera->frame; + app->camera->focus = app->iocamera->focus; reset_display(app); } diff --git a/apps/ysceneitraces/ysceneitraces.cpp b/apps/ysceneitraces/ysceneitraces.cpp index 7b6c22816..afbaa6ab7 100644 --- a/apps/ysceneitraces/ysceneitraces.cpp +++ b/apps/ysceneitraces/ysceneitraces.cpp @@ -125,11 +125,14 @@ void init_scene(trace_scene* scene, sceneio_scene* ioscene, for (auto iocamera : ioscene->cameras) { if (progress_cb) progress_cb("converting cameras", progress.x++, progress.y); - auto camera = add_camera(scene); - set_frame(camera, iocamera->frame); - set_lens(camera, iocamera->lens, iocamera->aspect, iocamera->film, - iocamera->orthographic); - set_focus(camera, iocamera->aperture, iocamera->focus); + auto camera = add_camera(scene); + camera->frame = iocamera->frame; + camera->lens = iocamera->lens; + camera->aspect = iocamera->aspect; + camera->film = iocamera->film; + camera->orthographic = iocamera->orthographic; + camera->aperture = iocamera->aperture; + camera->focus = iocamera->focus; camera_map[iocamera] = camera; } diff --git a/apps/yscenetrace/yscenetrace.cpp b/apps/yscenetrace/yscenetrace.cpp index 75542b1b3..9e4804f02 100644 --- a/apps/yscenetrace/yscenetrace.cpp +++ b/apps/yscenetrace/yscenetrace.cpp @@ -53,11 +53,14 @@ void init_scene(trace_scene* scene, sceneio_scene* ioscene, for (auto iocamera : ioscene->cameras) { if (progress_cb) progress_cb("converting cameras", progress.x++, progress.y); - auto camera = add_camera(scene); - set_frame(camera, iocamera->frame); - set_lens(camera, iocamera->lens, iocamera->aspect, iocamera->film, - iocamera->orthographic); - set_focus(camera, iocamera->aperture, iocamera->focus); + auto camera = add_camera(scene); + camera->frame = iocamera->frame; + camera->lens = iocamera->lens; + camera->aspect = iocamera->aspect; + camera->film = iocamera->film; + camera->orthographic = iocamera->orthographic; + camera->aperture = iocamera->aperture; + camera->focus = iocamera->focus; camera_map[iocamera] = camera; } diff --git a/libs/yocto/yocto_trace.h b/libs/yocto/yocto_trace.h index a89b5f18b..f836da448 100644 --- a/libs/yocto/yocto_trace.h +++ b/libs/yocto/yocto_trace.h @@ -226,12 +226,6 @@ trace_shape* add_shape(trace_scene* scene); trace_texture* add_texture(trace_scene* scene); trace_instance* add_complete_instance(trace_scene* scene); -// set camera properties -void set_frame(trace_camera* camera, const frame3f& frame); -void set_lens(trace_camera* camera, float lens, float aspect, float film, - bool ortho = false); -void set_focus(trace_camera* camera, float aperture, float focus); - // set instance properties void set_frame(trace_instance* instance, const frame3f& frame); void set_material(trace_instance* instance, trace_material* material); From 1430407c736eb06eaf9f822eacbd778c958c694f Mon Sep 17 00:00:00 2001 From: Fabio Pellacini Date: Wed, 9 Sep 2020 10:16:01 +0200 Subject: [PATCH 02/11] updated --- apps/ysceneitrace/ysceneitrace.cpp | 19 +++++++++---------- apps/ysceneitraces/ysceneitraces.cpp | 8 ++++---- apps/yscenetrace/yscenetrace.cpp | 8 ++++---- libs/yocto/yocto_trace.h | 5 ----- 4 files changed, 17 insertions(+), 23 deletions(-) diff --git a/apps/ysceneitrace/ysceneitrace.cpp b/apps/ysceneitrace/ysceneitrace.cpp index bd9c81083..99abe445f 100644 --- a/apps/ysceneitrace/ysceneitrace.cpp +++ b/apps/ysceneitrace/ysceneitrace.cpp @@ -217,10 +217,10 @@ void init_scene(trace_scene* scene, sceneio_scene* ioscene, for (auto ioinstance : ioscene->instances) { if (progress_cb) progress_cb("converting instances", progress.x++, progress.y); - auto instance = add_instance(scene); - set_frame(instance, ioinstance->frame); - set_shape(instance, shape_map.at(ioinstance->shape)); - set_material(instance, material_map.at(ioinstance->material)); + auto instance = add_instance(scene); + instance->frame = ioinstance->frame; + instance->shape = shape_map.at(ioinstance->shape); + instance->material = material_map.at(ioinstance->material); } for (auto ioenvironment : ioscene->environments) { @@ -612,12 +612,11 @@ void draw_widgets(gui_window* win, app_states* apps, const gui_input& input) { auto ioinstance = app->selected_instance; auto instance = get_element( ioinstance, app->ioscene->instances, app->scene->instances); - set_frame(instance, ioinstance->frame); - set_shape(instance, get_element(ioinstance->shape, app->ioscene->shapes, - app->scene->shapes)); - set_material( - instance, get_element(ioinstance->material, app->ioscene->materials, - app->scene->materials)); + instance->frame = ioinstance->frame; + instance->shape = get_element( + ioinstance->shape, app->ioscene->shapes, app->scene->shapes); + instance->material = get_element( + ioinstance->material, app->ioscene->materials, app->scene->materials); update_bvh(app->bvh, app->scene, {instance}, {}, app->params); reset_display(app); } diff --git a/apps/ysceneitraces/ysceneitraces.cpp b/apps/ysceneitraces/ysceneitraces.cpp index afbaa6ab7..bf20144e7 100644 --- a/apps/ysceneitraces/ysceneitraces.cpp +++ b/apps/ysceneitraces/ysceneitraces.cpp @@ -205,10 +205,10 @@ void init_scene(trace_scene* scene, sceneio_scene* ioscene, for (auto ioinstance : ioscene->instances) { if (progress_cb) progress_cb("converting instances", progress.x++, progress.y); - auto instance = add_instance(scene); - set_frame(instance, ioinstance->frame); - set_shape(instance, shape_map.at(ioinstance->shape)); - set_material(instance, material_map.at(ioinstance->material)); + auto instance = add_instance(scene); + instance->frame = ioinstance->frame; + instance->shape = shape_map.at(ioinstance->shape); + instance->material = material_map.at(ioinstance->material); } for (auto ioenvironment : ioscene->environments) { diff --git a/apps/yscenetrace/yscenetrace.cpp b/apps/yscenetrace/yscenetrace.cpp index 9e4804f02..e71694b16 100644 --- a/apps/yscenetrace/yscenetrace.cpp +++ b/apps/yscenetrace/yscenetrace.cpp @@ -133,10 +133,10 @@ void init_scene(trace_scene* scene, sceneio_scene* ioscene, for (auto ioinstance : ioscene->instances) { if (progress_cb) progress_cb("converting instances", progress.x++, progress.y); - auto instance = add_instance(scene); - set_frame(instance, ioinstance->frame); - set_shape(instance, shape_map.at(ioinstance->shape)); - set_material(instance, material_map.at(ioinstance->material)); + auto instance = add_instance(scene); + instance->frame = ioinstance->frame; + instance->shape = shape_map.at(ioinstance->shape); + instance->material = material_map.at(ioinstance->material); } for (auto ioenvironment : ioscene->environments) { diff --git a/libs/yocto/yocto_trace.h b/libs/yocto/yocto_trace.h index f836da448..7a1c42bba 100644 --- a/libs/yocto/yocto_trace.h +++ b/libs/yocto/yocto_trace.h @@ -226,11 +226,6 @@ trace_shape* add_shape(trace_scene* scene); trace_texture* add_texture(trace_scene* scene); trace_instance* add_complete_instance(trace_scene* scene); -// set instance properties -void set_frame(trace_instance* instance, const frame3f& frame); -void set_material(trace_instance* instance, trace_material* material); -void set_shape(trace_instance* instance, trace_shape* shape); - // set texture properties void set_texture(trace_texture* texture, const image& img); void set_texture(trace_texture* texture, const image& img); From dca8dcd87a137d187d65fa057185dc274a2f7369 Mon Sep 17 00:00:00 2001 From: Fabio Pellacini Date: Wed, 9 Sep 2020 10:17:47 +0200 Subject: [PATCH 03/11] updated --- apps/ysceneitrace/ysceneitrace.cpp | 16 +++++----------- apps/ysceneitraces/ysceneitraces.cpp | 9 +++------ apps/yscenetrace/yscenetrace.cpp | 9 +++------ libs/yocto/yocto_trace.h | 4 ---- 4 files changed, 11 insertions(+), 27 deletions(-) diff --git a/apps/ysceneitrace/ysceneitrace.cpp b/apps/ysceneitrace/ysceneitrace.cpp index 99abe445f..3ef64e6fa 100644 --- a/apps/ysceneitrace/ysceneitrace.cpp +++ b/apps/ysceneitrace/ysceneitrace.cpp @@ -153,12 +153,9 @@ void init_scene(trace_scene* scene, sceneio_scene* ioscene, for (auto iotexture : ioscene->textures) { if (progress_cb) progress_cb("converting textures", progress.x++, progress.y); - auto texture = add_texture(scene); - if (!iotexture->hdr.empty()) { - set_texture(texture, iotexture->hdr); - } else if (!iotexture->ldr.empty()) { - set_texture(texture, iotexture->ldr); - } + auto texture = add_texture(scene); + texture->hdr = iotexture->hdr; + texture->ldr = iotexture->ldr; texture_map[iotexture] = texture; } @@ -687,11 +684,8 @@ void draw_widgets(gui_window* win, app_states* apps, const gui_input& input) { auto iotexture = app->selected_texture; auto texture = get_element( iotexture, app->ioscene->textures, app->scene->textures); - if (!iotexture->hdr.empty()) { - set_texture(texture, iotexture->hdr); - } else if (!iotexture->ldr.empty()) { - set_texture(texture, iotexture->ldr); - } + texture->hdr = iotexture->hdr; + texture->ldr = iotexture->ldr; reset_display(app); } end_header(win); diff --git a/apps/ysceneitraces/ysceneitraces.cpp b/apps/ysceneitraces/ysceneitraces.cpp index bf20144e7..bb75e354b 100644 --- a/apps/ysceneitraces/ysceneitraces.cpp +++ b/apps/ysceneitraces/ysceneitraces.cpp @@ -141,12 +141,9 @@ void init_scene(trace_scene* scene, sceneio_scene* ioscene, for (auto iotexture : ioscene->textures) { if (progress_cb) progress_cb("converting textures", progress.x++, progress.y); - auto texture = add_texture(scene); - if (!iotexture->hdr.empty()) { - set_texture(texture, iotexture->hdr); - } else if (!iotexture->ldr.empty()) { - set_texture(texture, iotexture->ldr); - } + auto texture = add_texture(scene); + texture->hdr = iotexture->hdr; + texture->ldr = iotexture->ldr; texture_map[iotexture] = texture; } diff --git a/apps/yscenetrace/yscenetrace.cpp b/apps/yscenetrace/yscenetrace.cpp index e71694b16..189c79477 100644 --- a/apps/yscenetrace/yscenetrace.cpp +++ b/apps/yscenetrace/yscenetrace.cpp @@ -69,12 +69,9 @@ void init_scene(trace_scene* scene, sceneio_scene* ioscene, for (auto iotexture : ioscene->textures) { if (progress_cb) progress_cb("converting textures", progress.x++, progress.y); - auto texture = add_texture(scene); - if (!iotexture->hdr.empty()) { - set_texture(texture, iotexture->hdr); - } else if (!iotexture->ldr.empty()) { - set_texture(texture, iotexture->ldr); - } + auto texture = add_texture(scene); + texture->hdr = iotexture->hdr; + texture->ldr = iotexture->ldr; texture_map[iotexture] = texture; } diff --git a/libs/yocto/yocto_trace.h b/libs/yocto/yocto_trace.h index 7a1c42bba..9a1f7780f 100644 --- a/libs/yocto/yocto_trace.h +++ b/libs/yocto/yocto_trace.h @@ -226,10 +226,6 @@ trace_shape* add_shape(trace_scene* scene); trace_texture* add_texture(trace_scene* scene); trace_instance* add_complete_instance(trace_scene* scene); -// set texture properties -void set_texture(trace_texture* texture, const image& img); -void set_texture(trace_texture* texture, const image& img); - // set material properties void set_emission(trace_material* material, const vec3f& emission, trace_texture* emission_tex = nullptr); From fe02a9381b28b840bab60ccff7ff8de4aa3d11cc Mon Sep 17 00:00:00 2001 From: Fabio Pellacini Date: Wed, 9 Sep 2020 10:22:26 +0200 Subject: [PATCH 04/11] updated --- apps/ysceneitrace/ysceneitrace.cpp | 14 +++++++------- apps/ysceneitraces/ysceneitraces.cpp | 8 ++++---- apps/yscenetrace/yscenetrace.cpp | 8 ++++---- libs/yocto/yocto_trace.h | 5 ----- 4 files changed, 15 insertions(+), 20 deletions(-) diff --git a/apps/ysceneitrace/ysceneitrace.cpp b/apps/ysceneitrace/ysceneitrace.cpp index 3ef64e6fa..ce0f66b51 100644 --- a/apps/ysceneitrace/ysceneitrace.cpp +++ b/apps/ysceneitrace/ysceneitrace.cpp @@ -223,10 +223,10 @@ void init_scene(trace_scene* scene, sceneio_scene* ioscene, for (auto ioenvironment : ioscene->environments) { if (progress_cb) progress_cb("converting environments", progress.x++, progress.y); - auto environment = add_environment(scene); - set_frame(environment, ioenvironment->frame); - set_emission(environment, ioenvironment->emission, - texture_map.at(ioenvironment->emission_tex)); + auto environment = add_environment(scene); + environment->frame = ioenvironment->frame; + environment->emission = ioenvironment->emission; + environment->emission_tex = texture_map.at(ioenvironment->emission_tex); } // done @@ -593,9 +593,9 @@ void draw_widgets(gui_window* win, app_states* apps, const gui_input& input) { auto ioenvironment = app->selected_environment; auto environment = get_element( ioenvironment, app->ioscene->environments, app->scene->environments); - set_frame(environment, ioenvironment->frame); - set_emission(environment, ioenvironment->emission, - get_texture(ioenvironment->emission_tex)); + environment->frame = ioenvironment->frame; + environment->emission = ioenvironment->emission; + environment->emission_tex = get_texture(ioenvironment->emission_tex); init_lights(app->lights, app->scene, app->params); reset_display(app); } diff --git a/apps/ysceneitraces/ysceneitraces.cpp b/apps/ysceneitraces/ysceneitraces.cpp index bb75e354b..01c4b424e 100644 --- a/apps/ysceneitraces/ysceneitraces.cpp +++ b/apps/ysceneitraces/ysceneitraces.cpp @@ -211,10 +211,10 @@ void init_scene(trace_scene* scene, sceneio_scene* ioscene, for (auto ioenvironment : ioscene->environments) { if (progress_cb) progress_cb("converting environments", progress.x++, progress.y); - auto environment = add_environment(scene); - set_frame(environment, ioenvironment->frame); - set_emission(environment, ioenvironment->emission, - texture_map.at(ioenvironment->emission_tex)); + auto environment = add_environment(scene); + environment->frame = ioenvironment->frame; + environment->emission = ioenvironment->emission; + environment->emission_tex = texture_map.at(ioenvironment->emission_tex); } // done diff --git a/apps/yscenetrace/yscenetrace.cpp b/apps/yscenetrace/yscenetrace.cpp index 189c79477..5482f93b8 100644 --- a/apps/yscenetrace/yscenetrace.cpp +++ b/apps/yscenetrace/yscenetrace.cpp @@ -139,10 +139,10 @@ void init_scene(trace_scene* scene, sceneio_scene* ioscene, for (auto ioenvironment : ioscene->environments) { if (progress_cb) progress_cb("converting environments", progress.x++, progress.y); - auto environment = add_environment(scene); - set_frame(environment, ioenvironment->frame); - set_emission(environment, ioenvironment->emission, - texture_map.at(ioenvironment->emission_tex)); + auto environment = add_environment(scene); + environment->frame = ioenvironment->frame; + environment->emission = ioenvironment->emission; + environment->emission_tex = texture_map.at(ioenvironment->emission_tex); } // done diff --git a/libs/yocto/yocto_trace.h b/libs/yocto/yocto_trace.h index 9a1f7780f..7c0e4c9e6 100644 --- a/libs/yocto/yocto_trace.h +++ b/libs/yocto/yocto_trace.h @@ -267,11 +267,6 @@ void set_subdivision(trace_shape* shape, int subdivisions, bool catmullclark, void set_displacement( trace_shape* shape, float displacement, trace_texture* displacement_tex); -// set environment properties -void set_frame(trace_environment* environment, const frame3f& frame); -void set_emission(trace_environment* environment, const vec3f& emission, - trace_texture* emission_tex = nullptr); - } // namespace yocto // ----------------------------------------------------------------------------- From 8be249ffc5b688d2b6ee9f156f723190569c2ca4 Mon Sep 17 00:00:00 2001 From: Fabio Pellacini Date: Wed, 9 Sep 2020 10:30:36 +0200 Subject: [PATCH 05/11] updated --- apps/ysceneitrace/ysceneitrace.cpp | 56 +++++++++++++++------------- apps/ysceneitraces/ysceneitraces.cpp | 36 ++++++++++-------- apps/yscenetrace/yscenetrace.cpp | 36 ++++++++++-------- libs/yocto/yocto_trace.h | 18 --------- 4 files changed, 70 insertions(+), 76 deletions(-) diff --git a/apps/ysceneitrace/ysceneitrace.cpp b/apps/ysceneitrace/ysceneitrace.cpp index ce0f66b51..9292f2019 100644 --- a/apps/ysceneitrace/ysceneitrace.cpp +++ b/apps/ysceneitrace/ysceneitrace.cpp @@ -193,22 +193,26 @@ void init_scene(trace_scene* scene, sceneio_scene* ioscene, shape_map[nullptr] = nullptr; for (auto ioshape : ioscene->shapes) { if (progress_cb) progress_cb("converting shapes", progress.x++, progress.y); - auto shape = add_shape(scene); - set_points(shape, ioshape->points); - set_lines(shape, ioshape->lines); - set_triangles(shape, ioshape->triangles); - set_quads(shape, ioshape->quads); - set_fvquads( - shape, ioshape->quadspos, ioshape->quadsnorm, ioshape->quadstexcoord); - set_positions(shape, ioshape->positions); - set_normals(shape, ioshape->normals); - set_texcoords(shape, ioshape->texcoords); - set_colors(shape, ioshape->colors); - set_radius(shape, ioshape->radius); - set_tangents(shape, ioshape->tangents); - set_subdivision( - shape, ioshape->subdivisions, ioshape->catmullclark, ioshape->smooth); - shape_map[ioshape] = shape; + auto shape = add_shape(scene); + shape->points = ioshape->points; + shape->lines = ioshape->lines; + shape->triangles = ioshape->triangles; + shape->quads = ioshape->quads; + shape->quadspos = ioshape->quadspos; + shape->quadsnorm = ioshape->quadsnorm; + shape->quadstexcoord = ioshape->quadstexcoord; + shape->positions = ioshape->positions; + shape->normals = ioshape->normals; + shape->texcoords = ioshape->texcoords; + shape->colors = ioshape->colors; + shape->radius = ioshape->radius; + shape->tangents = ioshape->tangents; + shape->subdivisions = ioshape->subdivisions; + shape->catmullclark = ioshape->catmullclark; + shape->smooth = ioshape->smooth; + shape->displacement = ioshape->displacement; + shape->displacement_tex = texture_map.at(ioshape->displacement_tex); + shape_map[ioshape] = shape; } for (auto ioinstance : ioscene->instances) { @@ -627,16 +631,16 @@ void draw_widgets(gui_window* win, app_states* apps, const gui_input& input) { auto ioshape = app->selected_shape; auto shape = get_element( ioshape, app->ioscene->shapes, app->scene->shapes); - set_points(shape, ioshape->points); - set_lines(shape, ioshape->lines); - set_triangles(shape, ioshape->triangles); - set_quads(shape, ioshape->quads); - set_positions(shape, ioshape->positions); - set_normals(shape, ioshape->normals); - set_texcoords(shape, ioshape->texcoords); - set_colors(shape, ioshape->colors); - set_radius(shape, ioshape->radius); - set_tangents(shape, ioshape->tangents); + shape->points = ioshape->points; + shape->lines = ioshape->lines; + shape->triangles = ioshape->triangles; + shape->quads = ioshape->quads; + shape->positions = ioshape->positions; + shape->normals = ioshape->normals; + shape->texcoords = ioshape->texcoords; + shape->colors = ioshape->colors; + shape->radius = ioshape->radius; + shape->tangents = ioshape->tangents; update_bvh(app->bvh, app->scene, {}, {shape}, app->params); reset_display(app); } diff --git a/apps/ysceneitraces/ysceneitraces.cpp b/apps/ysceneitraces/ysceneitraces.cpp index 01c4b424e..328f13493 100644 --- a/apps/ysceneitraces/ysceneitraces.cpp +++ b/apps/ysceneitraces/ysceneitraces.cpp @@ -181,22 +181,26 @@ void init_scene(trace_scene* scene, sceneio_scene* ioscene, shape_map[nullptr] = nullptr; for (auto ioshape : ioscene->shapes) { if (progress_cb) progress_cb("converting shapes", progress.x++, progress.y); - auto shape = add_shape(scene); - set_points(shape, ioshape->points); - set_lines(shape, ioshape->lines); - set_triangles(shape, ioshape->triangles); - set_quads(shape, ioshape->quads); - set_fvquads( - shape, ioshape->quadspos, ioshape->quadsnorm, ioshape->quadstexcoord); - set_positions(shape, ioshape->positions); - set_normals(shape, ioshape->normals); - set_texcoords(shape, ioshape->texcoords); - set_colors(shape, ioshape->colors); - set_radius(shape, ioshape->radius); - set_tangents(shape, ioshape->tangents); - set_subdivision( - shape, ioshape->subdivisions, ioshape->catmullclark, ioshape->smooth); - shape_map[ioshape] = shape; + auto shape = add_shape(scene); + shape->points = ioshape->points; + shape->lines = ioshape->lines; + shape->triangles = ioshape->triangles; + shape->quads = ioshape->quads; + shape->quadspos = ioshape->quadspos; + shape->quadsnorm = ioshape->quadsnorm; + shape->quadstexcoord = ioshape->quadstexcoord; + shape->positions = ioshape->positions; + shape->normals = ioshape->normals; + shape->texcoords = ioshape->texcoords; + shape->colors = ioshape->colors; + shape->radius = ioshape->radius; + shape->tangents = ioshape->tangents; + shape->subdivisions = ioshape->subdivisions; + shape->catmullclark = ioshape->catmullclark; + shape->smooth = ioshape->smooth; + shape->displacement = ioshape->displacement; + shape->displacement_tex = texture_map.at(ioshape->displacement_tex); + shape_map[ioshape] = shape; } for (auto ioinstance : ioscene->instances) { diff --git a/apps/yscenetrace/yscenetrace.cpp b/apps/yscenetrace/yscenetrace.cpp index 5482f93b8..f485cfd75 100644 --- a/apps/yscenetrace/yscenetrace.cpp +++ b/apps/yscenetrace/yscenetrace.cpp @@ -109,22 +109,26 @@ void init_scene(trace_scene* scene, sceneio_scene* ioscene, shape_map[nullptr] = nullptr; for (auto ioshape : ioscene->shapes) { if (progress_cb) progress_cb("converting shapes", progress.x++, progress.y); - auto shape = add_shape(scene); - set_points(shape, ioshape->points); - set_lines(shape, ioshape->lines); - set_triangles(shape, ioshape->triangles); - set_quads(shape, ioshape->quads); - set_fvquads( - shape, ioshape->quadspos, ioshape->quadsnorm, ioshape->quadstexcoord); - set_positions(shape, ioshape->positions); - set_normals(shape, ioshape->normals); - set_texcoords(shape, ioshape->texcoords); - set_colors(shape, ioshape->colors); - set_radius(shape, ioshape->radius); - set_tangents(shape, ioshape->tangents); - set_subdivision( - shape, ioshape->subdivisions, ioshape->catmullclark, ioshape->smooth); - shape_map[ioshape] = shape; + auto shape = add_shape(scene); + shape->points = ioshape->points; + shape->lines = ioshape->lines; + shape->triangles = ioshape->triangles; + shape->quads = ioshape->quads; + shape->quadspos = ioshape->quadspos; + shape->quadsnorm = ioshape->quadsnorm; + shape->quadstexcoord = ioshape->quadstexcoord; + shape->positions = ioshape->positions; + shape->normals = ioshape->normals; + shape->texcoords = ioshape->texcoords; + shape->colors = ioshape->colors; + shape->radius = ioshape->radius; + shape->tangents = ioshape->tangents; + shape->subdivisions = ioshape->subdivisions; + shape->catmullclark = ioshape->catmullclark; + shape->smooth = ioshape->smooth; + shape->displacement = ioshape->displacement; + shape->displacement_tex = texture_map.at(ioshape->displacement_tex); + shape_map[ioshape] = shape; } for (auto ioinstance : ioscene->instances) { diff --git a/libs/yocto/yocto_trace.h b/libs/yocto/yocto_trace.h index 7c0e4c9e6..1505e3e09 100644 --- a/libs/yocto/yocto_trace.h +++ b/libs/yocto/yocto_trace.h @@ -249,24 +249,6 @@ void set_scattering(trace_material* material, const vec3f& scattering, float scanisotropy, trace_texture* scattering_tex = nullptr); void set_normalmap(trace_material* material, trace_texture* normal_tex); -// set shape properties -void set_points(trace_shape* shape, const vector& points); -void set_lines(trace_shape* shape, const vector& lines); -void set_triangles(trace_shape* shape, const vector& triangles); -void set_quads(trace_shape* shape, const vector& quads); -void set_fvquads(trace_shape* shape, const vector& quadspos, - const vector& quadsnorm, const vector& quadstexcoord); -void set_positions(trace_shape* shape, const vector& positions); -void set_normals(trace_shape* shape, const vector& normals); -void set_texcoords(trace_shape* shape, const vector& texcoords); -void set_colors(trace_shape* shape, const vector& colors); -void set_radius(trace_shape* shape, const vector& radius); -void set_tangents(trace_shape* shape, const vector& tangents); -void set_subdivision(trace_shape* shape, int subdivisions, bool catmullclark, - bool smooth = true); -void set_displacement( - trace_shape* shape, float displacement, trace_texture* displacement_tex); - } // namespace yocto // ----------------------------------------------------------------------------- From 50028d231ee7d6dbd6adb601347672fbae1b1759 Mon Sep 17 00:00:00 2001 From: Fabio Pellacini Date: Wed, 9 Sep 2020 10:41:19 +0200 Subject: [PATCH 06/11] updated --- apps/ysceneitrace/ysceneitrace.cpp | 100 +++++++++++++++------------ apps/ysceneitraces/ysceneitraces.cpp | 52 ++++++++------ apps/yscenetrace/yscenetrace.cpp | 52 ++++++++------ libs/yocto/yocto_trace.h | 23 ------ 4 files changed, 114 insertions(+), 113 deletions(-) diff --git a/apps/ysceneitrace/ysceneitrace.cpp b/apps/ysceneitrace/ysceneitrace.cpp index 9292f2019..a821a6c6d 100644 --- a/apps/ysceneitrace/ysceneitrace.cpp +++ b/apps/ysceneitrace/ysceneitrace.cpp @@ -164,29 +164,35 @@ void init_scene(trace_scene* scene, sceneio_scene* ioscene, for (auto iomaterial : ioscene->materials) { if (progress_cb) progress_cb("converting materials", progress.x++, progress.y); - auto material = add_material(scene); - set_emission(material, iomaterial->emission, - texture_map.at(iomaterial->emission_tex)); - set_color( - material, iomaterial->color, texture_map.at(iomaterial->color_tex)); - set_specular(material, iomaterial->specular, - texture_map.at(iomaterial->specular_tex)); - set_ior(material, iomaterial->ior); - set_metallic(material, iomaterial->metallic, - texture_map.at(iomaterial->metallic_tex)); - set_transmission(material, iomaterial->transmission, iomaterial->thin, - iomaterial->trdepth, texture_map.at(iomaterial->transmission_tex)); - set_translucency(material, iomaterial->translucency, iomaterial->thin, - iomaterial->trdepth, texture_map.at(iomaterial->translucency_tex)); - set_roughness(material, iomaterial->roughness, - texture_map.at(iomaterial->roughness_tex)); - set_opacity( - material, iomaterial->opacity, texture_map.at(iomaterial->opacity_tex)); - set_thin(material, iomaterial->thin); - set_normalmap(material, texture_map.at(iomaterial->normal_tex)); - set_scattering(material, iomaterial->scattering, iomaterial->scanisotropy, - texture_map.at(iomaterial->scattering_tex)); - material_map[iomaterial] = material; + auto material = add_material(scene); + material->emission = iomaterial->emission; + material->color = iomaterial->color; + material->specular = iomaterial->specular; + material->roughness = iomaterial->roughness; + material->metallic = iomaterial->metallic; + material->ior = iomaterial->ior; + material->spectint = iomaterial->spectint; + material->coat = iomaterial->coat; + material->transmission = iomaterial->transmission; + material->translucency = iomaterial->translucency; + material->scattering = iomaterial->scattering; + material->scanisotropy = iomaterial->scanisotropy; + material->trdepth = iomaterial->trdepth; + material->opacity = iomaterial->opacity; + material->thin = iomaterial->thin; + material->emission_tex = texture_map.at(iomaterial->emission_tex); + material->color_tex = texture_map.at(iomaterial->color_tex); + material->specular_tex = texture_map.at(iomaterial->specular_tex); + material->metallic_tex = texture_map.at(iomaterial->metallic_tex); + material->roughness_tex = texture_map.at(iomaterial->roughness_tex); + material->transmission_tex = texture_map.at(iomaterial->transmission_tex); + material->translucency_tex = texture_map.at(iomaterial->translucency_tex); + material->spectint_tex = texture_map.at(iomaterial->spectint_tex); + material->scattering_tex = texture_map.at(iomaterial->scattering_tex); + material->coat_tex = texture_map.at(iomaterial->coat_tex); + material->opacity_tex = texture_map.at(iomaterial->opacity_tex); + material->normal_tex = texture_map.at(iomaterial->normal_tex); + material_map[iomaterial] = material; } auto shape_map = unordered_map{}; @@ -654,27 +660,33 @@ void draw_widgets(gui_window* win, app_states* apps, const gui_input& input) { auto iomaterial = app->selected_material; auto material = get_element( iomaterial, app->ioscene->materials, app->scene->materials); - set_emission(material, iomaterial->emission, - get_texture(iomaterial->emission_tex)); - set_color( - material, iomaterial->color, get_texture(iomaterial->color_tex)); - set_specular(material, iomaterial->specular, - get_texture(iomaterial->specular_tex)); - set_ior(material, iomaterial->ior); - set_metallic(material, iomaterial->metallic, - get_texture(iomaterial->metallic_tex)); - set_transmission(material, iomaterial->transmission, iomaterial->thin, - iomaterial->trdepth, get_texture(iomaterial->transmission_tex)); - set_translucency(material, iomaterial->translucency, iomaterial->thin, - iomaterial->trdepth, get_texture(iomaterial->translucency_tex)); - set_roughness(material, iomaterial->roughness, - get_texture(iomaterial->roughness_tex)); - set_opacity( - material, iomaterial->opacity, get_texture(iomaterial->opacity_tex)); - set_thin(material, iomaterial->thin); - set_normalmap(material, get_texture(iomaterial->normal_tex)); - set_scattering(material, iomaterial->scattering, iomaterial->scanisotropy, - get_texture(iomaterial->scattering_tex)); + material->emission = iomaterial->emission; + material->color = iomaterial->color; + material->specular = iomaterial->specular; + material->roughness = iomaterial->roughness; + material->metallic = iomaterial->metallic; + material->ior = iomaterial->ior; + material->spectint = iomaterial->spectint; + material->coat = iomaterial->coat; + material->transmission = iomaterial->transmission; + material->translucency = iomaterial->translucency; + material->scattering = iomaterial->scattering; + material->scanisotropy = iomaterial->scanisotropy; + material->trdepth = iomaterial->trdepth; + material->opacity = iomaterial->opacity; + material->thin = iomaterial->thin; + material->emission_tex = get_texture(iomaterial->emission_tex); + material->color_tex = get_texture(iomaterial->color_tex); + material->specular_tex = get_texture(iomaterial->specular_tex); + material->metallic_tex = get_texture(iomaterial->metallic_tex); + material->roughness_tex = get_texture(iomaterial->roughness_tex); + material->transmission_tex = get_texture(iomaterial->transmission_tex); + material->translucency_tex = get_texture(iomaterial->translucency_tex); + material->spectint_tex = get_texture(iomaterial->spectint_tex); + material->scattering_tex = get_texture(iomaterial->scattering_tex); + material->coat_tex = get_texture(iomaterial->coat_tex); + material->opacity_tex = get_texture(iomaterial->opacity_tex); + material->normal_tex = get_texture(iomaterial->normal_tex); init_lights(app->lights, app->scene, app->params); reset_display(app); } diff --git a/apps/ysceneitraces/ysceneitraces.cpp b/apps/ysceneitraces/ysceneitraces.cpp index 328f13493..266cdfc6a 100644 --- a/apps/ysceneitraces/ysceneitraces.cpp +++ b/apps/ysceneitraces/ysceneitraces.cpp @@ -152,29 +152,35 @@ void init_scene(trace_scene* scene, sceneio_scene* ioscene, for (auto iomaterial : ioscene->materials) { if (progress_cb) progress_cb("converting materials", progress.x++, progress.y); - auto material = add_material(scene); - set_emission(material, iomaterial->emission, - texture_map.at(iomaterial->emission_tex)); - set_color( - material, iomaterial->color, texture_map.at(iomaterial->color_tex)); - set_specular(material, iomaterial->specular, - texture_map.at(iomaterial->specular_tex)); - set_ior(material, iomaterial->ior); - set_metallic(material, iomaterial->metallic, - texture_map.at(iomaterial->metallic_tex)); - set_transmission(material, iomaterial->transmission, iomaterial->thin, - iomaterial->trdepth, texture_map.at(iomaterial->transmission_tex)); - set_translucency(material, iomaterial->translucency, iomaterial->thin, - iomaterial->trdepth, texture_map.at(iomaterial->translucency_tex)); - set_roughness(material, iomaterial->roughness, - texture_map.at(iomaterial->roughness_tex)); - set_opacity( - material, iomaterial->opacity, texture_map.at(iomaterial->opacity_tex)); - set_thin(material, iomaterial->thin); - set_normalmap(material, texture_map.at(iomaterial->normal_tex)); - set_scattering(material, iomaterial->scattering, iomaterial->scanisotropy, - texture_map.at(iomaterial->scattering_tex)); - material_map[iomaterial] = material; + auto material = add_material(scene); + material->emission = iomaterial->emission; + material->color = iomaterial->color; + material->specular = iomaterial->specular; + material->roughness = iomaterial->roughness; + material->metallic = iomaterial->metallic; + material->ior = iomaterial->ior; + material->spectint = iomaterial->spectint; + material->coat = iomaterial->coat; + material->transmission = iomaterial->transmission; + material->translucency = iomaterial->translucency; + material->scattering = iomaterial->scattering; + material->scanisotropy = iomaterial->scanisotropy; + material->trdepth = iomaterial->trdepth; + material->opacity = iomaterial->opacity; + material->thin = iomaterial->thin; + material->emission_tex = texture_map.at(iomaterial->emission_tex); + material->color_tex = texture_map.at(iomaterial->color_tex); + material->specular_tex = texture_map.at(iomaterial->specular_tex); + material->metallic_tex = texture_map.at(iomaterial->metallic_tex); + material->roughness_tex = texture_map.at(iomaterial->roughness_tex); + material->transmission_tex = texture_map.at(iomaterial->transmission_tex); + material->translucency_tex = texture_map.at(iomaterial->translucency_tex); + material->spectint_tex = texture_map.at(iomaterial->spectint_tex); + material->scattering_tex = texture_map.at(iomaterial->scattering_tex); + material->coat_tex = texture_map.at(iomaterial->coat_tex); + material->opacity_tex = texture_map.at(iomaterial->opacity_tex); + material->normal_tex = texture_map.at(iomaterial->normal_tex); + material_map[iomaterial] = material; } auto shape_map = unordered_map{}; diff --git a/apps/yscenetrace/yscenetrace.cpp b/apps/yscenetrace/yscenetrace.cpp index f485cfd75..4b14e910b 100644 --- a/apps/yscenetrace/yscenetrace.cpp +++ b/apps/yscenetrace/yscenetrace.cpp @@ -80,29 +80,35 @@ void init_scene(trace_scene* scene, sceneio_scene* ioscene, for (auto iomaterial : ioscene->materials) { if (progress_cb) progress_cb("converting materials", progress.x++, progress.y); - auto material = add_material(scene); - set_emission(material, iomaterial->emission, - texture_map.at(iomaterial->emission_tex)); - set_color( - material, iomaterial->color, texture_map.at(iomaterial->color_tex)); - set_specular(material, iomaterial->specular, - texture_map.at(iomaterial->specular_tex)); - set_ior(material, iomaterial->ior); - set_metallic(material, iomaterial->metallic, - texture_map.at(iomaterial->metallic_tex)); - set_transmission(material, iomaterial->transmission, iomaterial->thin, - iomaterial->trdepth, texture_map.at(iomaterial->transmission_tex)); - set_translucency(material, iomaterial->translucency, iomaterial->thin, - iomaterial->trdepth, texture_map.at(iomaterial->translucency_tex)); - set_roughness(material, iomaterial->roughness, - texture_map.at(iomaterial->roughness_tex)); - set_opacity( - material, iomaterial->opacity, texture_map.at(iomaterial->opacity_tex)); - set_thin(material, iomaterial->thin); - set_normalmap(material, texture_map.at(iomaterial->normal_tex)); - set_scattering(material, iomaterial->scattering, iomaterial->scanisotropy, - texture_map.at(iomaterial->scattering_tex)); - material_map[iomaterial] = material; + auto material = add_material(scene); + material->emission = iomaterial->emission; + material->color = iomaterial->color; + material->specular = iomaterial->specular; + material->roughness = iomaterial->roughness; + material->metallic = iomaterial->metallic; + material->ior = iomaterial->ior; + material->spectint = iomaterial->spectint; + material->coat = iomaterial->coat; + material->transmission = iomaterial->transmission; + material->translucency = iomaterial->translucency; + material->scattering = iomaterial->scattering; + material->scanisotropy = iomaterial->scanisotropy; + material->trdepth = iomaterial->trdepth; + material->opacity = iomaterial->opacity; + material->thin = iomaterial->thin; + material->emission_tex = texture_map.at(iomaterial->emission_tex); + material->color_tex = texture_map.at(iomaterial->color_tex); + material->specular_tex = texture_map.at(iomaterial->specular_tex); + material->metallic_tex = texture_map.at(iomaterial->metallic_tex); + material->roughness_tex = texture_map.at(iomaterial->roughness_tex); + material->transmission_tex = texture_map.at(iomaterial->transmission_tex); + material->translucency_tex = texture_map.at(iomaterial->translucency_tex); + material->spectint_tex = texture_map.at(iomaterial->spectint_tex); + material->scattering_tex = texture_map.at(iomaterial->scattering_tex); + material->coat_tex = texture_map.at(iomaterial->coat_tex); + material->opacity_tex = texture_map.at(iomaterial->opacity_tex); + material->normal_tex = texture_map.at(iomaterial->normal_tex); + material_map[iomaterial] = material; } auto shape_map = unordered_map{}; diff --git a/libs/yocto/yocto_trace.h b/libs/yocto/yocto_trace.h index 1505e3e09..18b3ae408 100644 --- a/libs/yocto/yocto_trace.h +++ b/libs/yocto/yocto_trace.h @@ -226,29 +226,6 @@ trace_shape* add_shape(trace_scene* scene); trace_texture* add_texture(trace_scene* scene); trace_instance* add_complete_instance(trace_scene* scene); -// set material properties -void set_emission(trace_material* material, const vec3f& emission, - trace_texture* emission_tex = nullptr); -void set_color(trace_material* material, const vec3f& color, - trace_texture* color_tex = nullptr); -void set_specular(trace_material* material, float specular = 1, - trace_texture* specular_tex = nullptr); -void set_ior(trace_material* material, float ior); -void set_metallic(trace_material* material, float metallic, - trace_texture* metallic_tex = nullptr); -void set_transmission(trace_material* material, float transmission, bool thin, - float trdepth, trace_texture* transmission_tex = nullptr); -void set_translucency(trace_material* material, float translucency, bool thin, - float trdepth, trace_texture* translucency_tex = nullptr); -void set_roughness(trace_material* material, float roughness, - trace_texture* roughness_tex = nullptr); -void set_opacity(trace_material* material, float opacity, - trace_texture* opacity_tex = nullptr); -void set_thin(trace_material* material, bool thin); -void set_scattering(trace_material* material, const vec3f& scattering, - float scanisotropy, trace_texture* scattering_tex = nullptr); -void set_normalmap(trace_material* material, trace_texture* normal_tex); - } // namespace yocto // ----------------------------------------------------------------------------- From 58522f7097e5e087807e26c3694351e5237c18b5 Mon Sep 17 00:00:00 2001 From: Fabio Pellacini Date: Wed, 9 Sep 2020 10:47:05 +0200 Subject: [PATCH 07/11] updated --- apps/ysceneproc/ysceneproc.cpp | 48 +++++++++++++++----------- libs/yocto/yocto_sceneio.h | 61 ---------------------------------- 2 files changed, 29 insertions(+), 80 deletions(-) diff --git a/apps/ysceneproc/ysceneproc.cpp b/apps/ysceneproc/ysceneproc.cpp index 6de7b0857..d375cdab8 100644 --- a/apps/ysceneproc/ysceneproc.cpp +++ b/apps/ysceneproc/ysceneproc.cpp @@ -62,36 +62,46 @@ triangles_shape make_bunny(float scale = 1, bool align_middle = true) { sceneio_camera* add_camera(sceneio_scene* scene, const string& name, const vec3f& from, const vec3f& to, const vec3f& up, float lens, - float aspect, float aperture = 0, bool ortho = false, float film = 0.036) { - auto camera = add_camera(scene, name); - set_frame(camera, lookat_frame(from, to, up)); - set_lens(camera, lens, aspect, film, ortho); - set_focus(camera, aperture, length(from - to)); + float aspect, float aperture = 0, bool orthographic = false, + float film = 0.036) { + auto camera = add_camera(scene, name); + camera->frame = lookat_frame(from, to, up); + camera->lens = lens; + camera->aspect = aspect; + camera->film = film; + camera->orthographic = orthographic; + camera->aperture = aperture; + camera->focus = length(from - to); return camera; } sceneio_camera* add_camera(sceneio_scene* scene, const string& name, const frame3f& frame, float lens, float aspect, float aperture = 0, - float focus = 10, bool ortho = false, float film = 0.036) { - auto camera = add_camera(scene, name); - set_frame(camera, frame); - set_lens(camera, lens, aspect, film, ortho); - set_focus(camera, aperture, focus); + float focus = 10, bool orthographic = false, float film = 0.036) { + auto camera = add_camera(scene, name); + camera->frame = frame; + camera->lens = lens; + camera->aspect = aspect; + camera->film = film; + camera->orthographic = orthographic; + camera->aperture = aperture; + camera->focus = focus; return camera; } sceneio_instance* add_instance(sceneio_scene* scene, const string& name, const frame3f& frame, sceneio_shape* shape, sceneio_material* material) { - auto instance = add_instance(scene, name); - set_frame(instance, frame); - set_shape(instance, shape); - set_material(instance, material); + auto instance = add_instance(scene, name); + instance->frame = frame; + instance->shape = shape; + instance->material = material; return instance; } sceneio_environment* add_environment(sceneio_scene* scene, const string& name, const frame3f& frame, const vec3f& emission, sceneio_texture* emission_tex = nullptr) { - auto environment = add_environment(scene, name); - set_frame(environment, frame); - set_emission(environment, emission, emission_tex); + auto environment = add_environment(scene, name); + environment->frame = frame; + environment->emission = emission; + environment->emission_tex = emission_tex; return environment; } sceneio_texture* add_texture(sceneio_scene* scene, const string& name, @@ -99,9 +109,9 @@ sceneio_texture* add_texture(sceneio_scene* scene, const string& name, bool single_channel = false) { auto texture = add_texture(scene, name); if (hdr) { - set_texture(texture, img); + texture->hdr = img; } else { - set_texture(texture, ldr_linear ? float_to_byte(img) : rgb_to_srgbb(img)); + texture->ldr = ldr_linear ? float_to_byte(img) : rgb_to_srgbb(img); } return texture; } diff --git a/libs/yocto/yocto_sceneio.h b/libs/yocto/yocto_sceneio.h index abc753073..54952fab8 100644 --- a/libs/yocto/yocto_sceneio.h +++ b/libs/yocto/yocto_sceneio.h @@ -242,67 +242,6 @@ sceneio_texture* add_texture(sceneio_scene* scene, const string& name = ""); sceneio_instance* add_complete_instance( sceneio_scene* scene, const string& name = ""); -// set camera properties -void set_frame(sceneio_camera* camera, const frame3f& frame); -void set_lens(sceneio_camera* camera, float lens, float aspect, float film, - bool ortho = false); -void set_focus(sceneio_camera* camera, float aperture, float focus); - -// set instance properties -void set_frame(sceneio_instance* instance, const frame3f& frame); -void set_material(sceneio_instance* instance, sceneio_material* material); -void set_shape(sceneio_instance* instance, sceneio_shape* shape); - -// set texture properties -void set_texture(sceneio_texture* texture, const image& img); -void set_texture(sceneio_texture* texture, const image& img); - -// set material properties -void set_emission(sceneio_material* material, const vec3f& emission, - sceneio_texture* emission_tex = nullptr); -void set_color(sceneio_material* material, const vec3f& color, - sceneio_texture* color_tex = nullptr); -void set_specular(sceneio_material* material, float specular = 1, - sceneio_texture* specular_tex = nullptr); -void set_ior(sceneio_material* material, float ior); -void set_metallic(sceneio_material* material, float metallic, - sceneio_texture* metallic_tex = nullptr); -void set_transmission(sceneio_material* material, float transmission, bool thin, - float trdepth, sceneio_texture* transmission_tex = nullptr); -void set_translucency(sceneio_material* material, float translucency, bool thin, - float trdepth, sceneio_texture* translucency_tex = nullptr); -void set_roughness(sceneio_material* material, float roughness, - sceneio_texture* roughness_tex = nullptr); -void set_opacity(sceneio_material* material, float opacity, - sceneio_texture* opacity_tex = nullptr); -void set_thin(sceneio_material* material, bool thin); -void set_scattering(sceneio_material* material, const vec3f& scattering, - float scanisotropy, sceneio_texture* scattering_tex = nullptr); -void set_normalmap(sceneio_material* material, sceneio_texture* normal_tex); - -// set shape properties -void set_points(sceneio_shape* shape, const vector& points); -void set_lines(sceneio_shape* shape, const vector& lines); -void set_triangles(sceneio_shape* shape, const vector& triangles); -void set_quads(sceneio_shape* shape, const vector& quads); -void set_fvquads(sceneio_shape* shape, const vector& quadspos, - const vector& quadsnorm, const vector& quadstexcoord); -void set_positions(sceneio_shape* shape, const vector& positions); -void set_normals(sceneio_shape* shape, const vector& normals); -void set_texcoords(sceneio_shape* shape, const vector& texcoords); -void set_colors(sceneio_shape* shape, const vector& colors); -void set_radius(sceneio_shape* shape, const vector& radius); -void set_tangents(sceneio_shape* shape, const vector& tangents); -void set_subdivision(sceneio_shape* shape, int subdivisions, bool catmullclark, - bool smooth = true); -void set_displacement(sceneio_shape* shape, float displacement, - sceneio_texture* displacement_tex); - -// set environment properties -void set_frame(sceneio_environment* environment, const frame3f& frame); -void set_emission(sceneio_environment* environment, const vec3f& emission, - sceneio_texture* emission_tex = nullptr); - // add missing elements void add_cameras(sceneio_scene* scene); void add_radius(sceneio_scene* scene, float radius = 0.001f); From 9814f32f5d8f639ffe310f9f9ccdfa53b823decd Mon Sep 17 00:00:00 2001 From: Fabio Pellacini Date: Wed, 9 Sep 2020 10:49:53 +0200 Subject: [PATCH 08/11] updated --- libs/yocto/yocto_trace.cpp | 159 ------------------------------------- 1 file changed, 159 deletions(-) diff --git a/libs/yocto/yocto_trace.cpp b/libs/yocto/yocto_trace.cpp index e57d48683..5185e6fe3 100644 --- a/libs/yocto/yocto_trace.cpp +++ b/libs/yocto/yocto_trace.cpp @@ -92,165 +92,6 @@ trace_instance* add_instance(trace_scene* scene) { trace_material* add_material(trace_scene* scene) { return scene->materials.emplace_back(new trace_material{}); } -trace_instance* add_complete_instance(trace_scene* scene) { - auto instance = add_instance(scene); - instance->shape = add_shape(scene); - instance->material = add_material(scene); - return instance; -} - -// Set cameras -void set_frame(trace_camera* camera, const frame3f& frame) { - camera->frame = frame; -} -void set_lens( - trace_camera* camera, float lens, float aspect, float film, bool ortho) { - camera->lens = lens; - camera->aspect = aspect; - camera->film = film; - camera->orthographic = ortho; -} -void set_focus(trace_camera* camera, float aperture, float focus) { - camera->aperture = aperture; - camera->focus = focus; -} - -// Add texture -void set_texture(trace_texture* texture, const image& img) { - texture->ldr = img; - texture->hdr = {}; -} -void set_texture(trace_texture* texture, const image& img) { - texture->ldr = {}; - texture->hdr = img; -} - -// Add shape -void set_points(trace_shape* shape, const vector& points) { - shape->points = points; -} -void set_lines(trace_shape* shape, const vector& lines) { - shape->lines = lines; -} -void set_triangles(trace_shape* shape, const vector& triangles) { - shape->triangles = triangles; -} -void set_quads(trace_shape* shape, const vector& quads) { - shape->quads = quads; -} -void set_fvquads(trace_shape* shape, const vector& quadspos, - const vector& quadsnorm, const vector& quadstexcoord) { - shape->quadspos = quadspos; - shape->quadsnorm = quadsnorm; - shape->quadstexcoord = quadstexcoord; -} -void set_positions(trace_shape* shape, const vector& positions) { - shape->positions = positions; -} -void set_normals(trace_shape* shape, const vector& normals) { - shape->normals = normals; -} -void set_texcoords(trace_shape* shape, const vector& texcoords) { - shape->texcoords = texcoords; -} -void set_colors(trace_shape* shape, const vector& colors) { - shape->colors = colors; -} -void set_radius(trace_shape* shape, const vector& radius) { - shape->radius = radius; -} -void set_tangents(trace_shape* shape, const vector& tangents) { - shape->tangents = tangents; -} -void set_subdivision( - trace_shape* shape, int subdivisions, bool catmullclark, bool smooth) { - shape->subdivisions = subdivisions; - shape->catmullclark = catmullclark; - shape->smooth = smooth; -} -void set_displacement( - trace_shape* shape, float displacement, trace_texture* displacement_tex) { - shape->displacement = displacement; - shape->displacement_tex = displacement_tex; -} - -// Add instance -void set_frame(trace_instance* instance, const frame3f& frame) { - instance->frame = frame; -} -void set_shape(trace_instance* instance, trace_shape* shape) { - instance->shape = shape; -} -void set_material(trace_instance* instance, trace_material* material) { - instance->material = material; -} - -// Add material -void set_emission(trace_material* material, const vec3f& emission, - trace_texture* emission_tex) { - material->emission = emission; - material->emission_tex = emission_tex; -} -void set_color( - trace_material* material, const vec3f& color, trace_texture* color_tex) { - material->color = color; - material->color_tex = color_tex; -} -void set_specular( - trace_material* material, float specular, trace_texture* specular_tex) { - material->specular = specular; - material->specular_tex = specular_tex; -} -void set_metallic( - trace_material* material, float metallic, trace_texture* metallic_tex) { - material->metallic = metallic; - material->metallic_tex = metallic_tex; -} -void set_ior(trace_material* material, float ior) { material->ior = ior; } -void set_transmission(trace_material* material, float transmission, bool thin, - float trdepth, trace_texture* transmission_tex) { - material->transmission = transmission; - material->thin = thin; - material->trdepth = trdepth; - material->transmission_tex = transmission_tex; -} -void set_translucency(trace_material* material, float translucency, bool thin, - float trdepth, trace_texture* translucency_tex) { - material->translucency = translucency; - material->thin = thin; - material->trdepth = trdepth; - material->translucency_tex = translucency_tex; -} -void set_thin(trace_material* material, bool thin) { material->thin = thin; } -void set_roughness( - trace_material* material, float roughness, trace_texture* roughness_tex) { - material->roughness = roughness; - material->roughness_tex = roughness_tex; -} -void set_opacity( - trace_material* material, float opacity, trace_texture* opacity_tex) { - material->opacity = opacity; - material->opacity_tex = opacity_tex; -} -void set_scattering(trace_material* material, const vec3f& scattering, - float scanisotropy, trace_texture* scattering_tex) { - material->scattering = scattering; - material->scanisotropy = scanisotropy; - material->scattering_tex = scattering_tex; -} -void set_normalmap(trace_material* material, trace_texture* normal_tex) { - material->normal_tex = normal_tex; -} - -// Add environment -void set_frame(trace_environment* environment, const frame3f& frame) { - environment->frame = frame; -} -void set_emission(trace_environment* environment, const vec3f& emission, - trace_texture* emission_tex) { - environment->emission = emission; - environment->emission_tex = emission_tex; -} } // namespace yocto From bf3a876dcdfaa1c6ef2bf91924ca0609400be4ea Mon Sep 17 00:00:00 2001 From: Fabio Pellacini Date: Wed, 9 Sep 2020 10:56:29 +0200 Subject: [PATCH 09/11] updated --- libs/yocto/yocto_sceneio.cpp | 153 ----------------------------------- 1 file changed, 153 deletions(-) diff --git a/libs/yocto/yocto_sceneio.cpp b/libs/yocto/yocto_sceneio.cpp index 5ff0aa351..95a0b2ab0 100644 --- a/libs/yocto/yocto_sceneio.cpp +++ b/libs/yocto/yocto_sceneio.cpp @@ -268,159 +268,6 @@ sceneio_instance* add_complete_instance( return instance; } -// Set cameras -void set_frame(sceneio_camera* camera, const frame3f& frame) { - camera->frame = frame; -} -void set_lens( - sceneio_camera* camera, float lens, float aspect, float film, bool ortho) { - camera->lens = lens; - camera->aspect = aspect; - camera->film = film; - camera->orthographic = ortho; -} -void set_focus(sceneio_camera* camera, float aperture, float focus) { - camera->aperture = aperture; - camera->focus = focus; -} - -// Add texture -void set_texture(sceneio_texture* texture, const image& img) { - texture->ldr = img; - texture->hdr = {}; -} -void set_texture(sceneio_texture* texture, const image& img) { - texture->ldr = {}; - texture->hdr = img; -} - -// Add shape -void set_points(sceneio_shape* shape, const vector& points) { - shape->points = points; -} -void set_lines(sceneio_shape* shape, const vector& lines) { - shape->lines = lines; -} -void set_triangles(sceneio_shape* shape, const vector& triangles) { - shape->triangles = triangles; -} -void set_quads(sceneio_shape* shape, const vector& quads) { - shape->quads = quads; -} -void set_fvquads(sceneio_shape* shape, const vector& quadspos, - const vector& quadsnorm, const vector& quadstexcoord) { - shape->quadspos = quadspos; - shape->quadsnorm = quadsnorm; - shape->quadstexcoord = quadstexcoord; -} -void set_positions(sceneio_shape* shape, const vector& positions) { - shape->positions = positions; -} -void set_normals(sceneio_shape* shape, const vector& normals) { - shape->normals = normals; -} -void set_texcoords(sceneio_shape* shape, const vector& texcoords) { - shape->texcoords = texcoords; -} -void set_colors(sceneio_shape* shape, const vector& colors) { - shape->colors = colors; -} -void set_radius(sceneio_shape* shape, const vector& radius) { - shape->radius = radius; -} -void set_tangents(sceneio_shape* shape, const vector& tangents) { - shape->tangents = tangents; -} -void set_subdivision( - sceneio_shape* shape, int subdivisions, bool catmullclark, bool smooth) { - shape->subdivisions = subdivisions; - shape->catmullclark = catmullclark; - shape->smooth = smooth; -} -void set_displacement(sceneio_shape* shape, float displacement, - sceneio_texture* displacement_tex) { - shape->displacement = displacement; - shape->displacement_tex = displacement_tex; -} - -// Add instance -void set_frame(sceneio_instance* instance, const frame3f& frame) { - instance->frame = frame; -} -void set_shape(sceneio_instance* instance, sceneio_shape* shape) { - instance->shape = shape; -} -void set_material(sceneio_instance* instance, sceneio_material* material) { - instance->material = material; -} - -// Add material -void set_emission(sceneio_material* material, const vec3f& emission, - sceneio_texture* emission_tex) { - material->emission = emission; - material->emission_tex = emission_tex; -} -void set_color(sceneio_material* material, const vec3f& color, - sceneio_texture* color_tex) { - material->color = color; - material->color_tex = color_tex; -} -void set_specular( - sceneio_material* material, float specular, sceneio_texture* specular_tex) { - material->specular = specular; - material->specular_tex = specular_tex; -} -void set_metallic( - sceneio_material* material, float metallic, sceneio_texture* metallic_tex) { - material->metallic = metallic; - material->metallic_tex = metallic_tex; -} -void set_ior(sceneio_material* material, float ior) { material->ior = ior; } -void set_transmission(sceneio_material* material, float transmission, bool thin, - float trdepth, sceneio_texture* transmission_tex) { - material->transmission = transmission; - material->thin = thin; - material->trdepth = trdepth; - material->transmission_tex = transmission_tex; -} -void set_translucency(sceneio_material* material, float translucency, bool thin, - float trdepth, sceneio_texture* translucency_tex) { - material->translucency = translucency; - material->thin = thin; - material->trdepth = trdepth; - material->translucency_tex = translucency_tex; -} -void set_thin(sceneio_material* material, bool thin) { material->thin = thin; } -void set_roughness(sceneio_material* material, float roughness, - sceneio_texture* roughness_tex) { - material->roughness = roughness; - material->roughness_tex = roughness_tex; -} -void set_opacity( - sceneio_material* material, float opacity, sceneio_texture* opacity_tex) { - material->opacity = opacity; - material->opacity_tex = opacity_tex; -} -void set_scattering(sceneio_material* material, const vec3f& scattering, - float scanisotropy, sceneio_texture* scattering_tex) { - material->scattering = scattering; - material->scanisotropy = scanisotropy; - material->scattering_tex = scattering_tex; -} -void set_normalmap(sceneio_material* material, sceneio_texture* normal_tex) { - material->normal_tex = normal_tex; -} - -// Add environment -void set_frame(sceneio_environment* environment, const frame3f& frame) { - environment->frame = frame; -} -void set_emission(sceneio_environment* environment, const vec3f& emission, - sceneio_texture* emission_tex) { - environment->emission = emission; - environment->emission_tex = emission_tex; -} - // Add missing cameras. void add_cameras(sceneio_scene* scene) { if (!scene->cameras.empty()) return; From b83d74a0b51efd24872df8f5c94c7c0ef548c97e Mon Sep 17 00:00:00 2001 From: Fabio Pellacini Date: Wed, 9 Sep 2020 13:13:17 +0200 Subject: [PATCH 10/11] updated --- docs/yocto/yocto_sceneio.md | 286 +++++++++++++++++++++--------------- docs/yocto/yocto_trace.md | 168 +++++++++------------ 2 files changed, 236 insertions(+), 218 deletions(-) diff --git a/docs/yocto/yocto_sceneio.md b/docs/yocto/yocto_sceneio.md index 4b76a7442..ee15ec80d 100644 --- a/docs/yocto/yocto_sceneio.md +++ b/docs/yocto/yocto_sceneio.md @@ -119,159 +119,203 @@ Objects are added to the scene via `add_(scene,name)` functions, where `` is the object type name. In these functions, the name is optional and, if left blank, a unique name will be generated automatically. For each object type, properties can be set directly. -As a convenience, Yocto/SceneIO defines several functions to set objects -properties. -For cameras, use `set_frame(camera, frame)` to set the local to world frame, -`set_lens(camera, lens, aspect, film, ortho)` to set the camera projection using -photographic lens parameters, and `set_focus(camera, aperture, focus)` to set -the camera aperture and focus distance. +For camera, you should set the camera frame, the camera view, +via lens, aspect and film, and optionally the camera aperture and focus. ```cpp -auto scene = new sceneio_scene{}; // create a scene -auto camera = add_camera(scene, "cam"); // create a camera named cam -set_frame(camera,identity3x4f); // set frame to identity -set_lens(camera,0.050,1.5,0.036); // set as 50mm lens 3:2 aspect on 35mm -set_aperture(camera,0.01,10); // set 10mm aperture focused at 10m +auto scene = new trace_scene{}; // create a scene +auto camera = add_camera(scene); // create a camera named cam +camera->frame = identity3x4f; // set frame to identity +camera->lens = 0.050; // set as 50mm lens +camera->aspect = 1.5; // set 3:2 aspect ratio +camera->film = 0.036; // set the film as 35mm +camera->aperture = 0.01; // set 10mm aperture +camera->focus = 10; // set the focus at 10m ``` -For instances, use `set_frame(instance, frame)` to set the local to world frame, -`set_shape(instance, shape)` and `set_material(instance, material)` -to set the shape and material pointers. Since adding instances of single -shapes is common in simpler scenes, the function -`add_complete_instance(scene, name)` adds an instance with a new shape and -material. +For instances, you should set the instance frame, shape and material. ```cpp -auto scene = new sceneio_scene{}; // create a scene -auto instance = add_instance(scene, "ist"); // create an instance named ist -set_frame(instance,identity3x4f); // set frame to identity -auto shape = add_shape(scene, "shp"); -set_shape(instance,shape); // set shape pointer -auto material = add_material(scene, "mat"); -set_material(instance,material); // set material pointer -auto instance1 = add_complete_instance(scene, "obj"); // create an instance -print_info(instance1->shape); // with a new shape -print_info(instance1->material); // and a new material +auto scene = new trace_scene{}; // create a scene +auto instance = add_instance(scene); // create an instance named ist +instance->frame = identity3x4f; // set frame to identity +auto shape = add_shape(scene); +instance->shape = shape; // set shape pointer +auto material = add_material(scene); +instance->material = material; // set material pointer ``` -For textures, use `set_texture(texture, img)` to set the texture -to the specified image. The function has overloads for images with -one or three channels and with float or byte channel types. +For textures, set _either_ the hdr or ldr image. ```cpp -auto scene = new sceneio_scene{}; // create a scene -auto texture = add_texture(scene, "tex"); // create a texture named tex -set_texture(texture,image{...}); // set as a HDR texture -set_texture(texture,image{...}); // set as a LDR texture +auto scene = new trace_scene{}; // create a scene +auto texture = add_texture(scene); // create a texture named tex +texture->hdr = image{...}; // set as a HDR texture +texture->ldr = ,image{...}; // set as a LDR texture ``` -For materials, Yocto/SceneIO defines functions to set each material property. -Each functions take as input the parameter value and an optional texture. -Use `set_emission(material, emission, tex)` to set material emission. -Use `set_color(material, color, tex)` to set the surface color, -`set_specular(material, specular, tex)`, -`set_metallic(material, metallic, tex)`, -`set_transmission(material, transmission, tex)` -for specular, metallic and transmission weights, -`set_ior(material, ior)`, `set_roughness(material, roughness, tex)`, -`set_opacity(material, opacity, tex)` for surface ior, roughness and opacity, -`set_scattering(material, scattering,tex)` for volumetric scattering and -`set_thin(material, thin)` for the thin flag. +For materials, we adopt a Disney0like model that has many parameters, +but can render a large varierty of looks. Here are some examples. ```cpp -auto scene = new sceneio_scene{}; // create a scene -auto matte = add_texture(scene, "matte"); // create a matte material -set_color(matte, {1,0.5,0.5}, add_texture(scene)); // textured albedo -auto plastic = add_texture(scene, "plastic"); // create a plastic material -set_color(plastic, {0.5,1,0.5}); // constant color -set_specular(plastic, 1); // constant specular -set_roughness(plastic, 0.1, add_texture(scene)); // textured roughness -auto metal = add_texture(scene, "metal"); // create a metal material -set_color(metal, {0.5,0.5,1}); // constant color -set_specular(metal, 1); // constant specular -set_roughness(metal, 0.1); // constant roughness -auto tglass = add_texture(scene, "tglass"); // create a thin glass material -set_color(tglass, {1,1,1}); // constant color -set_specular(tglass, 1); // constant specular -set_transmission(tglass, 1); // constant transmission -auto glass = add_texture(scene, "glass"); // create a glass material -set_color(glass, {1,1,1}); // constant color -set_specular(glass, 1); // constant specular -set_transmission(glass, 1); // constant transmission -set_thin(glass, false); // volumetric material -auto subsurf = add_texture(scene, "subsurf"); // create a subsurface material -set_color(subsurf, {1,1,1}); // constant color -set_specular(subsurf, 1); // constant specular -set_transmission(subsurf, 1); // constant transmission -set_thin(subsurf, false); // volumetric material -set_scattering(subsurf, {0.5,1,0.5}); // volumetric scattering +auto scene = new trace_scene{}; // create a scene +auto matte = add_texture(scene); // create a matte material +matte->color = {1,0.5,0.5}; // with baese color and +matte->color_tex = add_texture(scene); // textured albedo +auto plastic = add_texture(scene); // create a plastic material +plastic->color = {0.5,1,0.5}; // with constant color +plastic->specular = 1; // constant specular +plastic->roughness = 0.1; // base roughness and a +plastic->roughness_tex = add_texture(scene); // roughness texture +auto metal = add_texture(scene); // create a metal material +metal->color = {0.5,0.5,1}; // constant color +metal->metallic = 1; // constant metallic +metal->roughness = 0.1; // constant roughness +auto tglass = add_texture(scene); // create a thin glass material +tglass->color = {1,1,1}; // with constant color +tglass->specular = 1; // constant specular +tglass->transmission = 1; // constant transmission +auto glass = add_texture(scene); // create a glass material +glass->color = {1,1,1}; // constant color +glass->specular, = 1; // constant specular +glass->transmission = 1; // constant transmission +glass->thin = false; // non-volumetric material +auto subsurf = add_texture(scene); // create a subsurface material +subsurf->color = {1,1,1}; // constant color +subsurf->specular = 1; // constant specular +subsurf->transmission = 1; // constant transmission +subsurf->thin = false; // volumetric material +subsurf->scattering = {0.5,1,0.5}; // volumetric scattering ``` -For shapes, Yocto/SceneIO defines functions to set shape element indices -and vertex properties. Use `set_points(shape, points)`, -`set_lines(shape, lines)`, `set_triangles(shape, triangles)`, and -`set_quads(shape, quads)` to set indexed meshes indices as points, lines, -triangles and quads respectively. -Use `set_positions(shape, positions)`, `set_normals(shape, normals)`, -`set_texcoords(shape, texcoords)`, `set_colors(shape, colors)`, -`set_radius(shape, radius)`, and `set_tangents(shape, tangents)` -to set positions, normals, texture coordinates, colors, radius and -tangent spaces respectively. +For shapes, you should set the shape elements, i.e. point, limes, triangles +or quads, and the vertex properties, i.e. positions, normals, texture +coordiantes, colors and radia. Shapes support only one element type. ```cpp -auto scene = new sceneio_scene{}; // create a scene -auto shape = add_shape(scene, "shp"); // create a shape named shp -set_triangles(shape, vector{...}); // set triangle indices -set_positions(shape, vector{...}); // set positions -set_normals(shape, vector{...}); // set normals -set_texcoords(shape, vector{...}); // set texture coordinates +auto scene = new trace_scene{}; // create a scene +auto shape = add_shape(scene); // create a shape named shp +shape->triangles = vector{...}; // set triangle indices +shape->positions = vector{...}; // set positions +shape->normals = vector{...}; // set normals +shape->texcoords = vector{...}; // set texture coordinates ``` -Use `set_fvquads(shape, quadspos, quadsnorm, quadsuv)` to set the shapes as -a facce-varying quad mesh. Use `set_displacement(shape, disp, tex)` to -set the displacement map and scale and `set_subdivision(shape, level, cc)` -to set the subdivision level and whether to use Catmull-Clark or linear -subdivision. +Shapes can also be face-varying. In this case, set the quads for positions, +normals and texture coordinates. This is helpful when using subdivision +surfaces, which are specified by settings the subdivision level, and whether +to use Catmull-Clark or linear subdivision. Finally, displacement can also +be applied by setting a displacement scale and texture. ```cpp -auto scene = new sceneio_scene{}; // create a scene -auto shape = add_shape(scene, "shp"); // create a shape named shp -set_fvquads(shape, vector{...}, // set face-varying indices - {}, vector{...}); // for positions and textures -set_positions(shape, vector{...}); // set positions -set_texcoords(shape, vector{...}); // set texture coordinates -set_subdivision(shape, 2, true); // set Catmull-Clark subdivision -set_displacement(shape, 1, tex); // sete displacement map tex +auto scene = new trace_scene{}; // create a scene +auto shape = add_shape(scene); // create a shape named shp +shape->quadspos = vector{...}; // set face-varying indices +shape->quadstexcoord = vector{...}; // for positions and textures +shape->positions = vector{...}; // set positions +shape->texcoords = vector{...}; // set texture coordinates +shape>subdivisions = 2; // set subdivision level +shape->catmullclark = true; // set Catmull-Clark subdivision +shape->displacement = 1; // set displacement scale +shape->displacement_tex = tex; // and displacement map ``` -For environments, use `set_frame(environment, frame)` to set the local to -world frame, `set_emission(instance, emission, emission_tex)` to set the -environment emission and emission texture. +For environments, set the frame, emission and optionally the emission texture. ```cpp -auto scene = new sceneio_scene{}; // create a scene -auto environment = add_environment(scene, "env"); // create an environment -set_frame(environment, identity3x4f); // set identity transform +auto scene = new trace_scene{}; // create a scene +auto environment = add_environment(scene); // create an environment +environment->frame = identity3x4f; // set identity transform auto tex = add_scene(scene, "sky"); // add hdr texture -set_emission(environment, {1,1,1}, tex); // add emission scale and texture +environment->emission = {1,1,1}; // set emission scale +environment->emission_tex = tex; // add emission texture ``` -For quickly creating scenes, Yocto/SceneIO provides convenience functions -that add missing elements to construct full scenes. -Use `add_cameras(scene)` to add a default camera, `add_materials(scene)` -to add default materials for instances that miss it, `add_radius(scene)` -to add points and lines thickness for rendering, and `add_sky(scene)` to -add a procedural sky environment map. +## Scene tesselation + +The evaluation functions defined above and the ray intersection functions do +not support subdivision surfaces or displaced shapes directly. Instead, +shapes should be converted to indexed meshes using `tesselate_shape(shape)` +for a specific shape, or `tesselate_shapes(scene, progress)` for the +whole scene. Note that tesselations are destructive, meaning that the original +shape data is lost. This is done to avoid copying whenever possible. + +```cpp +auto scene = new trace_scene{...}; // create a complete scene +void tesselate_shapes(scene); // tesselate shapes in the scene +``` + +## Evaluation of scene properties + +Yocto/Trace defines several function to evaluate scene properties. +Use `compute_bounds(scene)` to compute the scene bounding boxes. +Use `get_camera(scene, name)` to get a camera by name or the default camera +is the name is not given. Use `eval_camera(camera, image_uv, lens_uv)` +to get a camera ray from the normalized image coordinates `image_uv` and +lens coordinates `lens_uv`. ```cpp -auto scene = new sceneio_scene{}; // create a scene -auto shape = add_shape(scene); // add a shape -auto instance = add_instance(scene); // add a shape instance -set_shape(instance,shape); -add_cameras(scene); // add default camera -add_materials(scene); // add default materials to instances -add_sky(scene); // add environment and procedural sky +auto scene = new trace_scene{...}; // create a complete scene +auto camera = get_camera(scene); // get default camera +auto ray = eval_camera(camera,{0.5,0.5},{0,0});// get ray though image center +``` + +Use `texture_size(texture)` to get the texture resolution, and +`eval_texture(texture, uv)` to evaluate the texture at specific uvs. +Textures evaluation returns a color in linear color space, regardless of +the texture representation. + +```cpp +auto scene = new trace_scene{...}; // create a complete scene +auto texture = scene->textures.front(); // get first texture +auto col = eval_texture(texture,{0.5,0.5}); // eval texture +``` + +Use `eval_material(material, texcoord)` to evaluate material textures and +combine them with parameter values. The function returns a +`scene_material_sample` that has the same parameters of a material but no +textures defined. + +```cpp +auto scene = new trace_scene{...}; // create a complete scene +auto material = scene->materials.front(); // get first material +auto mat = eval_material(material,{0.5,0.5}); // eval material +``` + +Several functions are defined to evaluate the geometric and material +properties of points on instances, indicated by the shape element id +and, when needed, the shape element barycentric coordinates. +Use `eval_position(...)` to evaluate the point position, +`eval_normal(...)` to evaluate the interpolate point normal, +`eval_texcoord(...)` to evaluate the point texture coordinates, +`eval_element_normal(...)` to evaluate the point geometric normal, and +`eval_color(...)` to evaluate the interpolate point color. +Use `eval_material(...)` as a convenience function to evaluate material +properties of instance points. + +```cpp +auto scene = new trace_scene{...}; // create a complete scene +auto instance = scene->instances.front(); // get first instance +auto eid = 0; auto euv = vec3f{0.5,0.5}; // element id and uvs +auto pos = eval_position(instance, eid, euv); // eval point position +auto norm = eval_normal(instance, eid, euv); // eval point normal +auto st = eval_texcoord(instance, eid, euv); // eval point texture coords +auto col = eval_color(instance, eid, euv); // eval point color +auto gn = eval_element_normal(instance, eid, euv); // eval geometric normal +auto mat = eval_material(instance, eid, euv); // eval point material +``` + +Use `eval_environment(environment, direction)` to evaluate an environment +map emission along a specific direction `direction`. Use +`eval_environment(scene, direction)` to accumulate the lighting for all +environment maps. + +```cpp +auto scene = new trace_scene{...}; // create a complete scene +auto enva = eval_environment(scene, dir); // eval all environments +auto environment = scene->environments.front(); // get first environment +auto envi = eval_environment(environment, dir); // eval environment ``` ## Scene tesselation diff --git a/docs/yocto/yocto_trace.md b/docs/yocto/yocto_trace.md index 02630ffef..82012f2c1 100644 --- a/docs/yocto/yocto_trace.md +++ b/docs/yocto/yocto_trace.md @@ -306,145 +306,119 @@ parametrization. ## Scene Creation Objects are added to the scene via `add_(scene)` functions, -where `` is the object type name. In these functions, -the name is optional and, if left blank, a unique name will be generated -automatically. For each object type, properties can be set directly. -As a convenience, Yocto/Trace defines several functions to set objects -properties. +where `` is the object type name. For each object type, +properties can be set directly. -For cameras, use `set_frame(camera, frame)` to set the local to world frame, -`set_lens(camera, lens, aspect, film, ortho)` to set the camera projection using -photographic lens parameters, and `set_focus(camera, aperture, focus)` to set -the camera aperture and focus distance. +For camera, you should set the camera frame, the camera view, +via lens, aspect and film, and optionally the camera aperture and focus. ```cpp -auto scene = new trace_scene{}; // create a scene -auto camera = add_camera(scene); // create a camera named cam -set_frame(camera,identity3x4f); // set frame to identity -set_lens(camera,0.050,1.5,0.036); // set as 50mm lens 3:2 aspect on 35mm -set_aperture(camera,0.01,10); // set 10mm aperture focused at 10m +auto scene = new trace_scene{}; // create a scene +auto camera = add_camera(scene); // create a camera named cam +camera->frame = identity3x4f; // set frame to identity +camera->lens = 0.050; // set as 50mm lens +camera->aspect = 1.5; // set 3:2 aspect ratio +camera->film = 0.036; // set the film as 35mm +camera->aperture = 0.01; // set 10mm aperture +camera->focus = 10; // set the focus at 10m ``` -For instances, use `set_frame(instance, frame)` to set the local to world frame, -`set_shape(instance, shape)` and `set_material(instance, material)` -to set the shape and material pointers. Since adding instances of single -shapes is common in simpler scenes, the function -`add_complete_instance(scene, name)` adds an instance with a new shape and -material. +For instances, you should set the instance frame, shape and material. ```cpp -auto scene = new trace_scene{}; // create a scene -auto instance = add_instance(scene); // create an instance named ist -set_frame(instance,identity3x4f); // set frame to identity +auto scene = new trace_scene{}; // create a scene +auto instance = add_instance(scene); // create an instance named ist +instance->frame = identity3x4f; // set frame to identity auto shape = add_shape(scene); -set_shape(instance,shape); // set shape pointer +instance->shape = shape; // set shape pointer auto material = add_material(scene); -set_material(instance,material); // set material pointer -auto instance1 = add_complete_instance(scene); // create an instance -print_info(instance1->shape); // with a new shape -print_info(instance1->material); // and a new material +instance->material = material; // set material pointer ``` -For textures, use `set_texture(texture, img)` to set the texture -to the specified image. The function has overloads for images with -one or three channels and with float or byte channel types. +For textures, set _either_ the hdr or ldr image. ```cpp -auto scene = new trace_scene{}; // create a scene -auto texture = add_texture(scene); // create a texture named tex -set_texture(texture,image{...}); // set as a HDR texture -set_texture(texture,image{...}); // set as a LDR texture +auto scene = new trace_scene{}; // create a scene +auto texture = add_texture(scene); // create a texture named tex +texture->hdr = image{...}; // set as a HDR texture +texture->ldr = ,image{...}; // set as a LDR texture ``` -For materials, Yocto/Trace defines functions to set each material property. -Each functions take as input the parameter value and an optional texture. -Use `set_emission(material, emission, tex)` to set material emission. -Use `set_color(material, color, tex)` to set the surface color, -`set_specular(material, specular, tex)`, -`set_metallic(material, metallic, tex)`, -`set_transmission(material, transmission, tex)` -for specular, metallic and transmission weights, -`set_ior(material, ior)`, `set_roughness(material, roughness, tex)`, -`set_opacity(material, opacity, tex)` for surface ior, roughness and opacity, -`set_scattering(material, scattering,tex)` for volumetric scattering and -`set_thin(material, thin)` for the thin flag. +For materials, we adopt a Disney0like model that has many parameters, +but can render a large varierty of looks. Here are some examples. ```cpp auto scene = new trace_scene{}; // create a scene auto matte = add_texture(scene); // create a matte material -set_color(matte, {1,0.5,0.5}, add_texture(scene)); // textured albedo -auto plastic = add_texture(scene); // create a plastic material -set_color(plastic, {0.5,1,0.5}); // constant color -set_specular(plastic, 1); // constant specular -set_roughness(plastic, 0.1, add_texture(scene)); // textured roughness +matte->color = {1,0.5,0.5}; // with baese color and +matte->color_tex = add_texture(scene); // textured albedo +auto plastic = add_texture(scene); // create a plastic material +plastic->color = {0.5,1,0.5}; // with constant color +plastic->specular = 1; // constant specular +plastic->roughness = 0.1; // base roughness and a +plastic->roughness_tex = add_texture(scene); // roughness texture auto metal = add_texture(scene); // create a metal material -set_color(metal, {0.5,0.5,1}); // constant color -set_specular(metal, 1); // constant specular -set_roughness(metal, 0.1); // constant roughness +metal->color = {0.5,0.5,1}; // constant color +metal->metallic = 1; // constant metallic +metal->roughness = 0.1; // constant roughness auto tglass = add_texture(scene); // create a thin glass material -set_color(tglass, {1,1,1}); // constant color -set_specular(tglass, 1); // constant specular -set_transmission(tglass, 1); // constant transmission +tglass->color = {1,1,1}; // with constant color +tglass->specular = 1; // constant specular +tglass->transmission = 1; // constant transmission auto glass = add_texture(scene); // create a glass material -set_color(glass, {1,1,1}); // constant color -set_specular(glass, 1); // constant specular -set_transmission(glass, 1); // constant transmission -set_thin(glass, false); // volumetric material +glass->color = {1,1,1}; // constant color +glass->specular, = 1; // constant specular +glass->transmission = 1; // constant transmission +glass->thin = false; // non-volumetric material auto subsurf = add_texture(scene); // create a subsurface material -set_color(subsurf, {1,1,1}); // constant color -set_specular(subsurf, 1); // constant specular -set_transmission(subsurf, 1); // constant transmission -set_thin(subsurf, false); // volumetric material -set_scattering(subsurf, {0.5,1,0.5}); // volumetric scattering +subsurf->color = {1,1,1}; // constant color +subsurf->specular = 1; // constant specular +subsurf->transmission = 1; // constant transmission +subsurf->thin = false; // volumetric material +subsurf->scattering = {0.5,1,0.5}; // volumetric scattering ``` -For shapes, Yocto/Trace defines functions to set shape element indices -and vertex properties. Use `set_points(shape, points)`, -`set_lines(shape, lines)`, `set_triangles(shape, triangles)`, and -`set_quads(shape, quads)` to set indexed meshes indices as points, lines, -triangles and quads respectively. -Use `set_positions(shape, positions)`, `set_normals(shape, normals)`, -`set_texcoords(shape, texcoords)`, `set_colors(shape, colors)`, -`set_radius(shape, radius)`, and `set_tangents(shape, tangents)` -to set positions, normals, texture coordinates, colors, radius and -tangent spaces respectively. +For shapes, you should set the shape elements, i.e. point, limes, triangles +or quads, and the vertex properties, i.e. positions, normals, texture +coordiantes, colors and radia. Shapes support only one element type. ```cpp auto scene = new trace_scene{}; // create a scene auto shape = add_shape(scene); // create a shape named shp -set_triangles(shape, vector{...}); // set triangle indices -set_positions(shape, vector{...}); // set positions -set_normals(shape, vector{...}); // set normals -set_texcoords(shape, vector{...}); // set texture coordinates +shape->triangles = vector{...}; // set triangle indices +shape->positions = vector{...}; // set positions +shape->normals = vector{...}; // set normals +shape->texcoords = vector{...}; // set texture coordinates ``` -Use `set_fvquads(shape, quadspos, quadsnorm, quadsuv)` to set the shapes as -a facce-varying quad mesh. Use `set_displacement(shape, disp, tex)` to -set the displacement map and scale and `set_subdivision(shape, level, cc)` -to set the subdivision level and whether to use Catmull-Clark or linear -subdivision. +Shapes can also be face-varying. In this case, set the quads for positions, +normals and texture coordinates. This is helpful when using subdivision +surfaces, which are specified by settings the subdivision level, and whether +to use Catmull-Clark or linear subdivision. Finally, displacement can also +be applied by setting a displacement scale and texture. ```cpp auto scene = new trace_scene{}; // create a scene auto shape = add_shape(scene); // create a shape named shp -set_fvquads(shape, vector{...}, // set face-varying indices - {}, vector{...}); // for positions and textures -set_positions(shape, vector{...}); // set positions -set_texcoords(shape, vector{...}); // set texture coordinates -set_subdivision(shape, 2, true); // set Catmull-Clark subdivision -set_displacement(shape, 1, tex); // sete displacement map tex +shape->quadspos = vector{...}; // set face-varying indices +shape->quadstexcoord = vector{...}; // for positions and textures +shape->positions = vector{...}; // set positions +shape->texcoords = vector{...}; // set texture coordinates +shape>subdivisions = 2; // set subdivision level +shape->catmullclark = true; // set Catmull-Clark subdivision +shape->displacement = 1; // set displacement scale +shape->displacement_tex = tex; // and displacement map ``` -For environments, use `set_frame(environment, frame)` to set the local to -world frame, `set_emission(instance, emission, emission_tex)` to set the -environment emission and emission texture. +For environments, set the frame, emission and optionally the emission texture. ```cpp auto scene = new trace_scene{}; // create a scene auto environment = add_environment(scene); // create an environment -set_frame(environment, identity3x4f); // set identity transform +environment->frame = identity3x4f; // set identity transform auto tex = add_scene(scene, "sky"); // add hdr texture -set_emission(environment, {1,1,1}, tex); // add emission scale and texture +environment->emission = {1,1,1}; // set emission scale +environment->emission_tex = tex; // add emission texture ``` ## Scene tesselation From 51145cfbdf6e9b7a85a29245d647c975702ffbe7 Mon Sep 17 00:00:00 2001 From: Fabio Pellacini Date: Wed, 9 Sep 2020 13:13:59 +0200 Subject: [PATCH 11/11] updated --- libs/yocto/yocto_sceneio.cpp | 2 +- libs/yocto/yocto_sceneio.h | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/libs/yocto/yocto_sceneio.cpp b/libs/yocto/yocto_sceneio.cpp index 95a0b2ab0..3fd8a5bfe 100644 --- a/libs/yocto/yocto_sceneio.cpp +++ b/libs/yocto/yocto_sceneio.cpp @@ -260,7 +260,7 @@ sceneio_instance* add_instance(sceneio_scene* scene, const string& name) { sceneio_material* add_material(sceneio_scene* scene, const string& name) { return add_element(scene->materials, name, "material"); } -sceneio_instance* add_complete_instance( +static sceneio_instance* add_complete_instance( sceneio_scene* scene, const string& name) { auto instance = add_instance(scene, name); instance->shape = add_shape(scene, name); diff --git a/libs/yocto/yocto_sceneio.h b/libs/yocto/yocto_sceneio.h index 54952fab8..1cdd794cb 100644 --- a/libs/yocto/yocto_sceneio.h +++ b/libs/yocto/yocto_sceneio.h @@ -239,8 +239,6 @@ sceneio_instance* add_instance(sceneio_scene* scene, const string& name = ""); sceneio_material* add_material(sceneio_scene* scene, const string& name = ""); sceneio_shape* add_shape(sceneio_scene* scene, const string& name = ""); sceneio_texture* add_texture(sceneio_scene* scene, const string& name = ""); -sceneio_instance* add_complete_instance( - sceneio_scene* scene, const string& name = ""); // add missing elements void add_cameras(sceneio_scene* scene);