SunTextureFS.js 2.3 KB

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