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

Image-based-lighting for real-time viewers #1034

Merged
merged 25 commits into from
Aug 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
e509644
update yocto_gui
giacomonazzaro Aug 15, 2020
6378347
Merge branch 'master' of https://github.com/xelatihy/yocto-gl into yo…
giacomonazzaro Aug 15, 2020
0fb79ef
Merge branch 'master' of https://github.com/xelatihy/yocto-gl into yo…
giacomonazzaro Aug 15, 2020
6738247
Merge branch 'master' of https://github.com/xelatihy/yocto-gl into yo…
giacomonazzaro Aug 16, 2020
85284ed
Merge branch 'master' of https://github.com/xelatihy/yocto-gl into yo…
giacomonazzaro Aug 18, 2020
5e5d8d8
compiles
giacomonazzaro Aug 18, 2020
b1b6b96
init ibl data
giacomonazzaro Aug 18, 2020
b4b44c0
Merge branch 'master' of https://github.com/xelatihy/yocto-gl into yo…
giacomonazzaro Aug 19, 2020
bc8a51f
baking does not crash
giacomonazzaro Aug 19, 2020
0fcf5a1
environment works
giacomonazzaro Aug 19, 2020
9db0a0c
renaming
giacomonazzaro Aug 19, 2020
13af9fb
towards new shapes
giacomonazzaro Aug 19, 2020
8a31eb4
no more set attributes during draw
giacomonazzaro Aug 19, 2020
80fd09f
removed VAO from ogl_program
giacomonazzaro Aug 19, 2020
a28ebe6
ibl works
giacomonazzaro Aug 19, 2020
e96afac
updated
giacomonazzaro Aug 19, 2020
31d02b6
shading types
giacomonazzaro Aug 20, 2020
ed3de72
Merge branch 'master' of https://github.com/xelatihy/yocto-gl into yo…
giacomonazzaro Aug 20, 2020
941a60e
embedding shaders
giacomonazzaro Aug 20, 2020
19977ae
update
giacomonazzaro Aug 20, 2020
c8f210a
Merge branch 'master' of https://github.com/xelatihy/yocto-gl into yo…
giacomonazzaro Aug 20, 2020
2d73da6
fix image viewer
giacomonazzaro Aug 20, 2020
bc6fd94
fixes
giacomonazzaro Aug 20, 2020
9453203
fix for no environment
giacomonazzaro Aug 20, 2020
0e34680
get environment texture in a safer way
giacomonazzaro Aug 20, 2020
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
32 changes: 19 additions & 13 deletions apps/ysceneview/ysceneview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
#include <yocto/yocto_parallel.h>
#include <yocto/yocto_sceneio.h>
#include <yocto/yocto_shape.h>
#include <yocto_gui/yocto_draw.h>
#include <yocto_gui/yocto_imgui.h>
#include <yocto_gui/yocto_opengl.h>
using namespace yocto;

#include <deque>
Expand All @@ -56,15 +56,15 @@ struct app_state {
string name = "";

// options
ogl_scene_params drawgl_prms = {};
gui_scene_params drawgl_prms = {};

// scene
sceneio_scene* ioscene = new sceneio_scene{};
sceneio_camera* iocamera = nullptr;

// rendering state
ogl_scene* glscene = new ogl_scene{};
ogl_camera* glcamera = nullptr;
gui_scene* glscene = new gui_scene{};
gui_camera* glcamera = nullptr;

// editing
sceneio_camera* selected_camera = nullptr;
Expand Down Expand Up @@ -97,7 +97,7 @@ struct app_states {
std::deque<app_state*> loading = {};

// default options
ogl_scene_params drawgl_prms = {};
gui_scene_params drawgl_prms = {};

// cleanup
~app_states() {
Expand Down Expand Up @@ -129,7 +129,7 @@ void load_scene_async(
if (!apps->selected) apps->selected = app;
}

void update_lights(ogl_scene* glscene, sceneio_scene* ioscene) {
void update_lights(gui_scene* glscene, sceneio_scene* ioscene) {
clear_lights(glscene);
for (auto ioobject : ioscene->instances) {
if (has_max_lights(glscene)) break;
Expand Down Expand Up @@ -159,8 +159,8 @@ void update_lights(ogl_scene* glscene, sceneio_scene* ioscene) {
}
}

void init_glscene(ogl_scene* glscene, sceneio_scene* ioscene,
ogl_camera*& glcamera, sceneio_camera* iocamera,
void init_glscene(gui_scene* glscene, sceneio_scene* ioscene,
gui_camera*& glcamera, sceneio_camera* iocamera,
progress_callback progress_cb) {
// handle progress
auto progress = vec2i{
Expand All @@ -172,7 +172,7 @@ void init_glscene(ogl_scene* glscene, sceneio_scene* ioscene,
init_scene(glscene);

// camera
auto camera_map = unordered_map<sceneio_camera*, ogl_camera*>{};
auto camera_map = unordered_map<sceneio_camera*, gui_camera*>{};
camera_map[nullptr] = nullptr;
for (auto iocamera : ioscene->cameras) {
if (progress_cb) progress_cb("convert camera", progress.x++, progress.y);
Expand All @@ -198,7 +198,7 @@ void init_glscene(ogl_scene* glscene, sceneio_scene* ioscene,
}

// material
auto material_map = unordered_map<sceneio_material*, ogl_material*>{};
auto material_map = unordered_map<sceneio_material*, gui_material*>{};
material_map[nullptr] = nullptr;
for (auto iomaterial : ioscene->materials) {
if (progress_cb) progress_cb("convert material", progress.x++, progress.y);
Expand Down Expand Up @@ -248,6 +248,12 @@ void init_glscene(ogl_scene* glscene, sceneio_scene* ioscene,
set_material(globject, material_map.at(ioinstance->material));
}

// bake prefiltered environments
if (ioscene->environments.size()) {
ibl::init_ibl_data(
glscene, texture_map[ioscene->environments[0]->emission_tex]);
}

// done
if (progress_cb) progress_cb("convert done", progress.x++, progress.y);

Expand Down Expand Up @@ -450,7 +456,7 @@ void draw_widgets(gui_window* win, app_states* apps, const gui_input& input) {
}
auto& params = app->drawgl_prms;
draw_slider(win, "resolution", params.resolution, 0, 4096);
draw_combobox(win, "shading", (int&)params.shading, ogl_shading_names);
draw_combobox(win, "shading", (int&)params.shading, gui_shading_names);
draw_checkbox(win, "wireframe", params.wireframe);
continue_line(win);
draw_checkbox(win, "edges", params.edges);
Expand Down Expand Up @@ -583,7 +589,7 @@ void draw_widgets(gui_window* win, app_states* apps, const gui_input& input) {
void draw(gui_window* win, app_states* apps, const gui_input& input) {
if (!apps->selected || !apps->selected->ok) return;
auto app = apps->selected;
if (app->drawgl_prms.shading == ogl_shading_type::lights)
if (app->drawgl_prms.shading == gui_shading_type::eyelight)
update_lights(app->glscene, app->ioscene);
draw_scene(app->glscene, app->glcamera, input.framebuffer_viewport,
app->drawgl_prms);
Expand Down Expand Up @@ -631,7 +637,7 @@ int main(int argc, const char* argv[]) {
add_option(cli, "--resolution,-r", apps->drawgl_prms.resolution,
"Image resolution.");
add_option(cli, "--shading", apps->drawgl_prms.shading, "Shading type.",
ogl_shading_names);
gui_shading_names);
add_option(cli, "scenes", filenames, "Scene filenames", true);
parse_cli(cli, argc, argv);

Expand Down
31 changes: 19 additions & 12 deletions apps/ysceneviews/ysceneviews.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
#include <yocto/yocto_parallel.h>
#include <yocto/yocto_sceneio.h>
#include <yocto/yocto_shape.h>
#include <yocto_gui/yocto_draw.h>
#include <yocto_gui/yocto_imgui.h>
#include <yocto_gui/yocto_opengl.h>
using namespace yocto;

#include <deque>
Expand All @@ -57,15 +57,15 @@ struct app_state {
string name = "";

// options
ogl_scene_params drawgl_prms = {};
gui_scene_params drawgl_prms = {};

// scene
sceneio_scene* ioscene = new sceneio_scene{};
sceneio_camera* iocamera = nullptr;

// rendering state
ogl_scene* glscene = new ogl_scene{};
ogl_camera* glcamera = nullptr;
gui_scene* glscene = new gui_scene{};
gui_camera* glcamera = nullptr;

// editing
sceneio_camera* selected_camera = nullptr;
Expand All @@ -90,7 +90,7 @@ struct app_state {
}
};

void update_lights(ogl_scene* glscene, sceneio_scene* ioscene) {
void update_lights(gui_scene* glscene, sceneio_scene* ioscene) {
clear_lights(glscene);
for (auto ioobject : ioscene->instances) {
if (has_max_lights(glscene)) break;
Expand Down Expand Up @@ -120,8 +120,8 @@ void update_lights(ogl_scene* glscene, sceneio_scene* ioscene) {
}
}

void init_glscene(ogl_scene* glscene, sceneio_scene* ioscene,
ogl_camera*& glcamera, sceneio_camera* iocamera,
void init_glscene(gui_scene* glscene, sceneio_scene* ioscene,
gui_camera*& glcamera, sceneio_camera* iocamera,
progress_callback progress_cb) {
// handle progress
auto progress = vec2i{
Expand All @@ -133,7 +133,7 @@ void init_glscene(ogl_scene* glscene, sceneio_scene* ioscene,
init_scene(glscene);

// camera
auto camera_map = unordered_map<sceneio_camera*, ogl_camera*>{};
auto camera_map = unordered_map<sceneio_camera*, gui_camera*>{};
camera_map[nullptr] = nullptr;
for (auto iocamera : ioscene->cameras) {
if (progress_cb) progress_cb("convert camera", progress.x++, progress.y);
Expand All @@ -159,7 +159,7 @@ void init_glscene(ogl_scene* glscene, sceneio_scene* ioscene,
}

// material
auto material_map = unordered_map<sceneio_material*, ogl_material*>{};
auto material_map = unordered_map<sceneio_material*, gui_material*>{};
material_map[nullptr] = nullptr;
for (auto iomaterial : ioscene->materials) {
if (progress_cb) progress_cb("convert material", progress.x++, progress.y);
Expand Down Expand Up @@ -209,6 +209,13 @@ void init_glscene(ogl_scene* glscene, sceneio_scene* ioscene,
set_material(globject, material_map.at(ioobject->material));
}

// bake prefiltered environments
// TODO(giacomo): what if there's more than 1 environment?
if (ioscene->environments.size()) {
ibl::init_ibl_data(
glscene, texture_map[ioscene->environments[0]->emission_tex]);
}

// done
if (progress_cb) progress_cb("convert done", progress.x++, progress.y);

Expand All @@ -228,7 +235,7 @@ int main(int argc, const char* argv[]) {
add_option(
cli, "--resolution,-r", app->drawgl_prms.resolution, "Image resolution.");
add_option(cli, "--shading", app->drawgl_prms.shading, "Eyelight rendering.",
ogl_shading_names);
gui_shading_names);
add_option(cli, "scene", app->filename, "Scene filename", true);
parse_cli(cli, argc, argv);

Expand Down Expand Up @@ -257,7 +264,7 @@ int main(int argc, const char* argv[]) {
clear_scene(app->glscene);
};
callbacks.draw_cb = [app](gui_window* win, const gui_input& input) {
if (app->drawgl_prms.shading == ogl_shading_type::lights)
if (app->drawgl_prms.shading == gui_shading_type::eyelight)
update_lights(app->glscene, app->ioscene);
draw_scene(app->glscene, app->glcamera, input.framebuffer_viewport,
app->drawgl_prms);
Expand All @@ -273,7 +280,7 @@ int main(int argc, const char* argv[]) {
auto& params = app->drawgl_prms;
draw_slider(win, "resolution", params.resolution, 0, 4096);
draw_checkbox(win, "wireframe", params.wireframe);
draw_combobox(win, "shading", (int&)params.shading, ogl_shading_names);
draw_combobox(win, "shading", (int&)params.shading, gui_shading_names);
continue_line(win);
draw_checkbox(win, "edges", params.edges);
continue_line(win);
Expand Down
16 changes: 8 additions & 8 deletions apps/yshapeview/yshapeview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include <yocto/yocto_sceneio.h>
#include <yocto/yocto_shape.h>
#include <yocto_gui/yocto_imgui.h>
#include <yocto_gui/yocto_opengl.h>
#include <yocto_gui/yocto_draw.h>
using namespace yocto;

#include <deque>
Expand All @@ -56,14 +56,14 @@ struct app_state {
string name = "";

// options
ogl_scene_params drawgl_prms = {};
gui_scene_params drawgl_prms = {};

// scene
generic_shape* ioshape = new generic_shape{};

// rendering state
ogl_scene* glscene = new ogl_scene{};
ogl_camera* glcamera = nullptr;
gui_scene* glscene = new gui_scene{};
gui_camera* glcamera = nullptr;

// loading status
std::atomic<bool> ok = false;
Expand All @@ -88,7 +88,7 @@ struct app_states {
std::deque<app_state*> loading = {};

// default options
ogl_scene_params drawgl_prms = {};
gui_scene_params drawgl_prms = {};

// cleanup
~app_states() {
Expand Down Expand Up @@ -170,7 +170,7 @@ quads_shape make_cylinders(const vector<vec2i>& lines,
return shape;
}

void init_glscene(ogl_scene* glscene, const generic_shape* ioshape,
void init_glscene(gui_scene* glscene, const generic_shape* ioshape,
progress_callback progress_cb) {
// handle progress
auto progress = vec2i{0, 4};
Expand Down Expand Up @@ -280,7 +280,7 @@ void draw_widgets(gui_window* win, app_states* apps, const gui_input& input) {
draw_coloredit(win, "color", glmaterial->color);
auto& params = app->drawgl_prms;
draw_slider(win, "resolution", params.resolution, 0, 4096);
draw_combobox(win, "shading", (int&)params.shading, ogl_shading_names);
draw_combobox(win, "shading", (int&)params.shading, gui_shading_names);
draw_checkbox(win, "wireframe", params.wireframe);
continue_line(win);
draw_checkbox(win, "edges", params.edges);
Expand Down Expand Up @@ -364,7 +364,7 @@ int main(int argc, const char* argv[]) {
add_option(cli, "--resolution,-r", apps->drawgl_prms.resolution,
"Image resolution.");
add_option(cli, "--shading", apps->drawgl_prms.shading, "Shading type.",
ogl_shading_names);
gui_shading_names);
add_option(cli, "shapes", filenames, "Shape filenames", true);
parse_cli(cli, argc, argv);

Expand Down
2 changes: 2 additions & 0 deletions libs/yocto_gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ if(YOCTO_OPENGL)
add_library(yocto_gui
yocto_opengl.h
yocto_opengl.cpp
yocto_draw.h
yocto_draw.cpp
yocto_imgui.h
yocto_imgui.cpp
ext/imgui/imgui.cpp
Expand Down
Loading