fs_hdr_bright.sc 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. $input v_texcoord0
  2. /*
  3. * Copyright 2011-2025 Branimir Karadzic. All rights reserved.
  4. * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE
  5. */
  6. #include "common.sh"
  7. SAMPLER2D(s_texColor, 0);
  8. SAMPLER2D(s_texLum, 1);
  9. void main()
  10. {
  11. float lum = clamp(decodeRE8(texture2D(s_texLum, v_texcoord0) ), 0.1, 0.7);
  12. vec3 rgb = vec3(0.0, 0.0, 0.0);
  13. rgb += decodeRGBE8(texture2D(s_texColor, v_texcoord0+u_offset[0].xy) );
  14. rgb += decodeRGBE8(texture2D(s_texColor, v_texcoord0+u_offset[1].xy) );
  15. rgb += decodeRGBE8(texture2D(s_texColor, v_texcoord0+u_offset[2].xy) );
  16. rgb += decodeRGBE8(texture2D(s_texColor, v_texcoord0+u_offset[3].xy) );
  17. rgb += decodeRGBE8(texture2D(s_texColor, v_texcoord0+u_offset[4].xy) );
  18. rgb += decodeRGBE8(texture2D(s_texColor, v_texcoord0+u_offset[5].xy) );
  19. rgb += decodeRGBE8(texture2D(s_texColor, v_texcoord0+u_offset[6].xy) );
  20. rgb += decodeRGBE8(texture2D(s_texColor, v_texcoord0+u_offset[7].xy) );
  21. rgb += decodeRGBE8(texture2D(s_texColor, v_texcoord0+u_offset[8].xy) );
  22. rgb *= 1.0/9.0;
  23. float middleGray = u_tonemap.x;
  24. float whiteSqr = u_tonemap.y;
  25. float threshold = u_tonemap.z;
  26. float offset = u_tonemap.w;
  27. rgb = max(vec3_splat(0.0), rgb - threshold) * middleGray / (lum + 0.0001);
  28. rgb = reinhard2(rgb, whiteSqr);
  29. gl_FragColor = toGamma(vec4(rgb, 1.0) );
  30. }