diff --git a/resources/shaders/110/gouraud.fs b/resources/shaders/110/gouraud.fs index 0742f6cc88..cf3163fa37 100644 --- a/resources/shaders/110/gouraud.fs +++ b/resources/shaders/110/gouraud.fs @@ -26,8 +26,6 @@ struct SlopeDetection uniform vec4 uniform_color; uniform SlopeDetection slope; -uniform bool offset_depth_buffer; - #ifdef ENABLE_ENVIRONMENT_MAP uniform sampler2D environment_tex; uniform bool use_environment_tex; @@ -78,9 +76,4 @@ void main() else #endif gl_FragColor = vec4(vec3(intensity.y) + color * intensity.x, alpha); - - // In the support painting gizmo and the seam painting gizmo are painted triangles rendered over the already - // rendered object. To resolved z-fighting between previously rendered object and painted triangles, values - // inside the depth buffer are offset by small epsilon for painted triangles inside those gizmos. - gl_FragDepth = gl_FragCoord.z - (offset_depth_buffer ? EPSILON : 0.0); } diff --git a/resources/shaders/140/gouraud.fs b/resources/shaders/140/gouraud.fs index 225b11dbc0..d87e336321 100644 --- a/resources/shaders/140/gouraud.fs +++ b/resources/shaders/140/gouraud.fs @@ -26,8 +26,6 @@ struct SlopeDetection uniform vec4 uniform_color; uniform SlopeDetection slope; -uniform bool offset_depth_buffer; - #ifdef ENABLE_ENVIRONMENT_MAP uniform sampler2D environment_tex; uniform bool use_environment_tex; @@ -80,9 +78,4 @@ void main() else #endif out_color = vec4(vec3(intensity.y) + color * intensity.x, alpha); - - // In the support painting gizmo and the seam painting gizmo are painted triangles rendered over the already - // rendered object. To resolved z-fighting between previously rendered object and painted triangles, values - // inside the depth buffer are offset by small epsilon for painted triangles inside those gizmos. - gl_FragDepth = gl_FragCoord.z - (offset_depth_buffer ? EPSILON : 0.0); } diff --git a/resources/shaders/gouraud.fs b/resources/shaders/gouraud.fs index 511faf4c00..1657fc0513 100644 --- a/resources/shaders/gouraud.fs +++ b/resources/shaders/gouraud.fs @@ -26,8 +26,6 @@ struct SlopeDetection uniform vec4 uniform_color; uniform SlopeDetection slope; -uniform bool offset_depth_buffer; - #ifdef ENABLE_ENVIRONMENT_MAP uniform sampler2D environment_tex; uniform bool use_environment_tex; @@ -78,9 +76,4 @@ void main() else #endif gl_FragColor = vec4(vec3(intensity.y) + color * intensity.x, alpha); - - // In the support painting gizmo and the seam painting gizmo are painted triangles rendered over the already - // rendered object. To resolved z-fighting between previously rendered object and painted triangles, values - // inside the depth buffer are offset by small epsilon for painted triangles inside those gizmos. - gl_FragDepth = gl_FragCoord.z - (offset_depth_buffer ? EPSILON : 0.0); } diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index fdcc613ace..d104589315 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -5314,7 +5314,7 @@ void GLCanvas3D::_picking_pass() #if !ENABLE_LEGACY_OPENGL_REMOVAL m_camera_clipping_plane = m_gizmos.get_clipping_plane(); if (m_camera_clipping_plane.is_active()) { - ::glClipPlane(GL_CLIP_PLANE0, (GLdouble*)m_camera_clipping_plane.get_data()); + ::glClipPlane(GL_CLIP_PLANE0, (GLdouble*)m_camera_clipping_plane.get_data().data()); ::glEnable(GL_CLIP_PLANE0); } #endif // !ENABLE_LEGACY_OPENGL_REMOVAL diff --git a/src/slic3r/GUI/Gizmos/GLGizmoPainterBase.cpp b/src/slic3r/GUI/Gizmos/GLGizmoPainterBase.cpp index d71495a34f..4005f8bb19 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoPainterBase.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoPainterBase.cpp @@ -947,8 +947,6 @@ void TriangleSelectorGUI::render(ImGuiWrapper* imgui) assert(shader->get_name() == "gouraud"); - ScopeGuard guard([shader]() { if (shader) shader->set_uniform("offset_depth_buffer", false);}); - shader->set_uniform("offset_depth_buffer", true); for (auto iva : {std::make_pair(&m_iva_enforcers, enforcers_color), std::make_pair(&m_iva_blockers, blockers_color)}) { #if ENABLE_LEGACY_OPENGL_REMOVAL @@ -1039,6 +1037,9 @@ void TriangleSelectorGUI::update_render_data() iva.release_geometry(); #endif // ENABLE_LEGACY_OPENGL_REMOVAL + // small value used to offset triangles along their normal to avoid z-fighting + static const float offset = 0.001f; + for (const Triangle &tr : m_triangles) { if (!tr.valid() || tr.is_split() || (tr.get_state() == EnforcerBlockerType::NONE && !tr.is_selected_by_seed_fill())) continue; @@ -1062,15 +1063,17 @@ void TriangleSelectorGUI::update_render_data() //FIXME the normal may likely be pulled from m_triangle_selectors, but it may not be worth the effort // or the current implementation may be more cache friendly. const Vec3f n = (v1 - v0).cross(v2 - v1).normalized(); + // small value used to offset triangles along their normal to avoid z-fighting + const Vec3f offset_n = offset * n; #if ENABLE_LEGACY_OPENGL_REMOVAL - iva.add_vertex(v0, n); - iva.add_vertex(v1, n); - iva.add_vertex(v2, n); + iva.add_vertex(v0 + offset_n, n); + iva.add_vertex(v1 + offset_n, n); + iva.add_vertex(v2 + offset_n, n); iva.add_triangle((unsigned int)cnt, (unsigned int)cnt + 1, (unsigned int)cnt + 2); #else - iva.push_geometry(v0, n); - iva.push_geometry(v1, n); - iva.push_geometry(v2, n); + iva.push_geometry(v0 + offset_n, n); + iva.push_geometry(v1 + offset_n, n); + iva.push_geometry(v2 + offset_n, n); iva.push_triangle(cnt, cnt + 1, cnt + 2); #endif // ENABLE_LEGACY_OPENGL_REMOVAL cnt += 3;