Delayed rendering of transparent volumes
This commit is contained in:
parent
18c8003a0f
commit
ef8ddacdfc
6 changed files with 82 additions and 41 deletions
|
@ -68,6 +68,8 @@
|
||||||
#define DISABLE_ALLOW_NEGATIVE_Z_FOR_SLA (1 && ENABLE_ALLOW_NEGATIVE_Z)
|
#define DISABLE_ALLOW_NEGATIVE_Z_FOR_SLA (1 && ENABLE_ALLOW_NEGATIVE_Z)
|
||||||
// Enable visualization of objects clearance for sequential prints
|
// Enable visualization of objects clearance for sequential prints
|
||||||
#define ENABLE_SEQUENTIAL_LIMITS (1 && ENABLE_2_4_0_ALPHA0)
|
#define ENABLE_SEQUENTIAL_LIMITS (1 && ENABLE_2_4_0_ALPHA0)
|
||||||
|
// Enable delayed rendering of transparent volumes
|
||||||
|
#define ENABLE_DELAYED_TRANSPARENT_VOLUMES_RENDERING (1 && ENABLE_2_4_0_ALPHA0)
|
||||||
|
|
||||||
|
|
||||||
#endif // _prusaslicer_technologies_h_
|
#endif // _prusaslicer_technologies_h_
|
||||||
|
|
|
@ -752,17 +752,15 @@ GLVolumeWithIdAndZList volumes_to_render(const GLVolumePtrs& volumes, GLVolumeCo
|
||||||
{
|
{
|
||||||
GLVolume* volume = volumes[i];
|
GLVolume* volume = volumes[i];
|
||||||
bool is_transparent = (volume->render_color[3] < 1.0f);
|
bool is_transparent = (volume->render_color[3] < 1.0f);
|
||||||
if ((((type == GLVolumeCollection::Opaque) && !is_transparent) ||
|
if ((((type == GLVolumeCollection::ERenderType::Opaque) && !is_transparent) ||
|
||||||
((type == GLVolumeCollection::Transparent) && is_transparent) ||
|
((type == GLVolumeCollection::ERenderType::Transparent) && is_transparent) ||
|
||||||
(type == GLVolumeCollection::All)) &&
|
(type == GLVolumeCollection::ERenderType::All)) &&
|
||||||
(! filter_func || filter_func(*volume)))
|
(! filter_func || filter_func(*volume)))
|
||||||
list.emplace_back(std::make_pair(volume, std::make_pair(i, 0.0)));
|
list.emplace_back(std::make_pair(volume, std::make_pair(i, 0.0)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((type == GLVolumeCollection::Transparent) && (list.size() > 1))
|
if (type == GLVolumeCollection::ERenderType::Transparent && list.size() > 1) {
|
||||||
{
|
for (GLVolumeWithIdAndZ& volume : list) {
|
||||||
for (GLVolumeWithIdAndZ& volume : list)
|
|
||||||
{
|
|
||||||
volume.second.second = volume.first->bounding_box().transformed(view_matrix * volume.first->world_matrix()).max(2);
|
volume.second.second = volume.first->bounding_box().transformed(view_matrix * volume.first->world_matrix()).max(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -770,8 +768,7 @@ GLVolumeWithIdAndZList volumes_to_render(const GLVolumePtrs& volumes, GLVolumeCo
|
||||||
[](const GLVolumeWithIdAndZ& v1, const GLVolumeWithIdAndZ& v2) -> bool { return v1.second.second < v2.second.second; }
|
[](const GLVolumeWithIdAndZ& v1, const GLVolumeWithIdAndZ& v2) -> bool { return v1.second.second < v2.second.second; }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else if ((type == GLVolumeCollection::Opaque) && (list.size() > 1))
|
else if (type == GLVolumeCollection::ERenderType::Opaque && list.size() > 1) {
|
||||||
{
|
|
||||||
std::sort(list.begin(), list.end(),
|
std::sort(list.begin(), list.end(),
|
||||||
[](const GLVolumeWithIdAndZ& v1, const GLVolumeWithIdAndZ& v2) -> bool { return v1.first->selected && !v2.first->selected; }
|
[](const GLVolumeWithIdAndZ& v1, const GLVolumeWithIdAndZ& v2) -> bool { return v1.first->selected && !v2.first->selected; }
|
||||||
);
|
);
|
||||||
|
|
|
@ -480,7 +480,7 @@ typedef std::vector<GLVolumeWithIdAndZ> GLVolumeWithIdAndZList;
|
||||||
class GLVolumeCollection
|
class GLVolumeCollection
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum ERenderType : unsigned char
|
enum class ERenderType : unsigned char
|
||||||
{
|
{
|
||||||
Opaque,
|
Opaque,
|
||||||
Transparent,
|
Transparent,
|
||||||
|
|
|
@ -2593,7 +2593,7 @@ void GCodeViewer::render_shells() const
|
||||||
// glsafe(::glDepthMask(GL_FALSE));
|
// glsafe(::glDepthMask(GL_FALSE));
|
||||||
|
|
||||||
shader->start_using();
|
shader->start_using();
|
||||||
m_shells.volumes.render(GLVolumeCollection::Transparent, true, wxGetApp().plater()->get_camera().get_view_matrix());
|
m_shells.volumes.render(GLVolumeCollection::ERenderType::Transparent, true, wxGetApp().plater()->get_camera().get_view_matrix());
|
||||||
shader->stop_using();
|
shader->stop_using();
|
||||||
|
|
||||||
// glsafe(::glDepthMask(GL_TRUE));
|
// glsafe(::glDepthMask(GL_TRUE));
|
||||||
|
|
|
@ -1475,12 +1475,20 @@ void GLCanvas3D::render()
|
||||||
glsafe(::glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
|
glsafe(::glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
|
||||||
_render_background();
|
_render_background();
|
||||||
|
|
||||||
|
#if ENABLE_DELAYED_TRANSPARENT_VOLUMES_RENDERING
|
||||||
|
_render_objects(GLVolumeCollection::ERenderType::Opaque);
|
||||||
|
#else
|
||||||
_render_objects();
|
_render_objects();
|
||||||
|
#endif // ENABLE_DELAYED_TRANSPARENT_VOLUMES_RENDERING
|
||||||
if (!m_main_toolbar.is_enabled())
|
if (!m_main_toolbar.is_enabled())
|
||||||
_render_gcode();
|
_render_gcode();
|
||||||
_render_sla_slices();
|
_render_sla_slices();
|
||||||
_render_selection();
|
_render_selection();
|
||||||
_render_bed(!camera.is_looking_downward(), true);
|
_render_bed(!camera.is_looking_downward(), true);
|
||||||
|
#if ENABLE_DELAYED_TRANSPARENT_VOLUMES_RENDERING
|
||||||
|
_render_objects(GLVolumeCollection::ERenderType::Transparent);
|
||||||
|
#endif // ENABLE_DELAYED_TRANSPARENT_VOLUMES_RENDERING
|
||||||
|
|
||||||
#if ENABLE_SEQUENTIAL_LIMITS
|
#if ENABLE_SEQUENTIAL_LIMITS
|
||||||
_render_sequential_clearance();
|
_render_sequential_clearance();
|
||||||
#endif // ENABLE_SEQUENTIAL_LIMITS
|
#endif // ENABLE_SEQUENTIAL_LIMITS
|
||||||
|
@ -5036,7 +5044,11 @@ void GLCanvas3D::_render_bed(bool bottom, bool show_axes)
|
||||||
wxGetApp().plater()->get_bed().render(*this, bottom, scale_factor, show_axes, show_texture);
|
wxGetApp().plater()->get_bed().render(*this, bottom, scale_factor, show_axes, show_texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if ENABLE_DELAYED_TRANSPARENT_VOLUMES_RENDERING
|
||||||
|
void GLCanvas3D::_render_objects(GLVolumeCollection::ERenderType type)
|
||||||
|
#else
|
||||||
void GLCanvas3D::_render_objects()
|
void GLCanvas3D::_render_objects()
|
||||||
|
#endif // ENABLE_DELAYED_TRANSPARENT_VOLUMES_RENDERING
|
||||||
{
|
{
|
||||||
if (m_volumes.empty())
|
if (m_volumes.empty())
|
||||||
return;
|
return;
|
||||||
|
@ -5067,17 +5079,33 @@ void GLCanvas3D::_render_objects()
|
||||||
if (shader != nullptr) {
|
if (shader != nullptr) {
|
||||||
shader->start_using();
|
shader->start_using();
|
||||||
|
|
||||||
|
#if ENABLE_DELAYED_TRANSPARENT_VOLUMES_RENDERING
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
default:
|
||||||
|
case GLVolumeCollection::ERenderType::Opaque:
|
||||||
|
{
|
||||||
|
#endif // ENABLE_DELAYED_TRANSPARENT_VOLUMES_RENDERING
|
||||||
if (m_picking_enabled && !m_gizmos.is_dragging() && m_layers_editing.is_enabled() && (m_layers_editing.last_object_id != -1) && (m_layers_editing.object_max_z() > 0.0f)) {
|
if (m_picking_enabled && !m_gizmos.is_dragging() && m_layers_editing.is_enabled() && (m_layers_editing.last_object_id != -1) && (m_layers_editing.object_max_z() > 0.0f)) {
|
||||||
int object_id = m_layers_editing.last_object_id;
|
int object_id = m_layers_editing.last_object_id;
|
||||||
m_volumes.render(GLVolumeCollection::Opaque, false, wxGetApp().plater()->get_camera().get_view_matrix(), [object_id](const GLVolume& volume) {
|
#if ENABLE_DELAYED_TRANSPARENT_VOLUMES_RENDERING
|
||||||
|
m_volumes.render(type, false, wxGetApp().plater()->get_camera().get_view_matrix(), [object_id](const GLVolume& volume) {
|
||||||
|
#else
|
||||||
|
m_volumes.render(GLVolumeCollection::ERenderType::Opaque, false, wxGetApp().plater()->get_camera().get_view_matrix(), [object_id](const GLVolume& volume) {
|
||||||
|
#endif // ENABLE_DELAYED_TRANSPARENT_VOLUMES_RENDERING
|
||||||
// Which volume to paint without the layer height profile shader?
|
// Which volume to paint without the layer height profile shader?
|
||||||
return volume.is_active && (volume.is_modifier || volume.composite_id.object_id != object_id);
|
return volume.is_active && (volume.is_modifier || volume.composite_id.object_id != object_id);
|
||||||
});
|
});
|
||||||
// Let LayersEditing handle rendering of the active object using the layer height profile shader.
|
// Let LayersEditing handle rendering of the active object using the layer height profile shader.
|
||||||
m_layers_editing.render_volumes(*this, m_volumes);
|
m_layers_editing.render_volumes(*this, m_volumes);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
// do not cull backfaces to show broken geometry, if any
|
// do not cull backfaces to show broken geometry, if any
|
||||||
m_volumes.render(GLVolumeCollection::Opaque, m_picking_enabled, wxGetApp().plater()->get_camera().get_view_matrix(), [this](const GLVolume& volume) {
|
#if ENABLE_DELAYED_TRANSPARENT_VOLUMES_RENDERING
|
||||||
|
m_volumes.render(type, m_picking_enabled, wxGetApp().plater()->get_camera().get_view_matrix(), [this](const GLVolume& volume) {
|
||||||
|
#else
|
||||||
|
m_volumes.render(GLVolumeCollection::ERenderType::Opaque, m_picking_enabled, wxGetApp().plater()->get_camera().get_view_matrix(), [this](const GLVolume& volume) {
|
||||||
|
#endif // ENABLE_DELAYED_TRANSPARENT_VOLUMES_RENDERING
|
||||||
return (m_render_sla_auxiliaries || volume.composite_id.volume_id >= 0);
|
return (m_render_sla_auxiliaries || volume.composite_id.volume_id >= 0);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -5096,8 +5124,18 @@ void GLCanvas3D::_render_objects()
|
||||||
shader->start_using();
|
shader->start_using();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#if ENABLE_DELAYED_TRANSPARENT_VOLUMES_RENDERING
|
||||||
m_volumes.render(GLVolumeCollection::Transparent, false, wxGetApp().plater()->get_camera().get_view_matrix());
|
break;
|
||||||
|
}
|
||||||
|
case GLVolumeCollection::ERenderType::Transparent:
|
||||||
|
{
|
||||||
|
m_volumes.render(type, false, wxGetApp().plater()->get_camera().get_view_matrix());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
m_volumes.render(GLVolumeCollection::ERenderType::Transparent, false, wxGetApp().plater()->get_camera().get_view_matrix());
|
||||||
|
#endif // ENABLE_DELAYED_TRANSPARENT_VOLUMES_RENDERING
|
||||||
shader->stop_using();
|
shader->stop_using();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5258,7 +5296,7 @@ void GLCanvas3D::_render_volumes_for_picking() const
|
||||||
|
|
||||||
const Transform3d& view_matrix = wxGetApp().plater()->get_camera().get_view_matrix();
|
const Transform3d& view_matrix = wxGetApp().plater()->get_camera().get_view_matrix();
|
||||||
for (size_t type = 0; type < 2; ++ type) {
|
for (size_t type = 0; type < 2; ++ type) {
|
||||||
GLVolumeWithIdAndZList to_render = volumes_to_render(m_volumes.volumes, (type == 0) ? GLVolumeCollection::Opaque : GLVolumeCollection::Transparent, view_matrix);
|
GLVolumeWithIdAndZList to_render = volumes_to_render(m_volumes.volumes, (type == 0) ? GLVolumeCollection::ERenderType::Opaque : GLVolumeCollection::ERenderType::Transparent, view_matrix);
|
||||||
for (const GLVolumeWithIdAndZ& volume : to_render)
|
for (const GLVolumeWithIdAndZ& volume : to_render)
|
||||||
if (!volume.first->disabled && ((volume.first->composite_id.volume_id >= 0) || m_render_sla_auxiliaries)) {
|
if (!volume.first->disabled && ((volume.first->composite_id.volume_id >= 0) || m_render_sla_auxiliaries)) {
|
||||||
// Object picking mode. Render the object with a color encoding the object index.
|
// Object picking mode. Render the object with a color encoding the object index.
|
||||||
|
|
|
@ -822,7 +822,11 @@ private:
|
||||||
void _rectangular_selection_picking_pass();
|
void _rectangular_selection_picking_pass();
|
||||||
void _render_background() const;
|
void _render_background() const;
|
||||||
void _render_bed(bool bottom, bool show_axes);
|
void _render_bed(bool bottom, bool show_axes);
|
||||||
|
#if ENABLE_DELAYED_TRANSPARENT_VOLUMES_RENDERING
|
||||||
|
void _render_objects(GLVolumeCollection::ERenderType type);
|
||||||
|
#else
|
||||||
void _render_objects();
|
void _render_objects();
|
||||||
|
#endif // ENABLE_DELAYED_TRANSPARENT_VOLUMES_RENDERING
|
||||||
void _render_gcode() const;
|
void _render_gcode() const;
|
||||||
void _render_selection() const;
|
void _render_selection() const;
|
||||||
#if ENABLE_SEQUENTIAL_LIMITS
|
#if ENABLE_SEQUENTIAL_LIMITS
|
||||||
|
|
Loading…
Reference in a new issue