layerview_composite.shader 3.8 KB

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