Bloom.glsl 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Copyright (C) 2009-2022, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. ANKI_SPECIALIZATION_CONSTANT_UVEC2(FB_SIZE, 0u);
  6. #include <AnKi/Shaders/TonemappingFunctions.glsl>
  7. #include <AnKi/Shaders/Functions.glsl>
  8. layout(set = 0, binding = 0) uniform sampler u_linearAnyClampSampler;
  9. layout(set = 0, binding = 1) uniform ANKI_RP texture2D u_tex; ///< Its the IS RT
  10. layout(push_constant) uniform b_pc
  11. {
  12. Vec4 u_thresholdScalePad2;
  13. };
  14. const U32 TONEMAPPING_SET = 0u;
  15. const U32 TONEMAPPING_BINDING = 2u;
  16. #include <AnKi/Shaders/TonemappingResources.glsl>
  17. #if defined(ANKI_COMPUTE_SHADER)
  18. const UVec2 WORKGROUP_SIZE = UVec2(16, 16);
  19. layout(local_size_x = WORKGROUP_SIZE.x, local_size_y = WORKGROUP_SIZE.y, local_size_z = 1) in;
  20. layout(set = 0, binding = 3) writeonly uniform image2D u_outImg;
  21. #else
  22. layout(location = 0) in Vec2 in_uv;
  23. layout(location = 0) out ANKI_RP Vec3 out_color;
  24. #endif
  25. void main()
  26. {
  27. #if defined(ANKI_COMPUTE_SHADER)
  28. if(skipOutOfBoundsInvocations(WORKGROUP_SIZE, FB_SIZE))
  29. {
  30. return;
  31. }
  32. const Vec2 uv = (Vec2(gl_GlobalInvocationID.xy) + 0.5) / Vec2(FB_SIZE);
  33. #else
  34. const Vec2 uv = in_uv;
  35. #endif
  36. ANKI_RP F32 weight = 1.0 / 5.0;
  37. ANKI_RP Vec3 color = textureLod(u_tex, u_linearAnyClampSampler, uv, 0.0).rgb * weight;
  38. color += textureLodOffset(sampler2D(u_tex, u_linearAnyClampSampler), uv, 0.0, IVec2(+1, +1)).rgb * weight;
  39. color += textureLodOffset(sampler2D(u_tex, u_linearAnyClampSampler), uv, 0.0, IVec2(-1, -1)).rgb * weight;
  40. color += textureLodOffset(sampler2D(u_tex, u_linearAnyClampSampler), uv, 0.0, IVec2(-1, +1)).rgb * weight;
  41. color += textureLodOffset(sampler2D(u_tex, u_linearAnyClampSampler), uv, 0.0, IVec2(+1, -1)).rgb * weight;
  42. color = tonemap(color, readExposureAndAverageLuminance().y, u_thresholdScalePad2.x) * u_thresholdScalePad2.y;
  43. #if defined(ANKI_COMPUTE_SHADER)
  44. imageStore(u_outImg, IVec2(gl_GlobalInvocationID.xy), Vec4(color, 0.0));
  45. #else
  46. out_color = color;
  47. #endif
  48. }