diff --git a/cura/LayerPolygon.py b/cura/LayerPolygon.py index d3da01e590..cb00bd0c60 100644 --- a/cura/LayerPolygon.py +++ b/cura/LayerPolygon.py @@ -37,8 +37,8 @@ class LayerPolygon: # Buffering the colors shouldn't be necessary as it is not # re-used and can save alot of memory usage. - self._colors = self.__color_map[self._types] - self._color_map = self.__color_map + self._color_map = self.__color_map * [1, 1, 1, self._extruder] # The alpha component is used to store the extruder nr + self._colors = self._color_map[self._types] # When type is used as index returns true if type == LayerPolygon.InfillType or type == LayerPolygon.SkinType or type == LayerPolygon.SupportInfillType # Should be generated in better way, not hardcoded. @@ -172,31 +172,17 @@ class LayerPolygon: return normals - __color_mapping = { - NoneType: Color(1.0, 1.0, 1.0, 1.0), - Inset0Type: Color(1.0, 0.0, 0.0, 1.0), - InsetXType: Color(0.0, 1.0, 0.0, 1.0), - SkinType: Color(1.0, 1.0, 0.0, 1.0), - SupportType: Color(0.0, 1.0, 1.0, 1.0), - SkirtType: Color(0.0, 1.0, 1.0, 1.0), - InfillType: Color(1.0, 0.75, 0.0, 1.0), - SupportInfillType: Color(0.0, 1.0, 1.0, 1.0), - MoveCombingType: Color(0.0, 0.0, 1.0, 1.0), - MoveRetractionType: Color(0.5, 0.5, 1.0, 1.0), - SupportInterfaceType: Color(0.25, 0.75, 1.0, 1.0), - } - # Should be generated in better way, not hardcoded. __color_map = numpy.array([ - [1.0, 1.0, 1.0, 1.0], - [1.0, 0.0, 0.0, 1.0], - [0.0, 1.0, 0.0, 1.0], - [1.0, 1.0, 0.0, 1.0], - [0.0, 1.0, 1.0, 1.0], - [0.0, 1.0, 1.0, 1.0], - [1.0, 0.75, 0.0, 1.0], - [0.0, 1.0, 1.0, 1.0], - [0.0, 0.0, 1.0, 1.0], - [0.5, 0.5, 1.0, 1.0], - [0.25, 0.75, 1.0, 1.0] + [1.0, 1.0, 1.0, 1.0], # NoneType + [1.0, 0.0, 0.0, 1.0], # Inset0Type + [0.0, 1.0, 0.0, 1.0], # InsetXType + [1.0, 1.0, 0.0, 1.0], # SkinType + [0.0, 1.0, 1.0, 1.0], # SupportType + [0.0, 1.0, 1.0, 1.0], # SkirtType + [1.0, 0.75, 0.0, 1.0], # InfillType + [0.0, 1.0, 1.0, 1.0], # SupportInfillType + [0.0, 0.0, 1.0, 1.0], # MoveCombingType + [0.5, 0.5, 1.0, 1.0], # MoveRetractionType + [0.25, 0.75, 1.0, 1.0] # SupportInterfaceType ]) \ No newline at end of file diff --git a/plugins/LayerView/LayerPass.py b/plugins/LayerView/LayerPass.py index a85ef5292d..c9fe600a50 100644 --- a/plugins/LayerView/LayerPass.py +++ b/plugins/LayerView/LayerPass.py @@ -6,20 +6,26 @@ from UM.Resources import Resources from UM.Scene.SceneNode import SceneNode from UM.Scene.ToolHandle import ToolHandle from UM.Application import Application +from UM.PluginRegistry import PluginRegistry from UM.View.RenderPass import RenderPass from UM.View.RenderBatch import RenderBatch from UM.View.GL.OpenGL import OpenGL +from cura.Settings.ExtruderManager import ExtruderManager + +import os.path + ## RenderPass used to display g-code paths. class LayerPass(RenderPass): def __init__(self, width, height): super().__init__("layerview", width, height) - self._shader = None + self._layer_shader = None self._tool_handle_shader = None self._gl = OpenGL.getInstance().getBindingsObject() self._scene = Application.getInstance().getController().getScene() + self._extruder_manager = ExtruderManager.getInstance() self._layer_view = None @@ -27,8 +33,9 @@ class LayerPass(RenderPass): self._layerview = layerview def render(self): - if not self._shader: - self._shader = OpenGL.getInstance().createShaderProgram(Resources.getPath(Resources.Shaders, "default.shader")) + if not self._layer_shader: + self._layer_shader = OpenGL.getInstance().createShaderProgram(os.path.join(PluginRegistry.getInstance().getPluginPath("LayerView"), "layers.shader")) + self._layer_shader.setUniformValue("u_active_extruder", float(self._extruder_manager.activeExtruderIndex)) if not self._tool_handle_shader: self._tool_handle_shader = OpenGL.getInstance().createShaderProgram(Resources.getPath(Resources.Shaders, "toolhandle.shader")) @@ -56,12 +63,12 @@ class LayerPass(RenderPass): end += counts # This uses glDrawRangeElements internally to only draw a certain range of lines. - batch = RenderBatch(self._shader, type = RenderBatch.RenderType.Solid, mode = RenderBatch.RenderMode.Lines, range = (start, end)) + batch = RenderBatch(self._layer_shader, type = RenderBatch.RenderType.Solid, mode = RenderBatch.RenderMode.Lines, range = (start, end)) batch.addItem(node.getWorldTransformation(), layer_data) batch.render(self._scene.getActiveCamera()) # Create a new batch that is not range-limited - batch = RenderBatch(self._shader, type = RenderBatch.RenderType.Solid) + batch = RenderBatch(self._layer_shader, type = RenderBatch.RenderType.Solid) if self._layerview._current_layer_mesh: batch.addItem(node.getWorldTransformation(), self._layerview._current_layer_mesh) diff --git a/plugins/LayerView/layers.shader b/plugins/LayerView/layers.shader new file mode 100644 index 0000000000..8e1402e6b2 --- /dev/null +++ b/plugins/LayerView/layers.shader @@ -0,0 +1,35 @@ +[shaders] +vertex = + uniform highp mat4 u_modelViewProjectionMatrix; + uniform lowp float u_active_extruder; + uniform lowp float u_shade_factor; + + attribute highp vec4 a_vertex; + attribute lowp vec4 a_color; + varying lowp vec4 v_color; + void main() + { + gl_Position = u_modelViewProjectionMatrix * a_vertex; + // shade the color depending on the extruder index stored in the alpha component of the color + v_color = (a_color.a == u_active_extruder) ? a_color : a_color * u_shade_factor; + v_color.a = 1.0; + } + +fragment = + varying lowp vec4 v_color; + + void main() + { + gl_FragColor = v_color; + } + +[defaults] +u_active_extruder = 0.0 +u_shade_factor = 0.75 + +[bindings] +u_modelViewProjectionMatrix = model_view_projection_matrix + +[attributes] +a_vertex = vertex +a_color = color