bloom.fs 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #version 330
  2. // Input vertex attributes (from vertex shader)
  3. in vec2 fragTexCoord;
  4. in vec4 fragColor;
  5. // Input uniform values
  6. uniform sampler2D texture0;
  7. uniform vec4 colDiffuse;
  8. // Output fragment color
  9. out vec4 finalColor;
  10. // NOTE: Add here your custom variables
  11. const vec2 size = vec2(800, 450); // render size
  12. const float samples = 5.0; // pixels per axis; higher = bigger glow, worse performance
  13. const float quality = 2.5; // lower = smaller glow, better quality
  14. void main()
  15. {
  16. vec4 sum = vec4(0);
  17. vec2 sizeFactor = vec2(1)/size*quality;
  18. // Texel color fetching from texture sampler
  19. vec4 source = texture(texture0, fragTexCoord);
  20. const int range = 2; // should be = (samples - 1)/2;
  21. for (int x = -range; x <= range; x++)
  22. {
  23. for (int y = -range; y <= range; y++)
  24. {
  25. sum += texture(texture0, fragTexCoord + vec2(x, y)*sizeFactor);
  26. }
  27. }
  28. // Calculate final fragment color
  29. finalColor = ((sum/(samples*samples)) + source)*colDiffuse;
  30. }