Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

146 строки
4.0 KiB

  1. const float RING_STRENGTH = 0.0000;
  2. const float RING_BLUR = 0.0030;
  3. const float MARKER_STRENGTH = 0.0000;
  4. const float MARKER_BLUR = 0.0030;
  5. const vec2 VEC_HORZ = vec2(1.0, 0.0);
  6. const float PI = 3.1415926535897932384626433832795;
  7. /**
  8. * Calculate the a double ended smoothstep
  9. *
  10. * b0 --> b1 --> b2 --> b3
  11. * 0.0 1.0 1.0 0.0
  12. */
  13. float smoothstep2(float b0, float b1, float b2, float b3, float v) {
  14. return smoothstep(b0, b1, v) * (1.0 - smoothstep(b2, b3, v));
  15. }
  16. /**
  17. * Calculate a line (vertical or horizonal)
  18. *
  19. * @param actual The current value of the fragment
  20. * @param expected The expected value of the fragment
  21. * @param strength The strength of the line
  22. * @param blur Blur value of the line at the borders
  23. */
  24. float calcLine(float actual, float expected, float strength, float blur) {
  25. return smoothstep2(
  26. expected - strength - blur,
  27. expected - strength,
  28. expected + strength,
  29. expected + strength + blur,
  30. actual);
  31. }
  32. /**
  33. * Calculate the angle between the two passed vectors
  34. */
  35. float calcAngle(vec2 v1, vec2 v2) {
  36. v1 = -v1;
  37. return -atan(
  38. v1.x * v2.y - v1.y * v2.x,
  39. v1.x * v2.x + v1.y * v2.y);
  40. }
  41. /**
  42. * Calculate pseudo random value
  43. */
  44. float random(float seed) {
  45. return fract(sin(dot(vec4(seed), vec4(12.9898, 78.233, 45.164, 53.1324))) * 43758.5453);
  46. }
  47. /**
  48. * Linear animation
  49. *
  50. * @param v0 Start value
  51. * @param v1 End value
  52. * @param t Time in range of 0.0 to 1.0
  53. */
  54. float animLinear(float v0, float v1, float t) {
  55. return v0 + t * (v1 - v0);
  56. }
  57. /**
  58. * Quadric ease in ease out animation
  59. *
  60. * @param v0 Start value
  61. * @param v1 End value
  62. * @param t Time in range of 0.0 to 1.0
  63. */
  64. float animEaseInOutQuadric(float v0, float v1, float t) {
  65. float x = t * t * (3.0 - 2.0 * t);
  66. return v0 + x * (v1 - v0);
  67. }
  68. /**
  69. * Calculate the position of the marker
  70. *
  71. * @param t Animation progress in range 0.0 to 1.0
  72. * @param a Angle of the current fragment
  73. * @param r Radius of the current fragment
  74. * @param zoom Current zoom value
  75. */
  76. float calcMarker(float t, float a, float r, float zoom) {
  77. float m = calcAngle(uMarker, VEC_HORZ);
  78. m = calcLine(a, m, MARKER_STRENGTH / r / zoom, MARKER_BLUR / r / zoom);
  79. m *= smoothstep2(
  80. t * (uRings[0] - 0.25),
  81. t * uRings[0],
  82. t * uRings[1],
  83. t * (uRings[1] + 0.10),
  84. r);
  85. m *= 0.75;
  86. return m;
  87. }
  88. /**
  89. * Calculate the animation value of a ring
  90. *
  91. * @param t Animation progress in range 0.0 to 1.0
  92. * @param a Angle of the current fragment
  93. * @param overfill Overfilling the ring by the given value
  94. */
  95. float calcRingsAnimation(float t, float a, float overfill) {
  96. float t_opn_ring = clamp((t - 0.25) / 0.75, 0.0, 1.0);
  97. float f = a / PI + 1.0;
  98. f = f * 2.0;
  99. f = fract(f + 0.5);
  100. f = smoothstep2(
  101. animLinear(0.4, 0.0 - overfill, t_opn_ring),
  102. animLinear(0.5, 0.1 - overfill, t_opn_ring),
  103. animLinear(0.5, 0.9 + overfill, t_opn_ring),
  104. animLinear(0.6, 1.0 + overfill, t_opn_ring),
  105. f);
  106. return f;
  107. }
  108. /**
  109. * Calculate the value of an ring
  110. *
  111. * @param t Animation progress in range 0.0 to 1.0
  112. * @param anim Animation value calculated by 'calcRingsAnimation'
  113. * @param ring Value / position of the ring
  114. * @param r Radius of the current fragment
  115. * @param zoom Current zoom value
  116. */
  117. float calcRing(float t, float anim, float ring, float r, float zoom) {
  118. return anim * calcLine(r, animEaseInOutQuadric(uSize, ring, t), RING_STRENGTH / zoom, RING_BLUR / zoom);
  119. }
  120. /**
  121. * Calculate the alpha value of the whole rendered primitive
  122. *
  123. * @param t_opn Progress of the start animation in the range of 0.0 to 1.0
  124. * @param t_cls Progress of the close animation in the range of 0.0 to 1.0
  125. */
  126. float calcAlpha(float t_opn, float t_cls) {
  127. float as = (0.5 + 0.5 * step(1.0 - t_opn, random(uProgress)));
  128. float ae = (0.5 + 0.5 * step( t_cls, random(uProgress))) * (1.0 - t_cls);
  129. return as * ae;
  130. }