simulationview_composite.shader 4.0 KB

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