dof.frag 864 B

12345678910111213141516171819202122232425262728
  1. /* dof.frag -- Depth of Field composition shader
  2. *
  3. * Copyright (c) 2025 Victor Le Juez
  4. *
  5. * This software is distributed under the terms of the accompanying LICENSE file.
  6. * It is provided "as-is", without any express or implied warranty.
  7. */
  8. #version 330 core
  9. noperspective in vec2 vTexCoord;
  10. uniform sampler2D uSceneTex;
  11. uniform sampler2D uBlurTex;
  12. out vec4 FragColor;
  13. void main()
  14. {
  15. // There can be a tiny 1-pixel "bleeding" around sharp edges.
  16. // This comes from the half-res linear filtering of sharp pixels during upsampling, not from the blur itself.
  17. // One way to completely eliminate this bleeding is to use texelFetch but this creates a blocky pixelated look.
  18. vec4 sharp = texelFetch(uSceneTex, ivec2(gl_FragCoord), 0);
  19. vec4 blur = texture(uBlurTex, vTexCoord);
  20. FragColor = vec4(mix(sharp.rgb, blur.rgb, blur.a), 1.0);
  21. }