Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

114 rader
4.0 KiB

  1. #version 450 core
  2. #pragma include ./shared.glsl
  3. #pragma include ../misc/camera.glsl
  4. in FragmentData fragmentData;
  5. layout (location = 1) uniform vec2 uRings;
  6. layout (location = 2) uniform vec2 uMarker;
  7. layout (location = 3) uniform vec4 uValue;
  8. layout (location = 4) uniform float uProgress;
  9. layout (location = 5) uniform float uSize;
  10. out vec4 outColor;
  11. #pragma include ./shared_frag.glsl
  12. /**
  13. * Calculate the splitter animation
  14. *
  15. * @param t Animation process in range [0.0, 1.0]
  16. * @param r Radius of the current fragment
  17. *
  18. * @return The animation value of splitters
  19. */
  20. float calcSplitterAnimation(float t, float r) {
  21. return smoothstep2(
  22. animLinear(1.1 * uRings[0], (uRings[0] - 0.05), t),
  23. animLinear(1.1 * uRings[0], uRings[0], t),
  24. animLinear(1.1 * uRings[0], uRings[1], t),
  25. animLinear(1.1 * uRings[0], (uRings[1] + 0.05), t),
  26. r);
  27. }
  28. /**
  29. * Calculate the value of a splitter
  30. *
  31. * @param pi Position of the splitter as multiple of PI / 4
  32. * @param anim Animation value calculated by 'calcSplitterAnimation'
  33. * @param a Angle of the current fragment
  34. * @param r Radius of the current fragment
  35. * @param zoom Current zoom factor
  36. *
  37. * @return Splitter value.
  38. */
  39. float calcSplitter(float pi, float anim, float a, float r, float zoom) {
  40. return anim * calcLine(a, pi * PI / 4.0, MARKER_STRENGTH / r / zoom, MARKER_BLUR / r / zoom);
  41. }
  42. /**
  43. * Calculate the value of a ring that represents a given ship count value
  44. *
  45. * @param pi0 Position to start the value ring at as multiple of PI / 4
  46. * @param pi1 Position to end the value ring at as multiple of PI / 4
  47. * @param angle Angle of the current fragment
  48. * @param t Animation process in range [0.0, 1.0]
  49. * @param anim Animation value calculated by 'calcSplitterAnimation'
  50. * @param value Actual value of the ring
  51. * @param r Radius of the current fragment
  52. * @param zoom Current zoom factor
  53. *
  54. * @return Value of the value ring
  55. */
  56. float calcValueRing(float pi0, float pi1, float angle, float t, float anim, float value, float r, float zoom) {
  57. float x = animLinear(uRings[0], uRings[1], value);
  58. x = anim * calcLine(r, animEaseInOutQuadric(uSize, x, t), RING_STRENGTH / zoom, RING_BLUR / zoom);
  59. if (pi0 < pi1) {
  60. x *= step( pi0 * PI / 4.0, angle) * step(angle, pi1 * PI / 4.0);
  61. } else {
  62. x *= step( pi0 * PI / 4.0, angle) + step(angle, pi1 * PI / 4.0);
  63. }
  64. return x;
  65. }
  66. void main() {
  67. /* setup */
  68. float t_opn = clamp(uProgress, 0.0, 1.0);
  69. float t_cls = clamp(uProgress - 1.0, 0.0, 1.0);
  70. float r = length(fragmentData.texCoords);
  71. float zoom = pow(length(uCamera.view[0].xyz), 0.5);
  72. float angle = calcAngle(fragmentData.texCoords, VEC_HORZ);
  73. /* marker */
  74. float m = calcMarker(t_opn, angle, r, zoom);
  75. /* splitter */
  76. float x = calcSplitterAnimation(t_opn, r);
  77. float s0 = 0.25 * calcSplitter( 3.0, x, angle, r, zoom);
  78. float s1 = 0.25 * calcSplitter( 1.0, x, angle, r, zoom);
  79. float s2 = 0.25 * calcSplitter(-1.0, x, angle, r, zoom);
  80. float s3 = 0.25 * calcSplitter(-3.0, x, angle, r, zoom);
  81. /* rings */
  82. float f = calcRingsAnimation(t_opn, angle, 0.0);
  83. float t_opn_rad = clamp(2.0 * t_opn, 0.0, 1.0);
  84. float r0 = 0.25 * calcRing(t_opn_rad, f, uRings[0], r, zoom);
  85. float r1 = 0.25 * calcRing(t_opn_rad, f, uRings[1], r, zoom);
  86. float v0 = 0.75 * calcValueRing( 3.0, -3.0, angle, t_opn_rad, f, uValue[0], r, zoom);
  87. float v1 = 0.75 * calcValueRing( 1.0, 3.0, angle, t_opn_rad, f, uValue[1], r, zoom);
  88. float v2 = 0.75 * calcValueRing(-1.0, 1.0, angle, t_opn_rad, f, uValue[2], r, zoom);
  89. float v3 = 0.75 * calcValueRing(-3.0, -1.0, angle, t_opn_rad, f, uValue[3], r, zoom);
  90. /* alpha */
  91. float a = calcAlpha(t_opn, t_cls);
  92. /* put together */
  93. vec3 rgb = vec3(1.0);
  94. outColor = vec4(rgb, (v0 + v1 + v2 + v3 + r0 + r1 + m + s0 + s1 + s2 + s3) * a + uSize * 0.0001);
  95. }