diff --git a/resources/shaders/gouraud_light_uniform.fs b/resources/shaders/gouraud_light_uniform.fs deleted file mode 100644 index 342642bcba..0000000000 --- a/resources/shaders/gouraud_light_uniform.fs +++ /dev/null @@ -1,14 +0,0 @@ -#version 140 - -uniform vec4 uniform_color; -uniform float emission_factor; - -// x = tainted, y = specular; -in vec2 intensity; - -out vec4 out_color; - -void main() -{ - out_color = uniform_color; -} diff --git a/resources/shaders/gouraud_light_uniform.vs b/resources/shaders/gouraud_light_uniform.vs deleted file mode 100644 index fad848f8bd..0000000000 --- a/resources/shaders/gouraud_light_uniform.vs +++ /dev/null @@ -1,45 +0,0 @@ -#version 140 - -#define INTENSITY_CORRECTION 0.6 - -// normalized values for (-0.6/1.31, 0.6/1.31, 1./1.31) -const vec3 LIGHT_TOP_DIR = vec3(-0.4574957, 0.4574957, 0.7624929); -#define LIGHT_TOP_DIFFUSE (0.8 * INTENSITY_CORRECTION) -#define LIGHT_TOP_SPECULAR (0.125 * INTENSITY_CORRECTION) -#define LIGHT_TOP_SHININESS 20.0 - -// normalized values for (1./1.43, 0.2/1.43, 1./1.43) -const vec3 LIGHT_FRONT_DIR = vec3(0.6985074, 0.1397015, 0.6985074); -#define LIGHT_FRONT_DIFFUSE (0.3 * INTENSITY_CORRECTION) - -#define INTENSITY_AMBIENT 0.3 - -uniform mat4 view_model_matrix; -uniform mat4 projection_matrix; -uniform mat3 view_normal_matrix; - -in vec3 v_position; -in vec3 v_normal; - -// x = tainted, y = specular; -out vec2 intensity; - -void main() -{ - // First transform the normal into camera space and normalize the result. - vec3 normal = normalize(view_normal_matrix * v_normal); - - // Compute the cos of the angle between the normal and lights direction. The light is directional so the direction is constant for every vertex. - // Since these two are normalized the cosine is the dot product. We also need to clamp the result to the [0,1] range. - float NdotL = max(dot(normal, LIGHT_TOP_DIR), 0.0); - - intensity.x = INTENSITY_AMBIENT + NdotL * LIGHT_TOP_DIFFUSE; - vec4 position = view_model_matrix * vec4(v_position, 1.0); - intensity.y = LIGHT_TOP_SPECULAR * pow(max(dot(-normalize(position.xyz), reflect(-LIGHT_TOP_DIR, normal)), 0.0), LIGHT_TOP_SHININESS); - - // Perform the same lighting calculation for the 2nd light source (no specular applied). - NdotL = max(dot(normal, LIGHT_FRONT_DIR), 0.0); - intensity.x += NdotL * LIGHT_FRONT_DIFFUSE; - - gl_Position = projection_matrix * position; -} diff --git a/src/slic3r/GUI/GLShadersManager.cpp b/src/slic3r/GUI/GLShadersManager.cpp index 5f8ee9bc9f..c7d1c2647b 100644 --- a/src/slic3r/GUI/GLShadersManager.cpp +++ b/src/slic3r/GUI/GLShadersManager.cpp @@ -45,9 +45,6 @@ std::pair GLShadersManager::init() // used to render extrusion and travel paths as lines in gcode preview valid &= append_shader("toolpaths_lines", { "toolpaths_lines.vs", "toolpaths_lines.fs" }); - // used to render cut connectors - valid &= append_shader("gouraud_light_uniform", {"gouraud_light_uniform.vs", "gouraud_light_uniform.fs"}); - // used to render objects in 3d editor //if (GUI::wxGetApp().is_gl_version_greater_or_equal_to(3, 0)) { if (0) { diff --git a/src/slic3r/GUI/Gizmos/GLGizmoAdvancedCut.cpp b/src/slic3r/GUI/Gizmos/GLGizmoAdvancedCut.cpp index 295d81a851..8b4ab03b90 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoAdvancedCut.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoAdvancedCut.cpp @@ -558,11 +558,11 @@ void GLGizmoAdvancedCut::on_render_for_picking() Transform3d scale_tf = Transform3d::Identity(); scale_tf.scale(Vec3f(connector.radius, connector.radius, height).cast()); - const Transform3d view_model_matrix = camera.get_view_matrix() * translate_tf * m_rotate_matrix * scale_tf; + const Transform3d view_model_matrix = translate_tf * m_rotate_matrix * scale_tf; std::array color = picking_color_component(i+1); - render_connector_model(m_shapes[connectors[i].attribs], color, view_model_matrix); + render_connector_model(m_shapes[connectors[i].attribs], color, view_model_matrix, true); } } @@ -1004,9 +1004,8 @@ void GLGizmoAdvancedCut::render_connectors() Transform3d scale_tf = Transform3d::Identity(); scale_tf.scale(Vec3f(connector.radius, connector.radius, height).cast()); - const Transform3d view_model_matrix = camera.get_view_matrix() * translate_tf * m_rotate_matrix * scale_tf; + const Transform3d view_model_matrix = translate_tf * m_rotate_matrix * scale_tf; - //render_color = {1.f, 0.f, 0.f, 1.f}; render_connector_model(m_shapes[connector.attribs], render_color, view_model_matrix); } } @@ -1032,20 +1031,25 @@ void GLGizmoAdvancedCut::render_cut_line() glDisable(GL_LINE_STIPPLE); } -void GLGizmoAdvancedCut::render_connector_model(GLModel &model, const std::array& color, Transform3d view_model_matrix) +void GLGizmoAdvancedCut::render_connector_model(GLModel &model, const std::array &color, Transform3d view_model_matrix, bool for_picking) { - GLShaderProgram *shader = wxGetApp().get_shader("gouraud_light_uniform"); + glPushMatrix(); + GLShaderProgram *shader = nullptr; + if (for_picking) + shader = wxGetApp().get_shader("cali"); + else + shader = wxGetApp().get_shader("gouraud_light"); if (shader) { shader->start_using(); - shader->set_uniform("view_model_matrix", view_model_matrix); - shader->set_uniform("projection_matrix", wxGetApp().plater()->get_camera().get_projection_matrix()); + glsafe(::glMultMatrixd(view_model_matrix.data())); model.set_color(-1, color); model.render(); shader->stop_using(); } + glPopMatrix(); } void GLGizmoAdvancedCut::clear_selection() diff --git a/src/slic3r/GUI/Gizmos/GLGizmoAdvancedCut.hpp b/src/slic3r/GUI/Gizmos/GLGizmoAdvancedCut.hpp index a2ea836e0e..c27492df1c 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoAdvancedCut.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoAdvancedCut.hpp @@ -200,7 +200,7 @@ private: void render_connectors(); void render_clipper_cut(); void render_cut_line(); - void render_connector_model(GLModel &model, const std::array& color, Transform3d view_model_matrix); + void render_connector_model(GLModel &model, const std::array& color, Transform3d view_model_matrix, bool for_picking = false); void clear_selection(); void init_connector_shapes();