lm_blendseams.glsl 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #[versions]
  2. lines = "#define MODE_LINES";
  3. triangles = "#define MODE_TRIANGLES";
  4. #[vertex]
  5. #version 450
  6. #VERSION_DEFINES
  7. #include "lm_common_inc.glsl"
  8. layout(push_constant, std430) uniform Params {
  9. uint base_index;
  10. uint slice;
  11. vec2 uv_offset;
  12. bool debug;
  13. float blend;
  14. uint pad[2];
  15. }
  16. params;
  17. layout(location = 0) out vec3 uv_interp;
  18. void main() {
  19. #ifdef MODE_TRIANGLES
  20. uint triangle_idx = params.base_index + gl_VertexIndex / 3;
  21. uint triangle_subidx = gl_VertexIndex % 3;
  22. vec2 uv;
  23. if (triangle_subidx == 0) {
  24. uv = vertices.data[triangles.data[triangle_idx].indices.x].uv;
  25. } else if (triangle_subidx == 1) {
  26. uv = vertices.data[triangles.data[triangle_idx].indices.y].uv;
  27. } else {
  28. uv = vertices.data[triangles.data[triangle_idx].indices.z].uv;
  29. }
  30. uv_interp = vec3(uv, float(params.slice));
  31. gl_Position = vec4((uv + params.uv_offset) * 2.0 - 1.0, 0.0001, 1.0);
  32. #endif
  33. #ifdef MODE_LINES
  34. uint seam_idx = params.base_index + gl_VertexIndex / 4;
  35. uint seam_subidx = gl_VertexIndex % 4;
  36. uint src_idx;
  37. uint dst_idx;
  38. if (seam_subidx == 0) {
  39. src_idx = seams.data[seam_idx].b.x;
  40. dst_idx = seams.data[seam_idx].a.x;
  41. } else if (seam_subidx == 1) {
  42. src_idx = seams.data[seam_idx].b.y;
  43. dst_idx = seams.data[seam_idx].a.y;
  44. } else if (seam_subidx == 2) {
  45. src_idx = seams.data[seam_idx].a.x;
  46. dst_idx = seams.data[seam_idx].b.x;
  47. } else if (seam_subidx == 3) {
  48. src_idx = seams.data[seam_idx].a.y;
  49. dst_idx = seams.data[seam_idx].b.y;
  50. }
  51. vec2 src_uv = vertices.data[src_idx].uv;
  52. vec2 dst_uv = vertices.data[dst_idx].uv + params.uv_offset;
  53. uv_interp = vec3(src_uv, float(params.slice));
  54. gl_Position = vec4(dst_uv * 2.0 - 1.0, 0.0001, 1.0);
  55. #endif
  56. }
  57. #[fragment]
  58. #version 450
  59. #VERSION_DEFINES
  60. #include "lm_common_inc.glsl"
  61. layout(push_constant, std430) uniform Params {
  62. uint base_index;
  63. uint slice;
  64. vec2 uv_offset;
  65. bool debug;
  66. float blend;
  67. uint pad[2];
  68. }
  69. params;
  70. layout(location = 0) in vec3 uv_interp;
  71. layout(location = 0) out vec4 dst_color;
  72. layout(set = 1, binding = 0) uniform texture2DArray src_color_tex;
  73. void main() {
  74. if (params.debug) {
  75. #ifdef MODE_TRIANGLES
  76. dst_color = vec4(1, 0, 1, 1);
  77. #else
  78. dst_color = vec4(1, 1, 0, 1);
  79. #endif
  80. } else {
  81. vec4 src_color = textureLod(sampler2DArray(src_color_tex, linear_sampler), uv_interp, 0.0);
  82. dst_color = vec4(src_color.rgb, params.blend); //mix
  83. }
  84. }