xray_composite.shader 4.2 KB

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