diff --git a/cura/BuildVolume.py b/cura/BuildVolume.py index 1bd5c7028e..a7fc0701be 100755 --- a/cura/BuildVolume.py +++ b/cura/BuildVolume.py @@ -178,8 +178,9 @@ class BuildVolume(SceneNode): self._shader = OpenGL.getInstance().createShaderProgram(Resources.getPath(Resources.Shaders, "default.shader")) self._grid_shader = OpenGL.getInstance().createShaderProgram(Resources.getPath(Resources.Shaders, "grid.shader")) theme = Application.getInstance().getTheme() - self._grid_shader.setUniformValue("u_gridColor0", Color(*theme.getColor("buildplate").getRgb())) - self._grid_shader.setUniformValue("u_gridColor1", Color(*theme.getColor("buildplate_alt").getRgb())) + self._grid_shader.setUniformValue("u_plateColor", Color(*theme.getColor("buildplate").getRgb())) + self._grid_shader.setUniformValue("u_gridColor0", Color(*theme.getColor("buildplate_grid").getRgb())) + self._grid_shader.setUniformValue("u_gridColor1", Color(*theme.getColor("buildplate_grid_minor").getRgb())) self._grid_shader.setUniformValue("u_z_bias", 0.000001) renderer.queueNode(self, mode = RenderBatch.RenderMode.Lines) diff --git a/resources/shaders/grid.shader b/resources/shaders/grid.shader index 74eed544fd..c44db85dba 100644 --- a/resources/shaders/grid.shader +++ b/resources/shaders/grid.shader @@ -14,6 +14,7 @@ vertex = } fragment = + uniform lowp vec4 u_plateColor; uniform lowp vec4 u_gridColor0; uniform lowp vec4 u_gridColor1; @@ -21,10 +22,19 @@ fragment = void main() { - if (mod(floor(v_uvs.x / 10.0) - floor(v_uvs.y / 10.0), 2.0) < 1.0) - gl_FragColor = u_gridColor0; - else - gl_FragColor = u_gridColor1; + vec2 coord = v_uvs.xy; + + // Compute anti-aliased world-space minor grid lines + vec2 minorGrid = abs(fract(coord - 0.5) - 0.5) / fwidth(coord); + float minorLine = min(minorGrid.x, minorGrid.y); + + vec4 minorGridColor = mix(u_plateColor, u_gridColor1, 1.0 - min(minorLine, 1.0)); + + // Compute anti-aliased world-space major grid lines + vec2 majorGrid = abs(fract(coord / 10 - 0.5) - 0.5) / fwidth(coord / 10); + float majorLine = min(majorGrid.x, majorGrid.y); + + frag_color = mix(minorGridColor, u_gridColor0, 1.0 - min(majorLine, 1.0)); } vertex41core = @@ -44,23 +54,37 @@ vertex41core = fragment41core = #version 410 + uniform lowp vec4 u_plateColor; uniform lowp vec4 u_gridColor0; uniform lowp vec4 u_gridColor1; + uniform lowp float u_z_bias; //Bias in the depth buffer for rendering this object (to make an object be rendered in front of or behind other objects). in lowp vec2 v_uvs; out vec4 frag_color; void main() { - if (mod(floor(v_uvs.x / 10.0) - floor(v_uvs.y / 10.0), 2.0) < 1.0) - frag_color = u_gridColor0; - else - frag_color = u_gridColor1; + vec2 coord = v_uvs.xy; + + // Compute anti-aliased world-space minor grid lines + vec2 minorGrid = abs(fract(coord - 0.5) - 0.5) / fwidth(coord); + float minorLine = min(minorGrid.x, minorGrid.y); + + vec4 minorGridColor = mix(u_plateColor, u_gridColor1, 1.0 - min(minorLine, 1.0)); + + // Compute anti-aliased world-space major grid lines + vec2 majorGrid = abs(fract(coord / 10 - 0.5) - 0.5) / fwidth(coord / 10); + float majorLine = min(majorGrid.x, majorGrid.y); + + frag_color = mix(minorGridColor, u_gridColor0, 1.0 - min(majorLine, 1.0)); + gl_FragDepth = gl_FragCoord.z + u_z_bias; } [defaults] +u_plateColor = [1.0, 1.0, 1.0, 1.0] u_gridColor0 = [0.96, 0.96, 0.96, 1.0] u_gridColor1 = [0.8, 0.8, 0.8, 1.0] +u_z_bias = 0.0 [bindings] u_modelViewProjectionMatrix = model_view_projection_matrix diff --git a/resources/themes/cura-light/theme.json b/resources/themes/cura-light/theme.json index d727425795..57b9b77221 100644 --- a/resources/themes/cura-light/theme.json +++ b/resources/themes/cura-light/theme.json @@ -247,9 +247,8 @@ "viewport_background": [245, 245, 245, 255], "volume_outline": [12, 169, 227, 255], "buildplate": [244, 244, 244, 255], - "buildplate_alt": [204, 204, 204, 255], "buildplate_grid": [129, 131, 134, 255], - "buildplate_grid_minor": [129, 131, 134, 31], + "buildplate_grid_minor": [230, 230, 231, 255], "convex_hull": [35, 35, 35, 127], "disallowed_area": [0, 0, 0, 40], diff --git a/resources/themes/cura/theme.json b/resources/themes/cura/theme.json index 46da3cbe7a..e94141413c 100644 --- a/resources/themes/cura/theme.json +++ b/resources/themes/cura/theme.json @@ -170,9 +170,8 @@ "viewport_background": [241, 242, 242, 255], "volume_outline": [1, 168, 230, 255], "buildplate": [252, 252, 252, 255], - "buildplate_alt": [204, 204, 204, 255], "buildplate_grid": [129, 131, 134, 255], - "buildplate_grid_minor": [129, 131, 134, 31], + "buildplate_grid_minor": [230, 230, 231, 255], "convex_hull": [35, 35, 35, 127], "disallowed_area": [0, 0, 0, 52],