From def87a59c0a774f798e1c1968089f255029917ef Mon Sep 17 00:00:00 2001 From: "zhou.xu" Date: Mon, 24 Apr 2023 17:01:00 +0800 Subject: [PATCH] FIX:The mirrored patch normal vector needs to be reversed Change-Id: I3a67322eb59355ed91d1af390eb34f7f3d378198 (cherry picked from commit 3187f2b7944ddd2b9b6dc621da07dac6d4b3b31f) --- resources/shaders/mm_gouraud.fs | 27 +++++++++----------- src/slic3r/GUI/Gizmos/GLGizmoFdmSupports.cpp | 2 +- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/resources/shaders/mm_gouraud.fs b/resources/shaders/mm_gouraud.fs index 86dc503a4d..4a74d75b56 100644 --- a/resources/shaders/mm_gouraud.fs +++ b/resources/shaders/mm_gouraud.fs @@ -44,27 +44,24 @@ void main() float alpha = uniform_color.a; vec3 triangle_normal = normalize(cross(dFdx(model_pos.xyz), dFdy(model_pos.xyz))); -#ifdef FLIP_TRIANGLE_NORMALS - triangle_normal = -triangle_normal; -#endif - + if (volume_mirrored) + { + triangle_normal = -triangle_normal; + } vec3 transformed_normal = normalize(slope.volume_world_normal_matrix * triangle_normal); + if (slope.actived) { - if(world_pos.z<0.1&&world_pos.z>-0.1) + if(world_pos.z<0.1&&world_pos.z>-0.1) { - color = LightBlue; - alpha = 1.0; + color = LightBlue; + alpha = 1.0; } else if( transformed_normal.z < slope.normal_z - EPSILON) - { - color = color * 0.5 + LightRed * 0.5; - alpha = 1.0; - } + { + color = color * 0.5 + LightRed * 0.5; + alpha = 1.0; + } } - - if (volume_mirrored) - triangle_normal = -triangle_normal; - // First transform the normal into camera space and normalize the result. vec3 eye_normal = normalize(gl_NormalMatrix * triangle_normal); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoFdmSupports.cpp b/src/slic3r/GUI/Gizmos/GLGizmoFdmSupports.cpp index b57ca0a9f8..c095c0915e 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoFdmSupports.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoFdmSupports.cpp @@ -186,7 +186,7 @@ void GLGizmoFdmSupports::render_triangles(const Selection& selection) const shader->set_uniform("volume_world_matrix", trafo_matrix); shader->set_uniform("volume_mirrored", is_left_handed); shader->set_uniform("slope.actived", m_parent.is_using_slope()); - shader->set_uniform("slope.volume_world_normal_matrix", static_cast(trafo_matrix.matrix().block(0, 0, 3, 3).inverse().transpose().cast())); + shader->set_uniform("slope.volume_world_normal_matrix", normal_matrix); shader->set_uniform("slope.normal_z", normal_z); m_triangle_selectors[mesh_id]->render(m_imgui);