diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index e6e1d08afb..720f5b8fb7 100644 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -223,6 +223,7 @@ class CuraApplication(QtApplication): Preferences.getInstance().addPreference("mesh/scale_tiny_meshes", True) Preferences.getInstance().addPreference("cura/dialog_on_project_save", True) Preferences.getInstance().addPreference("cura/asked_dialog_on_project_save", False) + Preferences.getInstance().addPreference("view/force_layer_view_compatibility_mode", False) Preferences.getInstance().addPreference("cura/currency", "€") Preferences.getInstance().addPreference("cura/material_settings", "{}") diff --git a/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py b/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py index 1dbcbdb3b7..21227e7a8b 100644 --- a/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py +++ b/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py @@ -9,6 +9,7 @@ from UM.Scene.SceneNode import SceneNode from UM.Application import Application from UM.Mesh.MeshData import MeshData from UM.Preferences import Preferences +from UM.View.GL.OpenGLContext import OpenGLContext from UM.Message import Message from UM.i18n import i18nCatalog @@ -180,10 +181,10 @@ class ProcessSlicedLayersJob(Job): material_color_map[0, :] = color # We have to scale the colors for compatibility mode - if Application.getInstance().getRenderer().getSupportsGeometryShader(): - line_type_brightness = 1.0 - else: + if OpenGLContext.isLegacyOpenGL() or bool(Preferences.getInstance().getValue("view/force_layer_view_compatibility_mode")): line_type_brightness = 0.5 # for compatibility mode + else: + line_type_brightness = 1.0 layer_mesh = layer_data.build(material_color_map, line_type_brightness) if self._abort_requested: diff --git a/plugins/LayerView/LayerPass.py b/plugins/LayerView/LayerPass.py index 7ae024181d..9ba245489a 100644 --- a/plugins/LayerView/LayerPass.py +++ b/plugins/LayerView/LayerPass.py @@ -14,6 +14,7 @@ from UM.View.GL.OpenGL import OpenGL from cura.Settings.ExtruderManager import ExtruderManager + import os.path ## RenderPass used to display g-code paths. diff --git a/plugins/LayerView/LayerView.py b/plugins/LayerView/LayerView.py index 922966854d..468fc01ec3 100644 --- a/plugins/LayerView/LayerView.py +++ b/plugins/LayerView/LayerView.py @@ -16,6 +16,7 @@ from UM.Logger import Logger from UM.View.GL.OpenGL import OpenGL from UM.Message import Message from UM.Application import Application +from UM.View.GL.OpenGLContext import OpenGLContext from cura.ConvexHullNode import ConvexHullNode from cura.Settings.ExtruderManager import ExtruderManager @@ -65,7 +66,6 @@ class LayerView(View): Preferences.getInstance().addPreference("view/top_layer_count", 5) Preferences.getInstance().addPreference("view/only_show_top_layers", False) - Preferences.getInstance().addPreference("view/compatibility_mode", True) # Default True for now, needs testing of different computers Preferences.getInstance().preferenceChanged.connect(self._onPreferencesChanged) @@ -93,7 +93,7 @@ class LayerView(View): # Currently the RenderPass constructor requires a size > 0 # This should be fixed in RenderPass's constructor. self._layer_pass = LayerPass.LayerPass(1, 1) - self._compatibility_mode = not self.getRenderer().getSupportsGeometryShader() + self._compatibility_mode = OpenGLContext.isLegacyOpenGL() or bool(Preferences.getInstance().getValue("view/force_layer_view_compatibility_mode")) self._layer_pass.setLayerView(self) self.getRenderer().addRenderPass(self._layer_pass) return self._layer_pass diff --git a/plugins/LayerView/LayerView.qml b/plugins/LayerView/LayerView.qml index 9c877769bc..ee109b7f04 100644 --- a/plugins/LayerView/LayerView.qml +++ b/plugins/LayerView/LayerView.qml @@ -174,7 +174,7 @@ Item ComboBox { id: layerTypeCombobox - anchors.top: slider_background.bottom + anchors.top: parent.top anchors.left: parent.left model: layerViewTypes visible: !UM.LayerView.compatibilityMode @@ -186,7 +186,7 @@ Item Label { id: compatibilityModeLabel - anchors.top: slider_background.bottom + anchors.top: parent.top anchors.left: parent.left text: catalog.i18nc("@label","Compatibility mode") visible: UM.LayerView.compatibilityMode diff --git a/plugins/LayerView/layers.shader b/plugins/LayerView/layers.shader index b58d11da0c..81d5c94dff 100644 --- a/plugins/LayerView/layers.shader +++ b/plugins/LayerView/layers.shader @@ -4,10 +4,9 @@ vertex = uniform lowp float u_active_extruder; uniform lowp float u_shade_factor; uniform highp int u_layer_view_type; - uniform highp int u_only_color_active_extruder; - attribute highp int a_extruder; - attribute highp int a_line_type; + attribute highp float a_extruder; + attribute highp float a_line_type; attribute highp vec4 a_vertex; attribute lowp vec4 a_color; attribute lowp vec4 a_material_color; @@ -19,10 +18,7 @@ vertex = { gl_Position = u_modelViewProjectionMatrix * a_vertex; v_color = a_color; - if ((u_only_color_active_extruder == 1) && (a_line_type != 8) && (a_line_type != 9)) { - v_color = (a_extruder == u_active_extruder) ? v_color : vec4(0.4, 0.4, 0.4, v_color.a); - } - if ((u_only_color_active_extruder == 0) && (a_line_type != 8) && (a_line_type != 9)) { + if ((a_line_type != 8.0) && (a_line_type != 9.0)) { v_color = (a_extruder == u_active_extruder) ? v_color : vec4(u_shade_factor * v_color.rgb, v_color.a); } @@ -73,11 +69,83 @@ fragment = gl_FragColor = v_color; } +vertex41core = + #version 410 + uniform highp mat4 u_modelViewProjectionMatrix; + uniform lowp float u_active_extruder; + uniform lowp float u_shade_factor; + uniform highp int u_layer_view_type; + + in highp int a_extruder; + in highp int a_line_type; + in highp vec4 a_vertex; + in lowp vec4 a_color; + in lowp vec4 a_material_color; + + out lowp vec4 v_color; + out float v_line_type; + + void main() + { + gl_Position = u_modelViewProjectionMatrix * a_vertex; + v_color = a_color; + if ((a_line_type != 8) && (a_line_type != 9)) { + v_color = (a_extruder == u_active_extruder) ? v_color : vec4(u_shade_factor * v_color.rgb, v_color.a); + } + + v_line_type = a_line_type; + } + +fragment41core = + #version 410 + in lowp vec4 v_color; + in float v_line_type; + out vec4 frag_color; + + uniform int u_show_travel_moves; + uniform int u_show_support; + uniform int u_show_adhesion; + uniform int u_show_skin; + uniform int u_show_infill; + + void main() + { + if ((u_show_travel_moves == 0) && (v_line_type >= 7.5) && (v_line_type <= 9.5)) { // actually, 8 and 9 + // discard movements + discard; + } + // support: 4, 7, 10 + if ((u_show_support == 0) && ( + ((v_line_type >= 3.5) && (v_line_type <= 4.5)) || + ((v_line_type >= 6.5) && (v_line_type <= 7.5)) || + ((v_line_type >= 9.5) && (v_line_type <= 10.5)) + )) { + discard; + } + // skin: 1, 2, 3 + if ((u_show_skin == 0) && ( + (v_line_type >= 0.5) && (v_line_type <= 3.5) + )) { + discard; + } + // adhesion: + if ((u_show_adhesion == 0) && (v_line_type >= 4.5) && (v_line_type <= 5.5)) { + // discard movements + discard; + } + // infill: + if ((u_show_infill == 0) && (v_line_type >= 5.5) && (v_line_type <= 6.5)) { + // discard movements + discard; + } + + frag_color = v_color; + } + [defaults] u_active_extruder = 0.0 u_shade_factor = 0.60 u_layer_view_type = 0 -u_only_color_active_extruder = 1 u_extruder_opacity = [1.0, 1.0, 1.0, 1.0] u_show_travel_moves = 0 diff --git a/plugins/LayerView/layers3d.shader b/plugins/LayerView/layers3d.shader index 943e9bd64e..c7c7628a92 100644 --- a/plugins/LayerView/layers3d.shader +++ b/plugins/LayerView/layers3d.shader @@ -1,6 +1,8 @@ [shaders] -vertex = +vertex41core = #version 410 + uniform highp mat4 u_modelViewProjectionMatrix; + uniform highp mat4 u_modelMatrix; uniform highp mat4 u_viewProjectionMatrix; uniform lowp float u_active_extruder; @@ -9,27 +11,26 @@ vertex = uniform highp mat4 u_normalMatrix; - attribute highp vec4 a_vertex; - attribute lowp vec4 a_color; - attribute lowp vec4 a_material_color; - attribute highp vec4 a_normal; - attribute highp vec2 a_line_dim; // line width and thickness - attribute highp int a_extruder; - attribute highp int a_line_type; + in highp vec4 a_vertex; + in lowp vec4 a_color; + in lowp vec4 a_material_color; + in highp vec4 a_normal; + in highp vec2 a_line_dim; // line width and thickness + in highp int a_extruder; + in highp int a_line_type; - varying lowp vec4 v_color; + out lowp vec4 v_color; - varying highp vec3 v_vertex; - varying highp vec3 v_normal; - varying lowp vec2 v_line_dim; - varying highp int v_extruder; - varying highp vec4 v_extruder_opacity; - varying int v_line_type; + out highp vec3 v_vertex; + out highp vec3 v_normal; + out lowp vec2 v_line_dim; + out highp int v_extruder; + out highp vec4 v_extruder_opacity; + out int v_line_type; - varying lowp vec4 f_color; - varying highp vec3 f_vertex; - varying highp vec3 f_normal; - varying highp int f_extruder; + out lowp vec4 f_color; + out highp vec3 f_vertex; + out highp vec3 f_normal; void main() { @@ -56,13 +57,13 @@ vertex = v_line_type = a_line_type; v_extruder_opacity = u_extruder_opacity; - // for testing and backwards compatibility without geometry shader - /*f_color = v_color; + // for testing without geometry shader + f_color = v_color; f_vertex = v_vertex; - f_normal = v_normal;*/ + f_normal = v_normal; } -geometry = +geometry41core = #version 410 uniform highp mat4 u_viewProjectionMatrix; @@ -86,7 +87,6 @@ geometry = out vec4 f_color; out vec3 f_normal; out vec3 f_vertex; - out uint f_extruder; void main() { @@ -130,8 +130,6 @@ geometry = size_y = v_line_dim[0].y / 2 + 0.01; } - f_extruder = v_extruder[0]; - g_vertex_delta = gl_in[1].gl_Position - gl_in[0].gl_Position; g_vertex_normal_horz_head = normalize(vec3(-g_vertex_delta.x, -g_vertex_delta.y, -g_vertex_delta.z)); g_vertex_offset_horz_head = vec4(g_vertex_normal_horz_head * size_x, 0.0); @@ -285,11 +283,13 @@ geometry = EndPrimitive(); } -fragment = +fragment41core = #version 410 - varying lowp vec4 f_color; - varying lowp vec3 f_normal; - varying lowp vec3 f_vertex; + in lowp vec4 f_color; + in lowp vec3 f_normal; + in lowp vec3 f_vertex; + + out vec4 frag_color; uniform mediump vec4 u_ambientColor; uniform highp vec3 u_lightPosition; @@ -309,7 +309,7 @@ fragment = finalColor += (NdotL * f_color); finalColor.a = alpha; // Do not change alpha in any way - gl_FragColor = finalColor; + frag_color = finalColor; } diff --git a/plugins/LayerView/layerview_composite.shader b/plugins/LayerView/layerview_composite.shader index 61d61bb901..f203650ce6 100644 --- a/plugins/LayerView/layerview_composite.shader +++ b/plugins/LayerView/layerview_composite.shader @@ -63,6 +63,74 @@ fragment = } } +vertex41core = + #version 410 + uniform highp mat4 u_modelViewProjectionMatrix; + in highp vec4 a_vertex; + in highp vec2 a_uvs; + + out highp vec2 v_uvs; + + void main() + { + gl_Position = u_modelViewProjectionMatrix * a_vertex; + v_uvs = a_uvs; + } + +fragment41core = + #version 410 + uniform sampler2D u_layer0; + uniform sampler2D u_layer1; + uniform sampler2D u_layer2; + + uniform vec2 u_offset[9]; + + uniform vec4 u_background_color; + uniform float u_outline_strength; + uniform vec4 u_outline_color; + + in vec2 v_uvs; + + float kernel[9]; + + const vec3 x_axis = vec3(1.0, 0.0, 0.0); + const vec3 y_axis = vec3(0.0, 1.0, 0.0); + const vec3 z_axis = vec3(0.0, 0.0, 1.0); + + out vec4 frag_color; + + void main() + { + kernel[0] = 0.0; kernel[1] = 1.0; kernel[2] = 0.0; + kernel[3] = 1.0; kernel[4] = -4.0; kernel[5] = 1.0; + kernel[6] = 0.0; kernel[7] = 1.0; kernel[8] = 0.0; + + vec4 result = u_background_color; + + vec4 main_layer = texture(u_layer0, v_uvs); + vec4 selection_layer = texture(u_layer1, v_uvs); + vec4 layerview_layer = texture(u_layer2, v_uvs); + + result = main_layer * main_layer.a + result * (1.0 - main_layer.a); + result = layerview_layer * layerview_layer.a + result * (1.0 - layerview_layer.a); + + vec4 sum = vec4(0.0); + for (int i = 0; i < 9; i++) + { + vec4 color = vec4(texture(u_layer1, v_uvs.xy + u_offset[i]).a); + sum += color * (kernel[i] / u_outline_strength); + } + + if((selection_layer.rgb == x_axis || selection_layer.rgb == y_axis || selection_layer.rgb == z_axis)) + { + frag_color = result; + } + else + { + frag_color = mix(result, u_outline_color, abs(sum.a)); + } + } + [defaults] u_layer0 = 0 u_layer1 = 1 diff --git a/plugins/XRayView/xray.shader b/plugins/XRayView/xray.shader index b42b3e056a..41b00154ea 100644 --- a/plugins/XRayView/xray.shader +++ b/plugins/XRayView/xray.shader @@ -17,6 +17,28 @@ fragment = gl_FragColor = u_color; } +vertex41core = + #version 410 + uniform highp mat4 u_modelViewProjectionMatrix; + + in highp vec4 a_vertex; + + void main() + { + gl_Position = u_modelViewProjectionMatrix * a_vertex; + } + +fragment41core = + #version 410 + uniform lowp vec4 u_color; + + out vec4 frag_color; + + void main() + { + frag_color = u_color; + } + [defaults] u_color = [0.02, 0.02, 0.02, 1.0] diff --git a/plugins/XRayView/xray_composite.shader b/plugins/XRayView/xray_composite.shader index e7a38950bf..82dca52cf9 100644 --- a/plugins/XRayView/xray_composite.shader +++ b/plugins/XRayView/xray_composite.shader @@ -67,6 +67,77 @@ fragment = } } +vertex41core = + #version 410 + uniform highp mat4 u_modelViewProjectionMatrix; + in highp vec4 a_vertex; + in highp vec2 a_uvs; + + out highp vec2 v_uvs; + + void main() + { + gl_Position = u_modelViewProjectionMatrix * a_vertex; + v_uvs = a_uvs; + } + +fragment41core = + #version 410 + uniform sampler2D u_layer0; + uniform sampler2D u_layer1; + uniform sampler2D u_layer2; + + uniform vec2 u_offset[9]; + + uniform float u_outline_strength; + uniform vec4 u_outline_color; + uniform vec4 u_error_color; + uniform vec4 u_background_color; + + const vec3 x_axis = vec3(1.0, 0.0, 0.0); + const vec3 y_axis = vec3(0.0, 1.0, 0.0); + const vec3 z_axis = vec3(0.0, 0.0, 1.0); + + in vec2 v_uvs; + out vec4 frag_color; + + float kernel[9]; + + void main() + { + kernel[0] = 0.0; kernel[1] = 1.0; kernel[2] = 0.0; + kernel[3] = 1.0; kernel[4] = -4.0; kernel[5] = 1.0; + kernel[6] = 0.0; kernel[7] = 1.0; kernel[8] = 0.0; + + vec4 result = u_background_color; + vec4 layer0 = texture(u_layer0, v_uvs); + + result = layer0 * layer0.a + result * (1.0 - layer0.a); + + float intersection_count = (texture(u_layer2, v_uvs).r * 255.0) / 5.0; + if(mod(intersection_count, 2.0) == 1.0) + { + result = u_error_color; + } + + vec4 sum = vec4(0.0); + for (int i = 0; i < 9; i++) + { + vec4 color = vec4(texture(u_layer1, v_uvs.xy + u_offset[i]).a); + sum += color * (kernel[i] / u_outline_strength); + } + + vec4 layer1 = texture(u_layer1, v_uvs); + if((layer1.rgb == x_axis || layer1.rgb == y_axis || layer1.rgb == z_axis)) + { + frag_color = result; + } + else + { + frag_color = mix(result, vec4(abs(sum.a)) * u_outline_color, abs(sum.a)); + } + } + [defaults] u_layer0 = 0 u_layer1 = 1 diff --git a/resources/qml/Preferences/GeneralPage.qml b/resources/qml/Preferences/GeneralPage.qml index ee300989a4..9b6f32f114 100644 --- a/resources/qml/Preferences/GeneralPage.qml +++ b/resources/qml/Preferences/GeneralPage.qml @@ -265,6 +265,20 @@ UM.PreferencesPage } } + UM.TooltipArea { + width: childrenRect.width + height: childrenRect.height + text: catalog.i18nc("@info:tooltip", "Should layer be forced into compatibility mode?") + + CheckBox + { + id: forceLayerViewCompatibilityModeCheckbox + text: catalog.i18nc("@option:check", "Force layer view compatibility mode (restart required)") + checked: boolCheck(UM.Preferences.getValue("view/force_layer_view_compatibility_mode")) + onCheckedChanged: UM.Preferences.setValue("view/force_layer_view_compatibility_mode", checked) + } + } + Item { //: Spacer