layers.shader 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. [shaders]
  2. vertex =
  3. uniform highp mat4 u_modelMatrix;
  4. uniform highp mat4 u_viewMatrix;
  5. uniform highp mat4 u_projectionMatrix;
  6. uniform lowp float u_active_extruder;
  7. uniform lowp float u_shade_factor;
  8. uniform highp int u_layer_view_type;
  9. attribute highp float a_extruder;
  10. attribute highp float a_line_type;
  11. attribute highp vec4 a_vertex;
  12. attribute lowp vec4 a_color;
  13. attribute lowp vec4 a_material_color;
  14. attribute highp float a_vertex_index;
  15. varying lowp vec4 v_color;
  16. varying float v_line_type;
  17. varying highp float v_vertex_index;
  18. void main()
  19. {
  20. gl_Position = u_projectionMatrix * u_viewMatrix * u_modelMatrix * a_vertex;
  21. // shade the color depending on the extruder index
  22. v_color = a_color;
  23. // 8 and 9 are travel moves
  24. if ((a_line_type != 8.0) && (a_line_type != 9.0)) {
  25. v_color = (a_extruder == u_active_extruder) ? v_color : vec4(u_shade_factor * v_color.rgb, v_color.a);
  26. }
  27. v_line_type = a_line_type;
  28. v_vertex_index = a_vertex_index;
  29. }
  30. fragment =
  31. #ifdef GL_ES
  32. #ifdef GL_FRAGMENT_PRECISION_HIGH
  33. precision highp float;
  34. #else
  35. precision mediump float;
  36. #endif // GL_FRAGMENT_PRECISION_HIGH
  37. #endif // GL_ES
  38. varying lowp vec4 v_color;
  39. varying float v_line_type;
  40. varying highp float v_vertex_index;
  41. uniform int u_show_travel_moves;
  42. uniform int u_show_helpers;
  43. uniform int u_show_skin;
  44. uniform int u_show_infill;
  45. uniform highp vec2 u_drawRange;
  46. void main()
  47. {
  48. if (u_drawRange.x >= 0.0 && u_drawRange.y >= 0.0 && (v_vertex_index < u_drawRange.x || v_vertex_index > u_drawRange.y))
  49. {
  50. discard;
  51. }
  52. if ((u_show_travel_moves == 0) && (v_line_type >= 7.5) && (v_line_type <= 9.5)) { // actually, 8 and 9
  53. // discard movements
  54. discard;
  55. }
  56. // support: 4, 5, 7, 10, 11 (prime tower)
  57. if ((u_show_helpers == 0) && (
  58. ((v_line_type >= 3.5) && (v_line_type <= 4.5)) ||
  59. ((v_line_type >= 4.5) && (v_line_type <= 5.5)) ||
  60. ((v_line_type >= 6.5) && (v_line_type <= 7.5)) ||
  61. ((v_line_type >= 9.5) && (v_line_type <= 10.5)) ||
  62. ((v_line_type >= 10.5) && (v_line_type <= 11.5))
  63. )) {
  64. discard;
  65. }
  66. // skin: 1, 2, 3
  67. if ((u_show_skin == 0) && (
  68. (v_line_type >= 0.5) && (v_line_type <= 3.5)
  69. )) {
  70. discard;
  71. }
  72. // infill:
  73. if ((u_show_infill == 0) && (v_line_type >= 5.5) && (v_line_type <= 6.5)) {
  74. // discard movements
  75. discard;
  76. }
  77. gl_FragColor = v_color;
  78. }
  79. [defaults]
  80. u_active_extruder = 0.0
  81. u_shade_factor = 0.60
  82. u_layer_view_type = 0
  83. u_extruder_opacity = [[1.0, 1.0, 1.0, 1.0], [1.0, 1.0, 1.0, 1.0], [1.0, 1.0, 1.0, 1.0], [1.0, 1.0, 1.0, 1.0]]
  84. u_show_travel_moves = 0
  85. u_show_helpers = 1
  86. u_show_skin = 1
  87. u_show_infill = 1
  88. u_drawRange = [-1.0, -1.0]
  89. [bindings]
  90. u_modelMatrix = model_matrix
  91. u_viewMatrix = view_matrix
  92. u_projectionMatrix = projection_matrix
  93. u_drawRange = draw_range
  94. [attributes]
  95. a_vertex = vertex
  96. a_color = color
  97. a_extruder = extruder
  98. a_line_type = line_type
  99. a_material_color = material_color
  100. a_vertex_index = vertex_index