From 4659d8616eacf3d78b76903d0080f476a45ec13f Mon Sep 17 00:00:00 2001 From: Jack Ha Date: Wed, 1 Feb 2017 16:29:21 +0100 Subject: [PATCH] Fixed some opengl 4.1 core vertex and fragment shaders, layerview anchor. CURA-3273 --- plugins/LayerView/LayerView.qml | 4 +- plugins/LayerView/layerview_composite.shader | 68 ++++++++++++++++++++ plugins/XRayView/xray.shader | 22 +++++++ 3 files changed, 92 insertions(+), 2 deletions(-) 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/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]