SunTextureFS.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. //This file is automatically rebuilt by the Cesium build process.
  2. /*global define*/
  3. define(function() {
  4. "use strict";
  5. return "uniform float u_glowLengthTS;\n\
  6. uniform float u_radiusTS;\n\
  7. \n\
  8. varying vec2 v_textureCoordinates;\n\
  9. \n\
  10. vec2 rotate(vec2 p, vec2 direction)\n\
  11. {\n\
  12. return vec2(p.x * direction.x - p.y * direction.y, p.x * direction.y + p.y * direction.x);\n\
  13. }\n\
  14. \n\
  15. vec4 addBurst(vec2 position, vec2 direction)\n\
  16. {\n\
  17. vec2 rotatedPosition = rotate(position, direction) * vec2(25.0, 0.75);\n\
  18. float radius = length(rotatedPosition);\n\
  19. float burst = 1.0 - smoothstep(0.0, 0.55, radius);\n\
  20. \n\
  21. return vec4(burst);\n\
  22. }\n\
  23. \n\
  24. void main()\n\
  25. {\n\
  26. vec2 position = v_textureCoordinates - vec2(0.5);\n\
  27. float radius = length(position);\n\
  28. float surface = step(radius, u_radiusTS);\n\
  29. vec4 color = vec4(1.0, 1.0, surface + 0.2, surface);\n\
  30. \n\
  31. float glow = 1.0 - smoothstep(0.0, 0.55, radius);\n\
  32. color.ba += mix(vec2(0.0), vec2(1.0), glow) * 0.75;\n\
  33. \n\
  34. vec4 burst = vec4(0.0);\n\
  35. \n\
  36. // The following loop has been manually unrolled for speed, to\n\
  37. // avoid sin() and cos().\n\
  38. //\n\
  39. //for (float i = 0.4; i < 3.2; i += 1.047) {\n\
  40. // vec2 direction = vec2(sin(i), cos(i));\n\
  41. // burst += 0.4 * addBurst(position, direction);\n\
  42. //\n\
  43. // direction = vec2(sin(i - 0.08), cos(i - 0.08));\n\
  44. // burst += 0.3 * addBurst(position, direction);\n\
  45. //}\n\
  46. \n\
  47. burst += 0.4 * addBurst(position, vec2(0.38942, 0.92106)); // angle == 0.4\n\
  48. burst += 0.4 * addBurst(position, vec2(0.99235, 0.12348)); // angle == 0.4 + 1.047\n\
  49. burst += 0.4 * addBurst(position, vec2(0.60327, -0.79754)); // angle == 0.4 + 1.047 * 2.0\n\
  50. \n\
  51. burst += 0.3 * addBurst(position, vec2(0.31457, 0.94924)); // angle == 0.4 - 0.08\n\
  52. burst += 0.3 * addBurst(position, vec2(0.97931, 0.20239)); // angle == 0.4 + 1.047 - 0.08\n\
  53. burst += 0.3 * addBurst(position, vec2(0.66507, -0.74678)); // angle == 0.4 + 1.047 * 2.0 - 0.08\n\
  54. \n\
  55. // End of manual loop unrolling.\n\
  56. \n\
  57. color += clamp(burst, vec4(0.0), vec4(1.0)) * 0.15;\n\
  58. \n\
  59. gl_FragColor = clamp(color, vec4(0.0), vec4(1.0));\n\
  60. }\n\
  61. ";
  62. });