From 0f184219e6fa3158ae8facf2b93204a5e52ad3b9 Mon Sep 17 00:00:00 2001 From: Tim Kuipers Date: Thu, 2 Jan 2020 19:03:36 +0100 Subject: [PATCH] use tiled image for xray error instead of a uniform color temporarily use the cura logo as placeholder image didn't correctly determine window size yet --- plugins/SolidView/SolidView.py | 18 ++++++++++--- plugins/SolidView/xray_composite.shader | 35 ++++++------------------- 2 files changed, 23 insertions(+), 30 deletions(-) diff --git a/plugins/SolidView/SolidView.py b/plugins/SolidView/SolidView.py index 478cf7331b..8600234173 100644 --- a/plugins/SolidView/SolidView.py +++ b/plugins/SolidView/SolidView.py @@ -6,7 +6,7 @@ from UM.View.View import View from UM.Scene.Iterator.DepthFirstIterator import DepthFirstIterator from UM.Scene.Selection import Selection from UM.Resources import Resources -from PyQt5.QtGui import QOpenGLContext +from PyQt5.QtGui import QOpenGLContext, QImage from UM.Application import Application from UM.Logger import Logger @@ -43,6 +43,8 @@ class SolidView(View): self._xray_pass = None self._xray_composite_shader = None self._composite_pass = None + self._xray_error_image = None + self._xray_error_image_size = None self._extruders_model = None self._theme = None @@ -118,6 +120,15 @@ class SolidView(View): self._checkSetup() + if not self._xray_error_image: + self._xray_error_image = OpenGL.getInstance().createTexture() + texture_file = "cura-icon-32.png" #TODO make an img for this! + try: + self._xray_error_image.load(Resources.getPath(Resources.Images, texture_file)) + except FileNotFoundError: + Logger.log("w", "Unable to find xray error texture image [%s]", texture_file) + self._xray_error_image_size = QImage(Resources.getPath(Resources.Images, texture_file)).size() + if not self._xray_shader: self._xray_shader = OpenGL.getInstance().createShaderProgram(Resources.getPath(Resources.Shaders, "xray.shader")) @@ -125,9 +136,10 @@ class SolidView(View): self._xray_composite_shader = OpenGL.getInstance().createShaderProgram(os.path.join(PluginRegistry.getInstance().getPluginPath("SolidView"), "xray_composite.shader")) theme = Application.getInstance().getTheme() self._xray_composite_shader.setUniformValue("u_background_color", Color(*theme.getColor("viewport_background").getRgb())) - self._xray_composite_shader.setUniformValue("u_xray_error_dark", Color(*theme.getColor("xray_error_dark").getRgb())) - self._xray_composite_shader.setUniformValue("u_xray_error_light", Color(*theme.getColor("xray_error_light").getRgb())) self._xray_composite_shader.setUniformValue("u_outline_color", Color(*theme.getColor("model_selection_outline").getRgb())) + self._xray_composite_shader.setTexture(3, self._xray_error_image) + [ww,wh] = [1920,1080] + self._xray_composite_shader.setUniformValue("u_xray_error_img_scaling", [ww / self._xray_error_image_size.width(), wh / self._xray_error_image_size.height()]) if not self.getRenderer().getRenderPass("xray"): # Currently the RenderPass constructor requires a size > 0 diff --git a/plugins/SolidView/xray_composite.shader b/plugins/SolidView/xray_composite.shader index 75bbbf22ec..f24d14f165 100644 --- a/plugins/SolidView/xray_composite.shader +++ b/plugins/SolidView/xray_composite.shader @@ -23,15 +23,15 @@ fragment = uniform sampler2D u_layer0; //Default pass. uniform sampler2D u_layer1; //Selection pass. uniform sampler2D u_layer2; //X-ray pass. + uniform sampler2D u_xray_error; //X-ray error image. uniform vec2 u_offset[9]; uniform float u_outline_strength; uniform vec4 u_outline_color; - uniform vec4 u_xray_error_dark; - uniform vec4 u_xray_error_light; uniform vec4 u_background_color; uniform float u_xray_error_strength; + uniform vec2 u_xray_error_img_scaling; const vec3 x_axis = vec3(1.0, 0.0, 0.0); const vec3 y_axis = vec3(0.0, 1.0, 0.0); @@ -62,16 +62,7 @@ fragment = float intersection_count = texture2D(u_layer2, v_uvs).r * 255.0; if(mod(intersection_count, 2.0) >= 1.0) { - float lightness = (result.r + result.g + result.b) / 3.0; - //if ( (mod((v_uvs.x / u_offset[8].x - v_uvs.y / u_offset[8].y) * 0.1, 2.0) >= 1.0) == (mod((v_uvs.x / u_offset[8].x + v_uvs.y / u_offset[8].y) * 0.1, 2.0) >= 1.0) ) // diamond pattern - if (lightness > 0.5) - { - result = result * (1.0 - u_xray_error_strength) + u_xray_error_strength * u_xray_error_dark; - } - else - { - result = result * (1.0 - u_xray_error_strength) + u_xray_error_strength * u_xray_error_light; - } + result = result * (1.0 - u_xray_error_strength) + u_xray_error_strength * texture(u_xray_error, v_uvs * u_xray_error_img_scaling); } vec4 sum = vec4(0.0); @@ -113,15 +104,15 @@ fragment41core = uniform sampler2D u_layer0; //Default pass. uniform sampler2D u_layer1; //Selection pass. uniform sampler2D u_layer2; //X-ray pass. + uniform sampler2D u_xray_error; //X-ray error image. uniform vec2 u_offset[9]; uniform float u_outline_strength; uniform vec4 u_outline_color; - uniform vec4 u_xray_error_dark; - uniform vec4 u_xray_error_light; uniform vec4 u_background_color; uniform float u_xray_error_strength; + uniform vec2 u_xray_error_img_scaling; const vec3 x_axis = vec3(1.0, 0.0, 0.0); const vec3 y_axis = vec3(0.0, 1.0, 0.0); @@ -153,16 +144,7 @@ fragment41core = float intersection_count = texture(u_layer2, v_uvs).r * 255.0; if(mod(intersection_count, 2.0) >= 1.0) { - float lightness = (result.r + result.g + result.b) / 3.0; - //if ( (mod((v_uvs.x / u_offset[8].x - v_uvs.y / u_offset[8].y) * 0.1, 2.0) >= 1.0) == (mod((v_uvs.x / u_offset[8].x + v_uvs.y / u_offset[8].y) * 0.1, 2.0) >= 1.0) ) // diamond pattern - if (lightness > 0.5) - { - result = result * (1.0 - u_xray_error_strength) + u_xray_error_strength * u_xray_error_dark; - } - else - { - result = result * (1.0 - u_xray_error_strength) + u_xray_error_strength * u_xray_error_light; - } + result = result * (1.0 - u_xray_error_strength) + u_xray_error_strength * texture(u_xray_error, v_uvs * u_xray_error_img_scaling); } vec4 sum = vec4(0.0); @@ -189,13 +171,12 @@ fragment41core = u_layer0 = 0 u_layer1 = 1 u_layer2 = 2 +u_xray_error = 3 u_background_color = [0.965, 0.965, 0.965, 1.0] u_outline_strength = 1.0 u_outline_color = [0.05, 0.66, 0.89, 1.0] -u_error_color = [0.0, 0.0, 0.0, 1.0] -u_xray_error_dark = [1.0, 0.0, 0.0, 1.0] -u_xray_error_light = [1.0, 1.0, 0.0, 1.0] u_xray_error_strength = 0.4 +u_xray_error_img_scaling = [1.0,1.0] [bindings]