暂无描述

starsphere.frag 1021B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #version 450
  2. #extension GL_ARB_separate_shader_objects : enable
  3. #extension GL_ARB_shading_language_420pack : enable
  4. layout (location = 0) in vec3 inUVW;
  5. layout (location = 0) out vec4 outFragColor;
  6. #define HASHSCALE3 vec3(443.897, 441.423, 437.195)
  7. #define STARFREQUENCY 0.01
  8. // Hash function by Dave Hoskins (https://www.shadertoy.com/view/4djSRW)
  9. float hash33(vec3 p3)
  10. {
  11. p3 = fract(p3 * HASHSCALE3);
  12. p3 += dot(p3, p3.yxz+vec3(19.19));
  13. return fract((p3.x + p3.y)*p3.z + (p3.x+p3.z)*p3.y + (p3.y+p3.z)*p3.x);
  14. }
  15. vec3 starField(vec3 pos)
  16. {
  17. vec3 color = vec3(0.0);
  18. float threshhold = (1.0 - STARFREQUENCY);
  19. float rnd = hash33(pos);
  20. if (rnd >= threshhold)
  21. {
  22. float starCol = pow((rnd - threshhold) / (1.0 - threshhold), 16.0);
  23. color += vec3(starCol);
  24. }
  25. return color;
  26. }
  27. void main()
  28. {
  29. // Fake atmosphere at the bottom
  30. vec3 atmosphere = clamp(vec3(0.1, 0.15, 0.4) * (inUVW.t - 5.0), 0.0, 1.0);
  31. vec3 color = starField(inUVW) + atmosphere;
  32. outFragColor = vec4(color, 1.0);
  33. }