SunTextureFS.glsl 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. uniform float u_glowLengthTS;
  2. uniform float u_radiusTS;
  3. varying vec2 v_textureCoordinates;
  4. vec2 rotate(vec2 p, vec2 direction)
  5. {
  6. return vec2(p.x * direction.x - p.y * direction.y, p.x * direction.y + p.y * direction.x);
  7. }
  8. vec4 addBurst(vec2 position, vec2 direction)
  9. {
  10. vec2 rotatedPosition = rotate(position, direction) * vec2(25.0, 0.75);
  11. float radius = length(rotatedPosition);
  12. float burst = 1.0 - smoothstep(0.0, 0.55, radius);
  13. return vec4(burst);
  14. }
  15. void main()
  16. {
  17. vec2 position = v_textureCoordinates - vec2(0.5);
  18. float radius = length(position);
  19. float surface = step(radius, u_radiusTS);
  20. vec4 color = vec4(1.0, 1.0, surface + 0.2, surface);
  21. float glow = 1.0 - smoothstep(0.0, 0.55, radius);
  22. color.ba += mix(vec2(0.0), vec2(1.0), glow) * 0.75;
  23. vec4 burst = vec4(0.0);
  24. // The following loop has been manually unrolled for speed, to
  25. // avoid sin() and cos().
  26. //
  27. //for (float i = 0.4; i < 3.2; i += 1.047) {
  28. // vec2 direction = vec2(sin(i), cos(i));
  29. // burst += 0.4 * addBurst(position, direction);
  30. //
  31. // direction = vec2(sin(i - 0.08), cos(i - 0.08));
  32. // burst += 0.3 * addBurst(position, direction);
  33. //}
  34. burst += 0.4 * addBurst(position, vec2(0.38942, 0.92106)); // angle == 0.4
  35. burst += 0.4 * addBurst(position, vec2(0.99235, 0.12348)); // angle == 0.4 + 1.047
  36. burst += 0.4 * addBurst(position, vec2(0.60327, -0.79754)); // angle == 0.4 + 1.047 * 2.0
  37. burst += 0.3 * addBurst(position, vec2(0.31457, 0.94924)); // angle == 0.4 - 0.08
  38. burst += 0.3 * addBurst(position, vec2(0.97931, 0.20239)); // angle == 0.4 + 1.047 - 0.08
  39. burst += 0.3 * addBurst(position, vec2(0.66507, -0.74678)); // angle == 0.4 + 1.047 * 2.0 - 0.08
  40. // End of manual loop unrolling.
  41. color += clamp(burst, vec4(0.0), vec4(1.0)) * 0.15;
  42. gl_FragColor = clamp(color, vec4(0.0), vec4(1.0));
  43. }