Chillzy

Untitled

Nov 6th, 2024
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.42 KB | Source Code | 0 0
  1. // Based on: https://github.com/frozein/VkGalaxy/blob/main/assets/shaders/particle.frag
  2. #version 450
  3.  
  4. layout (location = 0) in vec2 in_tex;
  5. layout (location = 1) in float temperature;
  6. layout (location = 2) in flat uint in_type;
  7.  
  8. layout (location = 0) out vec4 out_color;
  9.  
  10. // Based on: https://github.com/zubetto/BlackBodyRadiation
  11. vec4 blackbody(in float temp_in_kel)
  12. {
  13.     if(temp_in_kel <= 0.0)
  14.     {
  15.         return vec4(0.0, 0.0, 0.0, 1.0);
  16.     }
  17.  
  18.     vec4 color = {0.0, 0.0, 0.0, 1.0};
  19.     float kel = temp_in_kel * 500.0;
  20.  
  21.     float u = 0.000536332 * kel;
  22.     color.r = 0.638749 + (u + 1.57533) / (u * u + 0.28664);
  23.  
  24.     u = 0.0019639 * kel;
  25.     color.g = 0.971029 + (u - 10.8015) / (u * u + 6.59002);
  26.  
  27.     float p = 0.00668406 * kel + 23.3962;
  28.     u = 0.000941064 * kel;
  29.     float q = u * u + 0.00100641 * kel + 10.9068;
  30.     color.b = 2.25398 - p / q;
  31.  
  32.     return color;
  33. }
  34.  
  35. void main(void)
  36. {
  37.     vec2 centered_pos = 3.0 * (in_tex - 0.5);
  38.  
  39.     if (in_type == 0)  // Star
  40.     {
  41.         out_color = blackbody(temperature);
  42.     }
  43.  
  44.     else if (in_type == 1) // Dust
  45.     {
  46.         out_color.rgb *= vec3(0.5, 0.5, 1.0);
  47.         out_color.a *= max(1.0 - length(centered_pos), 0.0);
  48.     }
  49.     else // H-2 regions
  50.     {
  51.         float dist = max(1.0 - length(centered_pos), 0.0);
  52.  
  53.         out_color.rgb = mix(vec3(1.0, 0.0, 0.0), vec3(1.0), dist * dist * dist);
  54.         out_color.a = dist * dist;
  55.     }
  56. }
  57.  
Advertisement
Add Comment
Please, Sign In to add comment