From 566bb7041a9444a9b14616d172dee061a7db616f Mon Sep 17 00:00:00 2001 From: bubnikv Date: Fri, 12 Apr 2019 11:01:53 +0200 Subject: [PATCH 1/2] Optimization of the OpenGL shaders for clipping with clipping planes. --- resources/shaders/gouraud.fs | 15 +++------------ resources/shaders/gouraud.vs | 16 ++++++++++++---- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/resources/shaders/gouraud.fs b/resources/shaders/gouraud.fs index b2bc915ab..09003f407 100644 --- a/resources/shaders/gouraud.fs +++ b/resources/shaders/gouraud.fs @@ -2,30 +2,21 @@ const vec3 ZERO = vec3(0.0, 0.0, 0.0); +varying vec3 clipping_planes_dots; + // x = tainted, y = specular; varying vec2 intensity; varying vec3 delta_box_min; varying vec3 delta_box_max; -varying vec3 world_pos; - uniform vec4 uniform_color; -// x = min z, y = max z; -uniform vec2 z_range; - -// clipping plane (general orientation): -uniform vec4 clipping_plane; void main() { - if ((world_pos.z < z_range.x) || (z_range.y < world_pos.z)) + if (any(lessThan(clipping_planes_dots, ZERO))) discard; - - if (world_pos.x*clipping_plane.x + world_pos.y*clipping_plane.y + world_pos.z*clipping_plane.z + clipping_plane.w < 0.0 ) - discard; - // if the fragment is outside the print volume -> use darker color vec3 color = (any(lessThan(delta_box_min, ZERO)) || any(greaterThan(delta_box_max, ZERO))) ? mix(uniform_color.rgb, ZERO, 0.3333) : uniform_color.rgb; gl_FragColor = vec4(vec3(intensity.y, intensity.y, intensity.y) + color * intensity.x, uniform_color.a); diff --git a/resources/shaders/gouraud.vs b/resources/shaders/gouraud.vs index a226cf312..cc54c1c44 100644 --- a/resources/shaders/gouraud.vs +++ b/resources/shaders/gouraud.vs @@ -28,13 +28,18 @@ struct PrintBoxDetection uniform PrintBoxDetection print_box; +// Clipping plane, x = min z, y = max z. Used by the FFF and SLA previews to clip with a top / bottom plane. +uniform vec2 z_range; +// Clipping plane - general orientation. Used by the SLA gizmo. +uniform vec4 clipping_plane; + // x = tainted, y = specular; varying vec2 intensity; varying vec3 delta_box_min; varying vec3 delta_box_max; -varying vec3 world_pos; +varying vec3 clipping_planes_dots; void main() { @@ -66,8 +71,11 @@ void main() { delta_box_min = ZERO; delta_box_max = ZERO; - } + } gl_Position = ftransform(); - world_pos = vec3(print_box.volume_world_matrix * gl_Vertex); -} + // Point in homogenous coordinates. + vec4 world_pos = print_box.volume_world_matrix * gl_Vertex; + // Fill in the scalars for fragment shader clipping. Fragments with any of these components lower than zero are discarded. + clipping_planes_dots = vec3(dot(world_pos, clipping_plane), world_pos.z - z_range.x, z_range.y - world_pos.z); +} From 2fe63e0b045361584e9320039088c7634303017a Mon Sep 17 00:00:00 2001 From: Vojtech Kral Date: Fri, 12 Apr 2019 10:57:30 +0200 Subject: [PATCH 2/2] Revert high DPI bitmaps in Preset and PresetBundle for now due to bugs in wxBitmapComboBox et al. --- src/slic3r/GUI/Preset.cpp | 8 ++++++-- src/slic3r/GUI/PresetBundle.cpp | 15 +++++++++++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/slic3r/GUI/Preset.cpp b/src/slic3r/GUI/Preset.cpp index 97c42d7fb..bed960a62 100644 --- a/src/slic3r/GUI/Preset.cpp +++ b/src/slic3r/GUI/Preset.cpp @@ -801,12 +801,16 @@ bool PresetCollection::delete_current_preset() void PresetCollection::load_bitmap_default(wxWindow *window, const std::string &file_name) { - *m_bitmap_main_frame = create_scaled_bitmap(window, file_name); + // XXX: See note in PresetBundle::load_compatible_bitmaps() + (void)window; + *m_bitmap_main_frame = create_scaled_bitmap(nullptr, file_name); } void PresetCollection::load_bitmap_add(wxWindow *window, const std::string &file_name) { - *m_bitmap_add = create_scaled_bitmap(window, file_name); + // XXX: See note in PresetBundle::load_compatible_bitmaps() + (void)window; + *m_bitmap_add = create_scaled_bitmap(nullptr, file_name); } const Preset* PresetCollection::get_selected_preset_parent() const diff --git a/src/slic3r/GUI/PresetBundle.cpp b/src/slic3r/GUI/PresetBundle.cpp index ad7829b2c..a8a63056c 100644 --- a/src/slic3r/GUI/PresetBundle.cpp +++ b/src/slic3r/GUI/PresetBundle.cpp @@ -398,10 +398,17 @@ void PresetBundle::export_selections(AppConfig &config) void PresetBundle::load_compatible_bitmaps(wxWindow *window) { - *m_bitmapCompatible = create_scaled_bitmap(window, "flag_green"); - *m_bitmapIncompatible = create_scaled_bitmap(window, "flag_red"); - *m_bitmapLock = create_scaled_bitmap(window, "lock_closed"); - *m_bitmapLockOpen = create_scaled_bitmap(window, "sys_unlock.png"); + // We don't actually pass the window pointer here and instead generate + // a low DPI bitmap, because the wxBitmapComboBox and wxDataViewControl don't support + // high DPI bitmaps very well, they compute their dimensions wrong. + // TODO: Update this when fixed in wxWidgets + // See also PresetCollection::load_bitmap_default() and PresetCollection::load_bitmap_add() + + (void)window; + *m_bitmapCompatible = create_scaled_bitmap(nullptr, "flag_green"); + *m_bitmapIncompatible = create_scaled_bitmap(nullptr, "flag_red"); + *m_bitmapLock = create_scaled_bitmap(nullptr, "lock_closed"); + *m_bitmapLockOpen = create_scaled_bitmap(nullptr, "sys_unlock.png"); prints .set_bitmap_compatible(m_bitmapCompatible); filaments .set_bitmap_compatible(m_bitmapCompatible);