From 95e4ab94609d854f733623349b427ee3781ce364 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Hejl?= Date: Thu, 26 Aug 2021 12:04:57 +0200 Subject: [PATCH 1/2] Fixed the issue that an object disappeared in a multi-material painting gizmo when the object was almost completely sunk under the bed. Object disappearance was caused by calling glPolygonOffset for rendered triangles in the multi-material painting gizmo to resolve z-fighting between painted triangles and contours around selected areas using seed/bucket fill. --- resources/shaders/mm_contour.fs | 5 +++++ src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.cpp | 8 ++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/resources/shaders/mm_contour.fs b/resources/shaders/mm_contour.fs index 14c18dcf1..8ccf5b832 100644 --- a/resources/shaders/mm_contour.fs +++ b/resources/shaders/mm_contour.fs @@ -1,6 +1,11 @@ #version 110 +const float EPSILON = 0.0001; + void main() { gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0); + // Values inside depth buffer for fragments of the contour of a selected area are offset + // by small epsilon to solve z-fighting between painted triangles and contour lines. + gl_FragDepth = gl_FragCoord.z - EPSILON; } diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.cpp index 3d8be9eff..a69319d3b 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.cpp @@ -630,7 +630,11 @@ void TriangleSelectorMmGui::render(ImGuiWrapper *imgui) auto *contour_shader = wxGetApp().get_shader("mm_contour"); contour_shader->start_using(); + + glsafe(::glDepthFunc(GL_LEQUAL)); m_gizmo_scene.render_contour(); + glsafe(::glDepthFunc(GL_LESS)); + contour_shader->stop_using(); } @@ -725,10 +729,6 @@ void GLMmSegmentationGizmo3DScene::render(size_t triangle_indices_idx) const assert(this->vertices_VBO_id != 0); assert(this->triangle_indices_VBO_ids[triangle_indices_idx] != 0); - ScopeGuard offset_fill_guard([]() { glsafe(::glDisable(GL_POLYGON_OFFSET_FILL)); }); - glsafe(::glEnable(GL_POLYGON_OFFSET_FILL)); - glsafe(::glPolygonOffset(5.0, 5.0)); - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, this->vertices_VBO_id)); glsafe(::glVertexPointer(3, GL_FLOAT, 3 * sizeof(float), (const void*)(0 * sizeof(float)))); From 9cffbc929ef5be72741b0698ee58cb40bed74a9d Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Thu, 26 Aug 2021 13:39:22 +0200 Subject: [PATCH 2/2] Fix unsliced objects when their dimensions are close to bed limits fixes #6823 --- src/slic3r/GUI/Plater.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 1841220d5..d315e7734 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -2915,6 +2915,7 @@ void Plater::priv::update_print_volume_state() BoundingBox bed_box_2D = get_extents(Polygon::new_scale(this->config->opt("bed_shape")->values)); BoundingBoxf3 print_volume(unscale(bed_box_2D.min(0), bed_box_2D.min(1), 0.0), unscale(bed_box_2D.max(0), bed_box_2D.max(1), scale_(this->config->opt_float("max_print_height")))); // Allow the objects to protrude below the print bed, only the part of the object above the print bed will be sliced. + print_volume.offset(BedEpsilon); print_volume.min(2) = -1e10; this->q->model().update_print_volume_state(print_volume); }