From dc3c5db9fe6251306159889ffed1b8ba3035aee5 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Mon, 20 Apr 2020 13:44:14 +0200 Subject: [PATCH] GCodeViewer -> Use rgb instead of rgba colors --- resources/shaders/extrusions.fs | 4 +- resources/shaders/retractions.fs | 4 +- resources/shaders/toolchanges.fs | 4 +- resources/shaders/travels.fs | 4 +- resources/shaders/unretractions.fs | 4 +- src/slic3r/GUI/GCodeViewer.cpp | 82 +++++++++++++++--------------- src/slic3r/GUI/GCodeViewer.hpp | 10 ++-- 7 files changed, 56 insertions(+), 56 deletions(-) diff --git a/resources/shaders/extrusions.fs b/resources/shaders/extrusions.fs index 046dade8a..fc81e487f 100644 --- a/resources/shaders/extrusions.fs +++ b/resources/shaders/extrusions.fs @@ -13,7 +13,7 @@ const vec3 LIGHT_TOP_DIR = vec3(-0.4574957, 0.4574957, 0.7624929); const vec3 LIGHT_FRONT_DIR = vec3(0.0, 0.0, 1.0); #define LIGHT_FRONT_DIFFUSE (0.3 * INTENSITY_CORRECTION) -uniform vec4 uniform_color; +uniform vec3 uniform_color; varying vec3 eye_position; varying vec3 eye_normal; @@ -41,5 +41,5 @@ void main() // if (world_normal_z < 0.0) // intensity.x *= (1.0 + world_normal_z * (1.0 - INTENSITY_AMBIENT)); - gl_FragColor = vec4(vec3(intensity.y, intensity.y, intensity.y) + uniform_color.rgb * intensity.x, uniform_color.a); + gl_FragColor = vec4(vec3(intensity.y, intensity.y, intensity.y) + uniform_color * intensity.x, 1.0); } diff --git a/resources/shaders/retractions.fs b/resources/shaders/retractions.fs index 046dade8a..fc81e487f 100644 --- a/resources/shaders/retractions.fs +++ b/resources/shaders/retractions.fs @@ -13,7 +13,7 @@ const vec3 LIGHT_TOP_DIR = vec3(-0.4574957, 0.4574957, 0.7624929); const vec3 LIGHT_FRONT_DIR = vec3(0.0, 0.0, 1.0); #define LIGHT_FRONT_DIFFUSE (0.3 * INTENSITY_CORRECTION) -uniform vec4 uniform_color; +uniform vec3 uniform_color; varying vec3 eye_position; varying vec3 eye_normal; @@ -41,5 +41,5 @@ void main() // if (world_normal_z < 0.0) // intensity.x *= (1.0 + world_normal_z * (1.0 - INTENSITY_AMBIENT)); - gl_FragColor = vec4(vec3(intensity.y, intensity.y, intensity.y) + uniform_color.rgb * intensity.x, uniform_color.a); + gl_FragColor = vec4(vec3(intensity.y, intensity.y, intensity.y) + uniform_color * intensity.x, 1.0); } diff --git a/resources/shaders/toolchanges.fs b/resources/shaders/toolchanges.fs index 046dade8a..fc81e487f 100644 --- a/resources/shaders/toolchanges.fs +++ b/resources/shaders/toolchanges.fs @@ -13,7 +13,7 @@ const vec3 LIGHT_TOP_DIR = vec3(-0.4574957, 0.4574957, 0.7624929); const vec3 LIGHT_FRONT_DIR = vec3(0.0, 0.0, 1.0); #define LIGHT_FRONT_DIFFUSE (0.3 * INTENSITY_CORRECTION) -uniform vec4 uniform_color; +uniform vec3 uniform_color; varying vec3 eye_position; varying vec3 eye_normal; @@ -41,5 +41,5 @@ void main() // if (world_normal_z < 0.0) // intensity.x *= (1.0 + world_normal_z * (1.0 - INTENSITY_AMBIENT)); - gl_FragColor = vec4(vec3(intensity.y, intensity.y, intensity.y) + uniform_color.rgb * intensity.x, uniform_color.a); + gl_FragColor = vec4(vec3(intensity.y, intensity.y, intensity.y) + uniform_color * intensity.x, 1.0); } diff --git a/resources/shaders/travels.fs b/resources/shaders/travels.fs index 046dade8a..fc81e487f 100644 --- a/resources/shaders/travels.fs +++ b/resources/shaders/travels.fs @@ -13,7 +13,7 @@ const vec3 LIGHT_TOP_DIR = vec3(-0.4574957, 0.4574957, 0.7624929); const vec3 LIGHT_FRONT_DIR = vec3(0.0, 0.0, 1.0); #define LIGHT_FRONT_DIFFUSE (0.3 * INTENSITY_CORRECTION) -uniform vec4 uniform_color; +uniform vec3 uniform_color; varying vec3 eye_position; varying vec3 eye_normal; @@ -41,5 +41,5 @@ void main() // if (world_normal_z < 0.0) // intensity.x *= (1.0 + world_normal_z * (1.0 - INTENSITY_AMBIENT)); - gl_FragColor = vec4(vec3(intensity.y, intensity.y, intensity.y) + uniform_color.rgb * intensity.x, uniform_color.a); + gl_FragColor = vec4(vec3(intensity.y, intensity.y, intensity.y) + uniform_color * intensity.x, 1.0); } diff --git a/resources/shaders/unretractions.fs b/resources/shaders/unretractions.fs index 046dade8a..fc81e487f 100644 --- a/resources/shaders/unretractions.fs +++ b/resources/shaders/unretractions.fs @@ -13,7 +13,7 @@ const vec3 LIGHT_TOP_DIR = vec3(-0.4574957, 0.4574957, 0.7624929); const vec3 LIGHT_FRONT_DIR = vec3(0.0, 0.0, 1.0); #define LIGHT_FRONT_DIFFUSE (0.3 * INTENSITY_CORRECTION) -uniform vec4 uniform_color; +uniform vec3 uniform_color; varying vec3 eye_position; varying vec3 eye_normal; @@ -41,5 +41,5 @@ void main() // if (world_normal_z < 0.0) // intensity.x *= (1.0 + world_normal_z * (1.0 - INTENSITY_AMBIENT)); - gl_FragColor = vec4(vec3(intensity.y, intensity.y, intensity.y) + uniform_color.rgb * intensity.x, uniform_color.a); + gl_FragColor = vec4(vec3(intensity.y, intensity.y, intensity.y) + uniform_color * intensity.x, 1.0); } diff --git a/src/slic3r/GUI/GCodeViewer.cpp b/src/slic3r/GUI/GCodeViewer.cpp index b240d76f5..52d392798 100644 --- a/src/slic3r/GUI/GCodeViewer.cpp +++ b/src/slic3r/GUI/GCodeViewer.cpp @@ -65,7 +65,7 @@ void GCodeViewer::IBuffer::add_path(const GCodeProcessor::MoveVertex& move) paths.push_back({ move.type, move.extrusion_role, id, id, move.height, move.width }); } -std::array GCodeViewer::Extrusions::Range::get_color_at(float value, const std::array, Default_Range_Colors_Count>& colors) const +std::array GCodeViewer::Extrusions::Range::get_color_at(float value, const std::array, Default_Range_Colors_Count>& colors) const { // Input value scaled to the color range const float step = step_size(); @@ -81,43 +81,43 @@ std::array GCodeViewer::Extrusions::Range::get_color_at(float value, c const float local_t = std::min(global_t - static_cast(color_low_idx), 1.0f); // upper limit of 1.0f // Interpolate between the low and high colors in RGB space to find exactly which color the input value should get - std::array ret; - for (unsigned int i = 0; i < 4; ++i) + std::array ret; + for (unsigned int i = 0; i < 3; ++i) { ret[i] = lerp(colors[color_low_idx][i], colors[color_high_idx][i], local_t); } return ret; } -const std::array, erCount> GCodeViewer::Default_Extrusion_Role_Colors {{ - { 1.00f, 1.00f, 1.00f, 1.0f }, // erNone - { 1.00f, 1.00f, 0.40f, 1.0f }, // erPerimeter - { 1.00f, 0.65f, 0.00f, 1.0f }, // erExternalPerimeter - { 0.00f, 0.00f, 1.00f, 1.0f }, // erOverhangPerimeter - { 0.69f, 0.19f, 0.16f, 1.0f }, // erInternalInfill - { 0.84f, 0.20f, 0.84f, 1.0f }, // erSolidInfill - { 1.00f, 0.10f, 0.10f, 1.0f }, // erTopSolidInfill - { 0.60f, 0.60f, 1.00f, 1.0f }, // erBridgeInfill - { 1.00f, 1.00f, 1.00f, 1.0f }, // erGapFill - { 0.52f, 0.48f, 0.13f, 1.0f }, // erSkirt - { 0.00f, 1.00f, 0.00f, 1.0f }, // erSupportMaterial - { 0.00f, 0.50f, 0.00f, 1.0f }, // erSupportMaterialInterface - { 0.70f, 0.89f, 0.67f, 1.0f }, // erWipeTower - { 0.16f, 0.80f, 0.58f, 1.0f }, // erCustom - { 0.00f, 0.00f, 0.00f, 1.0f } // erMixed +const std::array, erCount> GCodeViewer::Default_Extrusion_Role_Colors {{ + { 1.00f, 1.00f, 1.00f }, // erNone + { 1.00f, 1.00f, 0.40f }, // erPerimeter + { 1.00f, 0.65f, 0.00f }, // erExternalPerimeter + { 0.00f, 0.00f, 1.00f }, // erOverhangPerimeter + { 0.69f, 0.19f, 0.16f }, // erInternalInfill + { 0.84f, 0.20f, 0.84f }, // erSolidInfill + { 1.00f, 0.10f, 0.10f }, // erTopSolidInfill + { 0.60f, 0.60f, 1.00f }, // erBridgeInfill + { 1.00f, 1.00f, 1.00f }, // erGapFill + { 0.52f, 0.48f, 0.13f }, // erSkirt + { 0.00f, 1.00f, 0.00f }, // erSupportMaterial + { 0.00f, 0.50f, 0.00f }, // erSupportMaterialInterface + { 0.70f, 0.89f, 0.67f }, // erWipeTower + { 0.16f, 0.80f, 0.58f }, // erCustom + { 0.00f, 0.00f, 0.00f } // erMixed }}; -const std::array, GCodeViewer::Default_Range_Colors_Count> GCodeViewer::Default_Range_Colors {{ - { 0.043f, 0.173f, 0.478f, 1.0f }, - { 0.075f, 0.349f, 0.522f, 1.0f }, - { 0.110f, 0.533f, 0.569f, 1.0f }, - { 0.016f, 0.839f, 0.059f, 1.0f }, - { 0.667f, 0.949f, 0.000f, 1.0f }, - { 0.988f, 0.975f, 0.012f, 1.0f }, - { 0.961f, 0.808f, 0.039f, 1.0f }, - { 0.890f, 0.533f, 0.125f, 1.0f }, - { 0.820f, 0.408f, 0.188f, 1.0f }, - { 0.761f, 0.322f, 0.235f, 1.0f } +const std::array, GCodeViewer::Default_Range_Colors_Count> GCodeViewer::Default_Range_Colors {{ + { 0.043f, 0.173f, 0.478f }, + { 0.075f, 0.349f, 0.522f }, + { 0.110f, 0.533f, 0.569f }, + { 0.016f, 0.839f, 0.059f }, + { 0.667f, 0.949f, 0.000f }, + { 0.988f, 0.975f, 0.012f }, + { 0.961f, 0.808f, 0.039f }, + { 0.890f, 0.533f, 0.125f }, + { 0.820f, 0.408f, 0.188f }, + { 0.761f, 0.322f, 0.235f } }}; void GCodeViewer::load(const GCodeProcessor::Result& gcode_result, const Print& print, bool initialized) @@ -410,7 +410,7 @@ void GCodeViewer::load_shells(const Print& print, bool initialized) void GCodeViewer::render_toolpaths() const { auto extrusion_color = [this](const Path& path) { - std::array color; + std::array color; switch (m_view_type) { case EViewType::FeatureType: { color = m_extrusions.role_colors[static_cast(path.role)]; break; } @@ -423,18 +423,18 @@ void GCodeViewer::render_toolpaths() const case EViewType::ColorPrint: default: { - color = { 1.0f, 1.0f, 1.0f, 1.0f }; + color = { 1.0f, 1.0f, 1.0f }; break; } } return color; }; - auto set_color = [](GLint current_program_id, const std::array& color) { + auto set_color = [](GLint current_program_id, const std::array& color) { if (current_program_id > 0) { GLint color_id = (current_program_id > 0) ? ::glGetUniformLocation(current_program_id, "uniform_color") : -1; if (color_id >= 0) { - glsafe(::glUniform4fv(color_id, 1, (const GLfloat*)color.data())); + glsafe(::glUniform3fv(color_id, 1, (const GLfloat*)color.data())); return; } } @@ -478,7 +478,7 @@ void GCodeViewer::render_toolpaths() const { case GCodeProcessor::EMoveType::Tool_change: { - std::array color = { 1.0f, 1.0f, 1.0f, 1.0f }; + std::array color = { 1.0f, 1.0f, 1.0f }; set_color(current_program_id, color); glsafe(::glEnable(GL_PROGRAM_POINT_SIZE)); glsafe(::glDrawElements(GL_POINTS, (GLsizei)buffer.data_size, GL_UNSIGNED_INT, nullptr)); @@ -487,7 +487,7 @@ void GCodeViewer::render_toolpaths() const } case GCodeProcessor::EMoveType::Retract: { - std::array color = { 1.0f, 0.0f, 1.0f, 1.0f }; + std::array color = { 1.0f, 0.0f, 1.0f }; set_color(current_program_id, color); glsafe(::glEnable(GL_PROGRAM_POINT_SIZE)); glsafe(::glDrawElements(GL_POINTS, (GLsizei)buffer.data_size, GL_UNSIGNED_INT, nullptr)); @@ -496,7 +496,7 @@ void GCodeViewer::render_toolpaths() const } case GCodeProcessor::EMoveType::Unretract: { - std::array color = { 0.0f, 1.0f, 0.0f, 1.0f }; + std::array color = { 0.0f, 1.0f, 0.0f }; set_color(current_program_id, color); glsafe(::glEnable(GL_PROGRAM_POINT_SIZE)); glsafe(::glDrawElements(GL_POINTS, (GLsizei)buffer.data_size, GL_UNSIGNED_INT, nullptr)); @@ -517,7 +517,7 @@ void GCodeViewer::render_toolpaths() const } case GCodeProcessor::EMoveType::Travel: { - std::array color = { 1.0f, 1.0f, 0.0f, 1.0f }; + std::array color = { 1.0f, 1.0f, 0.0f }; set_color(current_program_id, color); for (const Path& path : buffer.paths) { @@ -572,8 +572,8 @@ void GCodeViewer::render_overlay() const auto add_item = [this, draw_list, &imgui](int i, float value) { ImVec2 pos(ImGui::GetCursorPosX() + 2.0f, ImGui::GetCursorPosY() + 2.0f); draw_list->AddRect(ImVec2(pos.x, pos.y), ImVec2(pos.x + ICON_BORDER_SIZE, pos.y + ICON_BORDER_SIZE), ICON_BORDER_COLOR, 0.0f, 0); - const std::array& color = m_extrusions.ranges.colors[i]; - ImU32 fill_color = ImGui::GetColorU32(ImVec4(color[0], color[1], color[2], color[3])); + const std::array& color = m_extrusions.ranges.colors[i]; + ImU32 fill_color = ImGui::GetColorU32(ImVec4(color[0], color[1], color[2], 1.0f)); draw_list->AddRectFilled(ImVec2(pos.x + 1.0f, pos.y + 1.0f), ImVec2(pos.x + ICON_BORDER_SIZE - 1.0f, pos.y + ICON_BORDER_SIZE - 1.0f), fill_color); ImGui::SetCursorPosX(pos.x + ICON_BORDER_SIZE + GAP_ICON_TEXT); ImGui::AlignTextToFramePadding(); @@ -618,7 +618,7 @@ void GCodeViewer::render_overlay() const { ImVec2 pos(ImGui::GetCursorPosX() + 2.0f, ImGui::GetCursorPosY() + 2.0f); draw_list->AddRect(ImVec2(pos.x, pos.y), ImVec2(pos.x + ICON_BORDER_SIZE, pos.y + ICON_BORDER_SIZE), ICON_BORDER_COLOR, 0.0f, 0); - const std::array& color = m_extrusions.role_colors[static_cast(role)]; + const std::array& color = m_extrusions.role_colors[static_cast(role)]; ImU32 fill_color = ImGui::GetColorU32(ImVec4(color[0], color[1], color[2], color[3])); draw_list->AddRectFilled(ImVec2(pos.x + 1.0f, pos.y + 1.0f), ImVec2(pos.x + ICON_BORDER_SIZE - 1.0f, pos.y + ICON_BORDER_SIZE - 1.0f), fill_color); ImGui::SetCursorPosX(pos.x + ICON_BORDER_SIZE + GAP_ICON_TEXT); diff --git a/src/slic3r/GUI/GCodeViewer.hpp b/src/slic3r/GUI/GCodeViewer.hpp index 342f3ba90..39361050b 100644 --- a/src/slic3r/GUI/GCodeViewer.hpp +++ b/src/slic3r/GUI/GCodeViewer.hpp @@ -15,9 +15,9 @@ namespace GUI { class GCodeViewer { - static const std::array, erCount> Default_Extrusion_Role_Colors; + static const std::array, erCount> Default_Extrusion_Role_Colors; static const size_t Default_Range_Colors_Count = 10; - static const std::array, Default_Range_Colors_Count> Default_Range_Colors; + static const std::array, Default_Range_Colors_Count> Default_Range_Colors; // buffer containing vertices data struct VBuffer @@ -93,12 +93,12 @@ class GCodeViewer } float step_size() const { return (max - min) / (static_cast(Default_Range_Colors_Count) - 1.0f); } - std::array get_color_at(float value, const std::array, Default_Range_Colors_Count>& colors) const; + std::array get_color_at(float value, const std::array, Default_Range_Colors_Count>& colors) const; }; struct Ranges { - std::array, Default_Range_Colors_Count> colors; + std::array, Default_Range_Colors_Count> colors; // Color mapping by layer height. Range height; @@ -117,7 +117,7 @@ class GCodeViewer } }; - std::array, erCount> role_colors; + std::array, erCount> role_colors; unsigned int role_visibility_flags{ 0 }; Ranges ranges;