Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

External bvh in trace (WIP) #1067

Merged
merged 15 commits into from
Sep 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion .vscode/cmake-variants.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,23 @@
}
}
}
},
"useEmbree": {
"default": "yes",
"description": "Build with Embree",
"choices": {
"yes": {
"short": "Embree",
"settings": {
"YOCTO_EMBREE": "yes"
}
},
"no": {
"short": "NoEmbree",
"settings": {
"YOCTO_EMBREE": "no"
}
}
}
}
}
}
24 changes: 14 additions & 10 deletions apps/ysceneitrace/ysceneitrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ struct app_state {

// rendering objects
trace_lights* lights = new trace_lights{};
trace_bvh* bvh = new trace_bvh{};

// options
trace_params params = {};
Expand Down Expand Up @@ -96,8 +97,9 @@ struct app_state {
~app_state() {
if (render_state) trace_stop(render_state);
delete render_state;
delete scene;
delete bvh;
delete lights;
delete scene;
delete ioscene;
delete glimage;
}
Expand Down Expand Up @@ -247,7 +249,8 @@ void reset_display(app_state* app) {
app->status = "render";
app->render_counter = 0;
trace_start(
app->render_state, app->scene, app->camera, app->lights, app->params,
app->render_state, app->scene, app->camera, app->bvh, app->lights,
app->params,
[app](const string& message, int sample, int nsamples) {
app->current = sample;
app->total = nsamples;
Expand Down Expand Up @@ -289,8 +292,8 @@ void load_scene_async(app_states* apps, const string& filename,
init_scene(
app->scene, app->ioscene, app->camera, app->iocamera, progress_cb);
tesselate_shapes(app->scene, progress_cb);
init_bvh(app->scene, app->params);
init_lights(app->lights, app->scene);
init_bvh(app->bvh, app->scene, app->params);
init_lights(app->lights, app->scene, app->params);
if (app->lights->lights.empty() && is_sampler_lit(app->params)) {
app->params.sampler = trace_sampler_type::eyelight;
}
Expand Down Expand Up @@ -336,7 +339,7 @@ bool draw_widgets(
draw_label(win, "ldr",
std::to_string(iotexture->ldr.width()) + " x " +
std::to_string(iotexture->ldr.height()));
// TODO: load texture
// TODO(fabio): load texture
return edited;
}

Expand Down Expand Up @@ -590,7 +593,7 @@ void draw_widgets(gui_window* win, app_states* apps, const gui_input& input) {
set_frame(environment, ioenvironment->frame);
set_emission(environment, ioenvironment->emission,
get_texture(ioenvironment->emission_tex));
init_lights(app->lights, app->scene);
init_lights(app->lights, app->scene, app->params);
reset_display(app);
}
end_header(win);
Expand All @@ -609,7 +612,7 @@ void draw_widgets(gui_window* win, app_states* apps, const gui_input& input) {
set_material(
instance, get_element(ioinstance->material, app->ioscene->materials,
app->scene->materials));
update_bvh(app->scene, {instance}, {}, app->params);
update_bvh(app->bvh, app->scene, {instance}, {}, app->params);
reset_display(app);
}
end_header(win);
Expand All @@ -632,7 +635,7 @@ void draw_widgets(gui_window* win, app_states* apps, const gui_input& input) {
set_colors(shape, ioshape->colors);
set_radius(shape, ioshape->radius);
set_tangents(shape, ioshape->tangents);
update_bvh(app->scene, {}, {shape}, app->params);
update_bvh(app->bvh, app->scene, {}, {shape}, app->params);
reset_display(app);
}
end_header(win);
Expand Down Expand Up @@ -666,7 +669,7 @@ void draw_widgets(gui_window* win, app_states* apps, const gui_input& input) {
set_normalmap(material, get_texture(iomaterial->normal_tex));
set_scattering(material, iomaterial->scattering, iomaterial->scanisotropy,
get_texture(iomaterial->scattering_tex));
init_lights(app->lights, app->scene);
init_lights(app->lights, app->scene, app->params);
reset_display(app);
}
end_header(win);
Expand Down Expand Up @@ -818,7 +821,8 @@ int main(int argc, const char* argv[]) {
app->camera->lens, app->camera->film,
vec2f{ij.x + 0.5f, ij.y + 0.5f} /
vec2f{(float)app->render.width(), (float)app->render.height()});
if (auto isec = intersect_scene_bvh(app->scene, ray); isec.hit) {
if (auto isec = intersect_scene_bvh(app->bvh, app->scene, ray);
isec.hit) {
app->selected_instance = app->ioscene->instances[isec.instance];
}
}
Expand Down
9 changes: 6 additions & 3 deletions apps/ysceneitraces/ysceneitraces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ struct app_state {

// rendering objects
trace_lights* lights = new trace_lights{};
trace_bvh* bvh = new trace_bvh{};

// rendering state
image<vec4f> render = {};
Expand All @@ -78,6 +79,7 @@ struct app_state {
if (render_state) trace_stop(render_state);
delete render_state;
delete lights;
delete bvh;
delete scene;
if (glimage) delete glimage;
}
Expand All @@ -90,7 +92,8 @@ void reset_display(app_state* app) {
// start render
app->render_counter = 0;
trace_start(
app->render_state, app->scene, app->camera, app->lights, app->params,
app->render_state, app->scene, app->camera, app->bvh, app->lights,
app->params,
[app](const string& message, int sample, int nsamples) {
app->current = sample;
app->total = nsamples;
Expand Down Expand Up @@ -280,10 +283,10 @@ int main(int argc, const char* argv[]) {
tesselate_shapes(app->scene, print_progress);

// build bvh
init_bvh(app->scene, app->params, print_progress);
init_bvh(app->bvh, app->scene, app->params, print_progress);

// init renderer
init_lights(app->lights, app->scene, print_progress);
init_lights(app->lights, app->scene, app->params, print_progress);

// fix renderer type if no lights
if (app->lights->lights.empty() && is_sampler_lit(app->params)) {
Expand Down
14 changes: 9 additions & 5 deletions apps/yscenetrace/yscenetrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,14 @@ int main(int argc, const char* argv[]) {
tesselate_shapes(scene, print_progress);

// build bvh
init_bvh(scene, params, print_progress);
auto bvh_guard = std::make_unique<trace_bvh>();
auto bvh = bvh_guard.get();
init_bvh(bvh, scene, params, print_progress);

// init renderer
auto lights_guard = std::make_unique<trace_lights>();
auto lights = lights_guard.get();
init_lights(lights, scene, print_progress);
init_lights(lights, scene, params, print_progress);

// fix renderer type if no lights
if (lights->lights.empty() && is_sampler_lit(params)) {
Expand All @@ -225,7 +227,7 @@ int main(int argc, const char* argv[]) {
}

// render
auto render = trace_image(scene, camera, lights, params, print_progress,
auto render = trace_image(scene, camera, bvh, lights, params, print_progress,
[save_batch, imfilename](
const image<vec4f>& render, int sample, int samples) {
if (!save_batch) return;
Expand Down Expand Up @@ -256,7 +258,8 @@ int main(int argc, const char* argv[]) {

// render denoise albedo
fparams.sampler = trace_sampler_type::albedo;
auto albedo = trace_image(scene, camera, lights, fparams, print_progress);
auto albedo = trace_image(
scene, camera, bvh, lights, fparams, print_progress);
auto albedo_filename = replace_extension(
imfilename, "-albedo" + feature_ext);

Expand All @@ -266,7 +269,8 @@ int main(int argc, const char* argv[]) {

// render denoise normals
fparams.sampler = trace_sampler_type::normal;
auto normal = trace_image(scene, camera, lights, fparams, print_progress);
auto normal = trace_image(
scene, camera, bvh, lights, fparams, print_progress);
auto normal_filename = replace_extension(
imfilename, "-normal" + feature_ext);

Expand Down
Loading