bloom.frag 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /* bloom.frag -- Fragment shader for applying bloom to the scene
  2. *
  3. * Copyright (c) 2025-2026 Le Juez Victor
  4. *
  5. * This software is provided 'as-is', without any express or implied warranty.
  6. * For conditions of distribution and use, see accompanying LICENSE file.
  7. */
  8. #version 330 core
  9. /* === Definitions === */
  10. #define BLOOM_MIX 1
  11. #define BLOOM_ADDITIVE 2
  12. #define BLOOM_SCREEN 3
  13. /* === Varyings === */
  14. noperspective in vec2 vTexCoord;
  15. /* === Uniforms === */
  16. uniform sampler2D uSceneTex;
  17. uniform sampler2D uBloomTex;
  18. uniform lowp int uBloomMode;
  19. uniform float uBloomIntensity;
  20. /* === Fragments === */
  21. out vec3 FragColor;
  22. /* === Main program === */
  23. void main()
  24. {
  25. vec3 color = texture(uSceneTex, vTexCoord).rgb;
  26. vec3 bloom = texture(uBloomTex, vTexCoord).rgb;
  27. if (uBloomMode == BLOOM_MIX) {
  28. color = mix(color, bloom, uBloomIntensity);
  29. }
  30. else if (uBloomMode == BLOOM_ADDITIVE) {
  31. color += bloom * uBloomIntensity;
  32. }
  33. else if (uBloomMode == BLOOM_SCREEN) {
  34. bloom = clamp(bloom * uBloomIntensity, vec3(0.0), vec3(1.0));
  35. color = max((color + bloom) - (color * bloom), vec3(0.0));
  36. }
  37. FragColor = vec3(color);
  38. }