simulationview_composite.shader 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. [shaders]
  2. vertex =
  3. uniform highp mat4 u_modelViewProjectionMatrix;
  4. attribute highp vec4 a_vertex;
  5. attribute highp vec2 a_uvs;
  6. varying highp vec2 v_uvs;
  7. void main()
  8. {
  9. gl_Position = u_modelViewProjectionMatrix * a_vertex;
  10. v_uvs = a_uvs;
  11. }
  12. fragment =
  13. #ifdef GL_ES
  14. #ifdef GL_FRAGMENT_PRECISION_HIGH
  15. precision highp float;
  16. #else
  17. precision mediump float;
  18. #endif // GL_FRAGMENT_PRECISION_HIGH
  19. #endif // GL_ES
  20. uniform sampler2D u_layer0;
  21. uniform sampler2D u_layer1;
  22. uniform sampler2D u_layer2;
  23. uniform vec2 u_offset[9];
  24. uniform vec4 u_background_color;
  25. uniform vec4 u_background_color_alt;
  26. uniform float u_outline_strength;
  27. uniform vec4 u_outline_color;
  28. varying vec2 v_uvs;
  29. float kernel[9];
  30. const vec3 x_axis = vec3(1.0, 0.0, 0.0);
  31. const vec3 y_axis = vec3(0.0, 1.0, 0.0);
  32. const vec3 z_axis = vec3(0.0, 0.0, 1.0);
  33. void main()
  34. {
  35. // blur kernel
  36. kernel[0] = 0.0; kernel[1] = 1.0; kernel[2] = 0.0;
  37. kernel[3] = 1.0; kernel[4] = -4.0; kernel[5] = 1.0;
  38. kernel[6] = 0.0; kernel[7] = 1.0; kernel[8] = 0.0;
  39. vec4 result = fract((v_uvs.x + v_uvs.y) * 20.0) < 0.5 ? u_background_color : u_background_color - u_background_color_alt;
  40. vec4 main_layer = texture2D(u_layer0, v_uvs);
  41. vec4 selection_layer = texture2D(u_layer1, v_uvs);
  42. vec4 layerview_layer = texture2D(u_layer2, v_uvs);
  43. result = main_layer * main_layer.a + result * (1.0 - main_layer.a);
  44. result = layerview_layer * layerview_layer.a + result * (1.0 - layerview_layer.a);
  45. vec4 sum = vec4(0.0);
  46. for (int i = 0; i < 9; i++)
  47. {
  48. vec4 color = vec4(texture2D(u_layer1, v_uvs.xy + u_offset[i]).a);
  49. sum += color * (kernel[i] / u_outline_strength);
  50. }
  51. if((selection_layer.rgb == x_axis || selection_layer.rgb == y_axis || selection_layer.rgb == z_axis))
  52. {
  53. gl_FragColor = result;
  54. }
  55. else
  56. {
  57. gl_FragColor = mix(result, u_outline_color, abs(sum.a));
  58. }
  59. }
  60. vertex41core =
  61. #version 410
  62. uniform highp mat4 u_modelViewProjectionMatrix;
  63. in highp vec4 a_vertex;
  64. in highp vec2 a_uvs;
  65. out highp vec2 v_uvs;
  66. void main()
  67. {
  68. gl_Position = u_modelViewProjectionMatrix * a_vertex;
  69. v_uvs = a_uvs;
  70. }
  71. fragment41core =
  72. #version 410
  73. uniform sampler2D u_layer0;
  74. uniform sampler2D u_layer1;
  75. uniform sampler2D u_layer2;
  76. uniform vec2 u_offset[9];
  77. uniform vec4 u_background_color;
  78. uniform vec4 u_background_color_alt;
  79. uniform float u_outline_strength;
  80. uniform vec4 u_outline_color;
  81. in vec2 v_uvs;
  82. float kernel[9];
  83. const vec3 x_axis = vec3(1.0, 0.0, 0.0);
  84. const vec3 y_axis = vec3(0.0, 1.0, 0.0);
  85. const vec3 z_axis = vec3(0.0, 0.0, 1.0);
  86. out vec4 frag_color;
  87. void main()
  88. {
  89. // blur kernel
  90. kernel[0] = 0.0; kernel[1] = 1.0; kernel[2] = 0.0;
  91. kernel[3] = 1.0; kernel[4] = -4.0; kernel[5] = 1.0;
  92. kernel[6] = 0.0; kernel[7] = 1.0; kernel[8] = 0.0;
  93. vec4 result = fract((v_uvs.x + v_uvs.y) * 20.0) < 0.5 ? u_background_color : u_background_color - u_background_color_alt;
  94. vec4 main_layer = texture(u_layer0, v_uvs);
  95. vec4 selection_layer = texture(u_layer1, v_uvs);
  96. vec4 layerview_layer = texture(u_layer2, v_uvs);
  97. result = main_layer * main_layer.a + result * (1.0 - main_layer.a);
  98. result = layerview_layer * layerview_layer.a + result * (1.0 - layerview_layer.a);
  99. vec4 sum = vec4(0.0);
  100. for (int i = 0; i < 9; i++)
  101. {
  102. vec4 color = vec4(texture(u_layer1, v_uvs.xy + u_offset[i]).a);
  103. sum += color * (kernel[i] / u_outline_strength);
  104. }
  105. if((selection_layer.rgb == x_axis || selection_layer.rgb == y_axis || selection_layer.rgb == z_axis))
  106. {
  107. frag_color = result;
  108. }
  109. else
  110. {
  111. frag_color = mix(result, u_outline_color, abs(sum.a));
  112. }
  113. }
  114. [defaults]
  115. u_layer0 = 0
  116. u_layer1 = 1
  117. u_layer2 = 2
  118. u_background_color = [0.965, 0.965, 0.965, 1.0]
  119. u_background_color_alt = [0.0, 0.0, 0.0, 0.0]
  120. u_outline_strength = 1.0
  121. u_outline_color = [0.05, 0.66, 0.89, 1.0]
  122. [bindings]
  123. [attributes]
  124. a_vertex = vertex
  125. a_uvs = uv