Improved transparent volumes rendering set as default

This commit is contained in:
Enrico Turri 2019-01-21 12:53:01 +01:00
parent 012c681e67
commit db1428dcae
4 changed files with 2 additions and 81 deletions

View file

@ -9,6 +9,8 @@
#define ENABLE_SHOW_CAMERA_TARGET 0 #define ENABLE_SHOW_CAMERA_TARGET 0
// Log debug messages to console when changing selection // Log debug messages to console when changing selection
#define ENABLE_SELECTION_DEBUG_OUTPUT 0 #define ENABLE_SELECTION_DEBUG_OUTPUT 0
// Renders a small sphere in the center of the bounding box of the current selection when no gizmo is active
#define ENABLE_RENDER_SELECTION_CENTER 0
//==================== //====================
// 1.42.0.alpha1 techs // 1.42.0.alpha1 techs
@ -24,10 +26,6 @@
#define ENABLE_SLA_SUPPORT_GIZMO_MOD (1 && ENABLE_1_42_0_ALPHA1) #define ENABLE_SLA_SUPPORT_GIZMO_MOD (1 && ENABLE_1_42_0_ALPHA1)
// Use wxDataViewRender instead of wxDataViewCustomRenderer // Use wxDataViewRender instead of wxDataViewCustomRenderer
#define ENABLE_NONCUSTOM_DATA_VIEW_RENDERING (0 && ENABLE_1_42_0_ALPHA1) #define ENABLE_NONCUSTOM_DATA_VIEW_RENDERING (0 && ENABLE_1_42_0_ALPHA1)
// Renders a small sphere in the center of the bounding box of the current selection when no gizmo is active
#define ENABLE_RENDER_SELECTION_CENTER (0 && ENABLE_1_42_0_ALPHA1)
// Separate rendering for opaque and transparent volumes
#define ENABLE_IMPROVED_TRANSPARENT_VOLUMES_RENDERING (1 && ENABLE_1_42_0_ALPHA1)
//==================== //====================
// 1.42.0.alpha2 techs // 1.42.0.alpha2 techs

View file

@ -541,9 +541,7 @@ int GLVolumeCollection::load_object_volume(
color[2] = 1.0f; color[2] = 1.0f;
} }
color[3] = model_volume->is_model_part() ? 1.f : 0.5f; */ color[3] = model_volume->is_model_part() ? 1.f : 0.5f; */
#if ENABLE_IMPROVED_TRANSPARENT_VOLUMES_RENDERING
color[3] = model_volume->is_model_part() ? 1.f : 0.5f; color[3] = model_volume->is_model_part() ? 1.f : 0.5f;
#endif // ENABLE_IMPROVED_TRANSPARENT_VOLUMES_RENDERING
this->volumes.emplace_back(new GLVolume(color)); this->volumes.emplace_back(new GLVolume(color));
GLVolume &v = *this->volumes.back(); GLVolume &v = *this->volumes.back();
v.set_color_from_model_volume(model_volume); v.set_color_from_model_volume(model_volume);
@ -687,7 +685,6 @@ int GLVolumeCollection::load_wipe_tower_preview(
return int(this->volumes.size() - 1); return int(this->volumes.size() - 1);
} }
#if ENABLE_IMPROVED_TRANSPARENT_VOLUMES_RENDERING
typedef std::pair<GLVolume*, double> GLVolumeWithZ; typedef std::pair<GLVolume*, double> GLVolumeWithZ;
typedef std::vector<GLVolumeWithZ> GLVolumesWithZList; typedef std::vector<GLVolumeWithZ> GLVolumesWithZList;
static GLVolumesWithZList volumes_to_render(const GLVolumePtrs& volumes, GLVolumeCollection::ERenderType type, std::function<bool(const GLVolume&)> filter_func) static GLVolumesWithZList volumes_to_render(const GLVolumePtrs& volumes, GLVolumeCollection::ERenderType type, std::function<bool(const GLVolume&)> filter_func)
@ -724,18 +721,13 @@ static GLVolumesWithZList volumes_to_render(const GLVolumePtrs& volumes, GLVolum
} }
void GLVolumeCollection::render_VBOs(GLVolumeCollection::ERenderType type, bool disable_cullface, std::function<bool(const GLVolume&)> filter_func) const void GLVolumeCollection::render_VBOs(GLVolumeCollection::ERenderType type, bool disable_cullface, std::function<bool(const GLVolume&)> filter_func) const
#else
void GLVolumeCollection::render_VBOs() const
#endif // ENABLE_IMPROVED_TRANSPARENT_VOLUMES_RENDERING
{ {
::glEnable(GL_BLEND); ::glEnable(GL_BLEND);
::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); ::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
::glCullFace(GL_BACK); ::glCullFace(GL_BACK);
#if ENABLE_IMPROVED_TRANSPARENT_VOLUMES_RENDERING
if (disable_cullface) if (disable_cullface)
::glDisable(GL_CULL_FACE); ::glDisable(GL_CULL_FACE);
#endif // ENABLE_IMPROVED_TRANSPARENT_VOLUMES_RENDERING
::glEnableClientState(GL_VERTEX_ARRAY); ::glEnableClientState(GL_VERTEX_ARRAY);
::glEnableClientState(GL_NORMAL_ARRAY); ::glEnableClientState(GL_NORMAL_ARRAY);
@ -758,19 +750,11 @@ void GLVolumeCollection::render_VBOs() const
if (z_range_id != -1) if (z_range_id != -1)
::glUniform2fv(z_range_id, 1, (const GLfloat*)z_range); ::glUniform2fv(z_range_id, 1, (const GLfloat*)z_range);
#if ENABLE_IMPROVED_TRANSPARENT_VOLUMES_RENDERING
GLVolumesWithZList to_render = volumes_to_render(this->volumes, type, filter_func); GLVolumesWithZList to_render = volumes_to_render(this->volumes, type, filter_func);
for (GLVolumeWithZ& volume : to_render) { for (GLVolumeWithZ& volume : to_render) {
volume.first->set_render_color(); volume.first->set_render_color();
volume.first->render_VBOs(color_id, print_box_detection_id, print_box_worldmatrix_id); volume.first->render_VBOs(color_id, print_box_detection_id, print_box_worldmatrix_id);
} }
#else
for (GLVolume *volume : this->volumes)
if (! filter_func || filter_func(*volume)) {
volume->set_render_color();
volume->render_VBOs(color_id, print_box_detection_id, print_box_worldmatrix_id);
}
#endif // ENABLE_IMPROVED_TRANSPARENT_VOLUMES_RENDERING
::glBindBuffer(GL_ARRAY_BUFFER, 0); ::glBindBuffer(GL_ARRAY_BUFFER, 0);
::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); ::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
@ -778,54 +762,36 @@ void GLVolumeCollection::render_VBOs() const
::glDisableClientState(GL_VERTEX_ARRAY); ::glDisableClientState(GL_VERTEX_ARRAY);
::glDisableClientState(GL_NORMAL_ARRAY); ::glDisableClientState(GL_NORMAL_ARRAY);
#if ENABLE_IMPROVED_TRANSPARENT_VOLUMES_RENDERING
if (disable_cullface) if (disable_cullface)
::glEnable(GL_CULL_FACE); ::glEnable(GL_CULL_FACE);
#endif // ENABLE_IMPROVED_TRANSPARENT_VOLUMES_RENDERING
::glDisable(GL_BLEND); ::glDisable(GL_BLEND);
} }
#if ENABLE_IMPROVED_TRANSPARENT_VOLUMES_RENDERING
void GLVolumeCollection::render_legacy(ERenderType type, bool disable_cullface) const void GLVolumeCollection::render_legacy(ERenderType type, bool disable_cullface) const
#else
void GLVolumeCollection::render_legacy() const
#endif // ENABLE_IMPROVED_TRANSPARENT_VOLUMES_RENDERING
{ {
glEnable(GL_BLEND); glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glCullFace(GL_BACK); glCullFace(GL_BACK);
#if ENABLE_IMPROVED_TRANSPARENT_VOLUMES_RENDERING
if (disable_cullface) if (disable_cullface)
::glDisable(GL_CULL_FACE); ::glDisable(GL_CULL_FACE);
#endif // ENABLE_IMPROVED_TRANSPARENT_VOLUMES_RENDERING
glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY); glEnableClientState(GL_NORMAL_ARRAY);
#if ENABLE_IMPROVED_TRANSPARENT_VOLUMES_RENDERING
GLVolumesWithZList to_render = volumes_to_render(this->volumes, type, std::function<bool(const GLVolume&)>()); GLVolumesWithZList to_render = volumes_to_render(this->volumes, type, std::function<bool(const GLVolume&)>());
for (GLVolumeWithZ& volume : to_render) for (GLVolumeWithZ& volume : to_render)
{ {
volume.first->set_render_color(); volume.first->set_render_color();
volume.first->render_legacy(); volume.first->render_legacy();
} }
#else
for (GLVolume *volume : this->volumes)
{
volume->set_render_color();
volume->render_legacy();
}
#endif // ENABLE_IMPROVED_TRANSPARENT_VOLUMES_RENDERING
glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY); glDisableClientState(GL_NORMAL_ARRAY);
#if ENABLE_IMPROVED_TRANSPARENT_VOLUMES_RENDERING
if (disable_cullface) if (disable_cullface)
::glEnable(GL_CULL_FACE); ::glEnable(GL_CULL_FACE);
#endif // ENABLE_IMPROVED_TRANSPARENT_VOLUMES_RENDERING
glDisable(GL_BLEND); glDisable(GL_BLEND);
} }

View file

@ -388,7 +388,6 @@ typedef std::vector<GLVolume*> GLVolumePtrs;
class GLVolumeCollection class GLVolumeCollection
{ {
#if ENABLE_IMPROVED_TRANSPARENT_VOLUMES_RENDERING
public: public:
enum ERenderType : unsigned char enum ERenderType : unsigned char
{ {
@ -398,7 +397,6 @@ public:
}; };
private: private:
#endif // ENABLE_IMPROVED_TRANSPARENT_VOLUMES_RENDERING
// min and max vertex of the print box volume // min and max vertex of the print box volume
float print_box_min[3]; float print_box_min[3];
float print_box_max[3]; float print_box_max[3];
@ -442,13 +440,8 @@ public:
int obj_idx, float pos_x, float pos_y, float width, float depth, float height, float rotation_angle, bool use_VBOs, bool size_unknown, float brim_width); int obj_idx, float pos_x, float pos_y, float width, float depth, float height, float rotation_angle, bool use_VBOs, bool size_unknown, float brim_width);
// Render the volumes by OpenGL. // Render the volumes by OpenGL.
#if ENABLE_IMPROVED_TRANSPARENT_VOLUMES_RENDERING
void render_VBOs(ERenderType type, bool disable_cullface, std::function<bool(const GLVolume&)> filter_func = std::function<bool(const GLVolume&)>()) const; void render_VBOs(ERenderType type, bool disable_cullface, std::function<bool(const GLVolume&)> filter_func = std::function<bool(const GLVolume&)>()) const;
void render_legacy(ERenderType type, bool disable_cullface) const; void render_legacy(ERenderType type, bool disable_cullface) const;
#else
void render_VBOs() const;
void render_legacy() const;
#endif // ENABLE_IMPROVED_TRANSPARENT_VOLUMES_RENDERING
// Finalize the initialization of the geometry & indices, // Finalize the initialization of the geometry & indices,
// upload the geometry and indices to OpenGL VBO objects // upload the geometry and indices to OpenGL VBO objects

View file

@ -4275,13 +4275,9 @@ void GLCanvas3D::render()
::glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); ::glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
_render_background(); _render_background();
#if ENABLE_IMPROVED_TRANSPARENT_VOLUMES_RENDERING
// textured bed needs to be rendered after objects if the texture is transparent // textured bed needs to be rendered after objects if the texture is transparent
bool early_bed_render = is_custom_bed || (theta <= 90.0f); bool early_bed_render = is_custom_bed || (theta <= 90.0f);
if (early_bed_render) if (early_bed_render)
#else
if (is_custom_bed) // untextured bed needs to be rendered before objects
#endif // ENABLE_IMPROVED_TRANSPARENT_VOLUMES_RENDERING
_render_bed(theta); _render_bed(theta);
_render_objects(); _render_objects();
@ -4290,11 +4286,7 @@ void GLCanvas3D::render()
_render_axes(); _render_axes();
#if ENABLE_IMPROVED_TRANSPARENT_VOLUMES_RENDERING
if (!early_bed_render) if (!early_bed_render)
#else
if (!is_custom_bed) // textured bed needs to be rendered after objects
#endif // ENABLE_IMPROVED_TRANSPARENT_VOLUMES_RENDERING
_render_bed(theta); _render_bed(theta);
#if ENABLE_RENDER_SELECTION_CENTER #if ENABLE_RENDER_SELECTION_CENTER
@ -6224,10 +6216,6 @@ void GLCanvas3D::_render_objects() const
m_volumes.set_print_box((float)bed_bb.min(0), (float)bed_bb.min(1), 0.0f, (float)bed_bb.max(0), (float)bed_bb.max(1), (float)m_config->opt_float("max_print_height")); m_volumes.set_print_box((float)bed_bb.min(0), (float)bed_bb.min(1), 0.0f, (float)bed_bb.max(0), (float)bed_bb.max(1), (float)m_config->opt_float("max_print_height"));
m_volumes.check_outside_state(m_config, nullptr); m_volumes.check_outside_state(m_config, nullptr);
} }
#if !ENABLE_IMPROVED_TRANSPARENT_VOLUMES_RENDERING
// do not cull backfaces to show broken geometry, if any
::glDisable(GL_CULL_FACE);
#endif // !ENABLE_IMPROVED_TRANSPARENT_VOLUMES_RENDERING
} }
if (m_use_clipping_planes) if (m_use_clipping_planes)
@ -6236,7 +6224,6 @@ void GLCanvas3D::_render_objects() const
m_volumes.set_z_range(-FLT_MAX, FLT_MAX); m_volumes.set_z_range(-FLT_MAX, FLT_MAX);
m_shader.start_using(); m_shader.start_using();
#if ENABLE_IMPROVED_TRANSPARENT_VOLUMES_RENDERING
if (m_picking_enabled && m_layers_editing.is_enabled() && m_layers_editing.last_object_id != -1) { if (m_picking_enabled && m_layers_editing.is_enabled() && m_layers_editing.last_object_id != -1) {
int object_id = m_layers_editing.last_object_id; int object_id = m_layers_editing.last_object_id;
m_volumes.render_VBOs(GLVolumeCollection::Opaque, false, [object_id](const GLVolume &volume) { m_volumes.render_VBOs(GLVolumeCollection::Opaque, false, [object_id](const GLVolume &volume) {
@ -6250,15 +6237,7 @@ void GLCanvas3D::_render_objects() const
m_volumes.render_VBOs(GLVolumeCollection::Opaque, m_picking_enabled); m_volumes.render_VBOs(GLVolumeCollection::Opaque, m_picking_enabled);
} }
m_volumes.render_VBOs(GLVolumeCollection::Transparent, false); m_volumes.render_VBOs(GLVolumeCollection::Transparent, false);
#else
m_volumes.render_VBOs();
#endif // ENABLE_IMPROVED_TRANSPARENT_VOLUMES_RENDERING
m_shader.stop_using(); m_shader.stop_using();
#if !ENABLE_IMPROVED_TRANSPARENT_VOLUMES_RENDERING
if (m_picking_enabled)
::glEnable(GL_CULL_FACE);
#endif // !ENABLE_IMPROVED_TRANSPARENT_VOLUMES_RENDERING
} }
else else
{ {
@ -6270,24 +6249,9 @@ void GLCanvas3D::_render_objects() const
::glEnable(GL_CLIP_PLANE1); ::glEnable(GL_CLIP_PLANE1);
} }
#if !ENABLE_IMPROVED_TRANSPARENT_VOLUMES_RENDERING
// do not cull backfaces to show broken geometry, if any
if (m_picking_enabled)
::glDisable(GL_CULL_FACE);
#endif // !ENABLE_IMPROVED_TRANSPARENT_VOLUMES_RENDERING
#if ENABLE_IMPROVED_TRANSPARENT_VOLUMES_RENDERING
// do not cull backfaces to show broken geometry, if any // do not cull backfaces to show broken geometry, if any
m_volumes.render_legacy(GLVolumeCollection::Opaque, m_picking_enabled); m_volumes.render_legacy(GLVolumeCollection::Opaque, m_picking_enabled);
m_volumes.render_legacy(GLVolumeCollection::Transparent, false); m_volumes.render_legacy(GLVolumeCollection::Transparent, false);
#else
m_volumes.render_legacy();
#endif // ENABLE_IMPROVED_TRANSPARENT_VOLUMES_RENDERING
#if !ENABLE_IMPROVED_TRANSPARENT_VOLUMES_RENDERING
if (m_picking_enabled)
::glEnable(GL_CULL_FACE);
#endif // !ENABLE_IMPROVED_TRANSPARENT_VOLUMES_RENDERING
if (m_use_clipping_planes) if (m_use_clipping_planes)
{ {