stencil.vert 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #version 310 es
  2. // SPDX-License-Identifier: Unlicense OR MIT
  3. #extension GL_GOOGLE_include_directive : enable
  4. precision highp float;
  5. #include "common.h"
  6. layout(push_constant) uniform Block {
  7. vec4 transform;
  8. vec2 pathOffset;
  9. } _block;
  10. layout(location=0) in float corner;
  11. layout(location=1) in float maxy;
  12. layout(location=2) in vec2 from;
  13. layout(location=3) in vec2 ctrl;
  14. layout(location=4) in vec2 to;
  15. layout(location=0) out vec2 vFrom;
  16. layout(location=1) out vec2 vCtrl;
  17. layout(location=2) out vec2 vTo;
  18. void main() {
  19. // Add a one pixel overlap so curve quads cover their
  20. // entire curves. Could use conservative rasterization
  21. // if available.
  22. vec2 from = from + _block.pathOffset;
  23. vec2 ctrl = ctrl + _block.pathOffset;
  24. vec2 to = to + _block.pathOffset;
  25. float maxy = maxy + _block.pathOffset.y;
  26. vec2 pos;
  27. float c = corner;
  28. if (c >= 0.375) {
  29. // North.
  30. c -= 0.5;
  31. pos.y = maxy + 1.0;
  32. } else {
  33. // South.
  34. pos.y = min(min(from.y, ctrl.y), to.y) - 1.0;
  35. }
  36. if (c >= 0.125) {
  37. // East.
  38. pos.x = max(max(from.x, ctrl.x), to.x)+1.0;
  39. } else {
  40. // West.
  41. pos.x = min(min(from.x, ctrl.x), to.x)-1.0;
  42. }
  43. vFrom = from-pos;
  44. vCtrl = ctrl-pos;
  45. vTo = to-pos;
  46. pos = pos*_block.transform.xy + _block.transform.zw;
  47. gl_Position = vec4(transform3x2(fboTransform, vec3(pos, 0)), 1);
  48. }