opengl_fragment.glsl 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. // based on Phys.Bloom OpenGL tutorial https://learnopengl.com/Guest-Articles/2022/Phys.-Based-Bloom
  2. // and ACM Siggraph talk in 2014 by Jorge Jimenez for Call of Duty: Advanced Warfare.
  3. #define rendered texture0
  4. uniform sampler2D rendered;
  5. uniform vec2 texelSize0;
  6. #ifdef GL_ES
  7. varying mediump vec2 varTexCoord;
  8. #else
  9. centroid varying vec2 varTexCoord;
  10. #endif
  11. void main(void)
  12. {
  13. vec2 tx = 2.0 * texelSize0;
  14. vec3 a = texture2D(rendered, varTexCoord.st + vec2(-1., -1.) * tx).rgb;
  15. vec3 b = texture2D(rendered, varTexCoord.st + vec2(0., -1.) * tx).rgb;
  16. vec3 c = texture2D(rendered, varTexCoord.st + vec2(1., -1.) * tx).rgb;
  17. vec3 d = texture2D(rendered, varTexCoord.st + vec2(-1., 0.) * tx).rgb;
  18. vec3 e = texture2D(rendered, varTexCoord.st + vec2(0., 0.) * tx).rgb;
  19. vec3 f = texture2D(rendered, varTexCoord.st + vec2(1., 0.) * tx).rgb;
  20. vec3 g = texture2D(rendered, varTexCoord.st + vec2(-1., 1.) * tx).rgb;
  21. vec3 h = texture2D(rendered, varTexCoord.st + vec2(0., 1.) * tx).rgb;
  22. vec3 i = texture2D(rendered, varTexCoord.st + vec2(1., 1.) * tx).rgb;
  23. vec3 j = texture2D(rendered, varTexCoord.st + vec2(-0.5, -0.5) * tx).rgb;
  24. vec3 k = texture2D(rendered, varTexCoord.st + vec2(0.5, -0.5) * tx).rgb;
  25. vec3 l = texture2D(rendered, varTexCoord.st + vec2(-0.5, 0.5) * tx).rgb;
  26. vec3 m = texture2D(rendered, varTexCoord.st + vec2(-0.5, 0.5) * tx).rgb;
  27. vec3 color =
  28. (a + c + g + i) * 0.03125 +
  29. (b + d + f + h) * 0.0625 +
  30. (e + j + k + l + m) * 0.125;
  31. gl_FragColor = max(vec4(color, 1.0), 1e-4);
  32. }