Skip to content

Commit

Permalink
Display optional light paths overlay over final render or opengl view
Browse files Browse the repository at this point in the history
  • Loading branch information
fu5ha committed Jul 2, 2019
1 parent 2362c84 commit bf27aaf
Show file tree
Hide file tree
Showing 18 changed files with 338 additions and 281 deletions.
16 changes: 8 additions & 8 deletions src/appleseed.studio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -250,12 +250,12 @@ set (mainwindow_rendering_sources
mainwindow/rendering/cameracontroller.h
mainwindow/rendering/glscenelayer.h
mainwindow/rendering/glscenelayer.cpp
# mainwindow/rendering/lightpathspickinghandler.cpp
# mainwindow/rendering/lightpathspickinghandler.h
# mainwindow/rendering/lightpathsviewportmanager.cpp
# mainwindow/rendering/lightpathsviewportmanager.h
# mainwindow/rendering/lightpathslayer.cpp
# mainwindow/rendering/lightpathslayer.h
mainwindow/rendering/lightpathspickinghandler.cpp
mainwindow/rendering/lightpathspickinghandler.h
mainwindow/rendering/lightpathsviewportmanager.cpp
mainwindow/rendering/lightpathsviewportmanager.h
mainwindow/rendering/lightpathslayer.cpp
mainwindow/rendering/lightpathslayer.h
mainwindow/rendering/materialdrophandler.cpp
mainwindow/rendering/materialdrophandler.h
mainwindow/rendering/pixelcolortracker.cpp
Expand All @@ -271,12 +271,12 @@ set (mainwindow_rendering_sources
mainwindow/rendering/renderingmanager.cpp
mainwindow/rendering/renderingmanager.h
mainwindow/rendering/renderingtimer.h
mainwindow/rendering/renderregionhandler.cpp
mainwindow/rendering/renderregionhandler.h
mainwindow/rendering/renderlayer.cpp
mainwindow/rendering/renderlayer.h
mainwindow/rendering/scenepickinghandler.cpp
mainwindow/rendering/scenepickinghandler.h
mainwindow/rendering/viewportregionselectionhandler.cpp
mainwindow/rendering/viewportregionselectionhandler.h
mainwindow/rendering/viewporttab.cpp
mainwindow/rendering/viewporttab.h
mainwindow/rendering/viewportwidget.h
Expand Down
14 changes: 7 additions & 7 deletions src/appleseed.studio/mainwindow/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -742,17 +742,17 @@ void MainWindow::update_workspace()
update_pause_resume_checkbox(false);
m_ui->attribute_editor_scrollarea_contents->setEnabled(true);

// Add/remove light paths tab.
// Enable/disable light paths
if (m_project_manager.is_project_open() &&
m_project_manager.get_project()->get_light_path_recorder().get_light_path_count() > 0)
{
for (const_each<ViewportTabCollection> i = m_viewport_tabs; i; ++i)
i->second->enable_light_paths_toggle();
i->second->set_light_paths_enabled(true);
}
else
{
for (const_each<ViewportTabCollection> i = m_viewport_tabs; i; ++i)
i->second->disable_light_paths_toggle();
i->second->set_light_paths_enabled(false);
}
}

Expand Down Expand Up @@ -894,7 +894,7 @@ void MainWindow::set_rendering_widgets_enabled(const bool is_enabled, const Rend
// Rendering -> Render Settings.
m_ui->action_rendering_rendering_settings->setEnabled(allow_start);

// Render tab buttons.
// Viewport tab buttons.
const int current_tab_index = m_ui->tab_render_channels->currentIndex();
if (current_tab_index != -1)
{
Expand Down Expand Up @@ -982,7 +982,8 @@ void MainWindow::add_viewport_tab(const QString& label)
*m_project_explorer,
*m_project_manager.get_project(),
m_rendering_manager,
m_ocio_config);
m_ocio_config,
m_application_settings);

// Connect the render tab to the main window and the rendering manager.
connect(
Expand Down Expand Up @@ -1218,8 +1219,7 @@ void MainWindow::start_rendering(const RenderingMode rendering_mode)
// Darken render widgets.
for (const_each<ViewportTabCollection> i = m_viewport_tabs; i; ++i)
{
i->second->get_viewport_widget()->get_render_layer()->darken();
i->second->update();
i->second->render_began();
}

// Retrieve the appropriate rendering configuration.
Expand Down
7 changes: 1 addition & 6 deletions src/appleseed.studio/mainwindow/rendering/glscenelayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ namespace {
}
}

void GLSceneLayer::initialize(QSurfaceFormat format)
void GLSceneLayer::init_gl(QSurfaceFormat format)
{
// If there was already previous data, clean up
GLSceneLayer::cleanup_gl_data();
Expand Down Expand Up @@ -511,11 +511,6 @@ void GLSceneLayer::initialize(QSurfaceFormat format)
m_initialized = true;
}

bool GLSceneLayer::is_initialized()
{
return m_initialized;
}

void GLSceneLayer::cleanup_gl_data()
{
if (!m_scene_object_vaos.empty())
Expand Down
8 changes: 3 additions & 5 deletions src/appleseed.studio/mainwindow/rendering/glscenelayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,15 @@ class GLSceneLayer
const size_t width,
const size_t height);

void init_gl(
QSurfaceFormat format);

void set_transform(
const foundation::Transformd& transform);

void set_gl_functions(
QOpenGLFunctions_3_3_Core* functions);

void initialize(
QSurfaceFormat format);

bool is_initialized();

void draw();
void draw_depth_only();

Expand Down
48 changes: 33 additions & 15 deletions src/appleseed.studio/mainwindow/rendering/lightpathslayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,17 @@ void LightPathsLayer::set_gl_functions(QOpenGLFunctions_3_3_Core* functions)
m_gl = functions;
}

void LightPathsLayer::update_render_camera_transform()
{
const float time = m_camera.get_shutter_middle_time();
m_render_camera_matrix = m_camera.transform_sequence().evaluate(time).get_parent_to_local();
m_gl_render_view_matrix = transpose(m_render_camera_matrix);
}

void LightPathsLayer::set_transform(const Transformd& transform)
{
m_camera_matrix = transform.get_parent_to_local();
m_gl_view_matrix = transpose(m_camera_matrix);
m_camera_position = Vector3f(m_camera_matrix.extract_translation());
}

void LightPathsLayer::set_light_paths(const LightPathArray& light_paths)
Expand Down Expand Up @@ -365,23 +371,18 @@ void LightPathsLayer::init_gl(QSurfaceFormat format)
// If there was already previous data, clean up
LightPathsLayer::cleanup_gl_data();

bool manual_srgb_conversion = false;
if (format.colorSpace() != QSurfaceFormat::sRGBColorSpace)
{
manual_srgb_conversion = true;
RENDERER_LOG_WARNING(
"opengl: srgb framebuffer extensions not supported, using slower manual conversion.");
}

glEnable(GL_DEPTH_TEST);

glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

auto vertex_shader = load_gl_shader("lightpaths.vert");
auto fragment_shader = load_gl_shader("lightpaths.frag");

create_shader_program(
m_gl,
m_light_paths_shader_program,
load_gl_shader("lightpaths.vert"),
load_gl_shader("lightpaths.frag"));
vertex_shader,
fragment_shader);

m_light_paths_view_mat_location = m_gl->glGetUniformLocation(m_light_paths_shader_program, "u_view");
m_light_paths_proj_mat_location = m_gl->glGetUniformLocation(m_light_paths_shader_program, "u_proj");
Expand Down Expand Up @@ -447,23 +448,40 @@ void LightPathsLayer::cleanup_gl_data()
}
}

void LightPathsLayer::draw()
void LightPathsLayer::draw_render_camera() const
{
auto gl_view_matrix = const_cast<const GLfloat*>(&m_gl_render_view_matrix[0]);
render_scene(gl_view_matrix);
}

void LightPathsLayer::draw() const
{
auto gl_view_matrix = const_cast<const GLfloat*>(&m_gl_view_matrix[0]);
render_scene(gl_view_matrix);
}

void LightPathsLayer::render_scene(const GLfloat* gl_view_matrix) const
{
if (!m_gl_initialized)
return;

if (m_backface_culling_enabled)
glEnable(GL_CULL_FACE);
else glDisable(GL_CULL_FACE);
m_gl->glEnable(GL_CULL_FACE);
else m_gl->glDisable(GL_CULL_FACE);

m_gl->glDepthMask(GL_TRUE);
m_gl->glEnable(GL_DEPTH_TEST);
m_gl->glDepthFunc(GL_LEQUAL);

if (m_light_paths_index_offsets.size() > 1)
{
m_gl->glUseProgram(m_light_paths_shader_program);

m_gl->glUniformMatrix4fv(
m_light_paths_view_mat_location,
1,
false,
const_cast<const GLfloat*>(&m_gl_view_matrix[0]));
gl_view_matrix);
m_gl->glUniformMatrix4fv(
m_light_paths_proj_mat_location,
1,
Expand Down
14 changes: 11 additions & 3 deletions src/appleseed.studio/mainwindow/rendering/lightpathslayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ namespace studio {
// A widget providing an hardware-accelerated visualization of recorded light paths.
//

class LightPathsLayer
class LightPathsLayer: public QObject
{
Q_OBJECT

Expand All @@ -77,6 +77,9 @@ class LightPathsLayer
const size_t width,
const size_t height);


void update_render_camera_transform();

void set_transform(
const foundation::Transformd& transform);

Expand All @@ -91,7 +94,9 @@ class LightPathsLayer

void init_gl(QSurfaceFormat format);

void draw();
void draw() const;

void draw_render_camera() const;

signals:
void signal_light_path_selection_changed(
Expand All @@ -109,7 +114,7 @@ class LightPathsLayer
const renderer::Project& m_project;
renderer::Camera& m_camera;
foundation::Matrix4d m_camera_matrix;
foundation::Vector3f m_camera_position;
foundation::Matrix4d m_render_camera_matrix;

bool m_backface_culling_enabled;

Expand All @@ -124,13 +129,16 @@ class LightPathsLayer
GLuint m_light_paths_shader_program;
GLint m_light_paths_view_mat_location;
GLint m_light_paths_proj_mat_location;
foundation::Matrix4f m_gl_render_view_matrix;
foundation::Matrix4f m_gl_view_matrix;
foundation::Matrix4f m_gl_proj_matrix;
bool m_gl_initialized;

void cleanup_gl_data();
void load_light_paths_data();

void render_scene(const GLfloat* gl_view_matrix) const;

void dump_selected_light_path() const;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
#include "lightpathspickinghandler.h"

// appleseed.studio headers.
#include "mainwindow/rendering/lightpathswidget.h"
#include "mainwindow/rendering/lightpathslayer.h"
#include "mainwindow/rendering/viewportwidget.h"
#include "utility/mousecoordinatestracker.h"

// appleseed.renderer headers.
Expand All @@ -57,20 +58,13 @@ namespace appleseed {
namespace studio {

LightPathsPickingHandler::LightPathsPickingHandler(
LightPathsLayer* light_paths_widget,
ViewportWidget* viewport_widget,
const MouseCoordinatesTracker& mouse_tracker,
const Project& project)
: m_light_paths_widget(light_paths_widget)
, m_mouse_tracker(mouse_tracker)
, m_project(project)
: m_project(project)
, m_enabled(true)
, m_viewport_widget(viewport_widget)
{
m_light_paths_widget->installEventFilter(this);
}

LightPathsPickingHandler::~LightPathsPickingHandler()
{
m_light_paths_widget->removeEventFilter(this);
}

void LightPathsPickingHandler::set_enabled(const bool enabled)
Expand Down Expand Up @@ -108,8 +102,8 @@ void LightPathsPickingHandler::pick(const Vector2i& pixel) const
pixel.y);
}

m_light_paths_widget->set_light_paths(light_paths);
m_light_paths_widget->update();
m_viewport_widget->get_light_paths_layer()->set_light_paths(light_paths);
m_viewport_widget->update();
}
}

Expand Down Expand Up @@ -156,31 +150,10 @@ void LightPathsPickingHandler::pick(const AABB2i& rect) const
final_rect.max.y);
}

m_light_paths_widget->set_light_paths(light_paths);
m_light_paths_widget->update();
m_viewport_widget->get_light_paths_layer()->set_light_paths(light_paths);
m_viewport_widget->update();
}
}

bool LightPathsPickingHandler::eventFilter(QObject* object, QEvent* event)
{
if (m_enabled)
{
if (event->type() == QEvent::MouseButtonPress)
{
const QMouseEvent* mouse_event = static_cast<QMouseEvent*>(event);
if (!(mouse_event->modifiers() & (Qt::AltModifier | Qt::ShiftModifier | Qt::ControlModifier)))
{
if (mouse_event->button() == Qt::LeftButton)
{
pick(m_mouse_tracker.widget_to_pixel(mouse_event->pos()));
return true;
}
}
}
}

return QObject::eventFilter(object, event);
}

} // namespace studio
} // namespace appleseed
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
// Forward declarations.
namespace appleseed { namespace studio { class LightPathsLayer; } }
namespace appleseed { namespace studio { class MouseCoordinatesTracker; } }
namespace appleseed { namespace studio { class ViewportWidget; } }
namespace renderer { class Project; }
class QEvent;

Expand All @@ -51,24 +52,19 @@ class LightPathsPickingHandler

public:
LightPathsPickingHandler(
LightPathsLayer* light_paths_widget,
ViewportWidget* viewport_widget,
const MouseCoordinatesTracker& mouse_tracker,
const renderer::Project& project);

~LightPathsPickingHandler() override;

void set_enabled(const bool enabled);

void pick(const foundation::Vector2i& pixel) const;
void pick(const foundation::AABB2i& rect) const;

private:
LightPathsLayer* m_light_paths_widget;
const MouseCoordinatesTracker& m_mouse_tracker;
ViewportWidget* m_viewport_widget;
const renderer::Project& m_project;
bool m_enabled;

bool eventFilter(QObject* object, QEvent* event) override;
};

} // namespace studio
Expand Down
Loading

0 comments on commit bf27aaf

Please sign in to comment.