fs_hdr_tonemap.sc 942 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. $input v_texcoord0, v_texcoord1, v_texcoord2, v_texcoord3, v_texcoord4
  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. SAMPLER2D(s_texBlur, 2);
  10. void main()
  11. {
  12. vec3 rgb = decodeRGBE8(texture2D(s_texColor, v_texcoord0) );
  13. float lum = clamp(decodeRE8(texture2D(s_texLum, v_texcoord0) ), 0.1, 0.7);
  14. vec3 Yxy = convertRGB2Yxy(rgb);
  15. float middleGray = u_tonemap.x;
  16. float whiteSqr = u_tonemap.y;
  17. float threshold = u_tonemap.z;
  18. float offset = u_tonemap.w;
  19. float lp = Yxy.x * middleGray / (lum + 0.0001);
  20. Yxy.x = reinhard2(lp, whiteSqr);
  21. rgb = convertYxy2RGB(Yxy);
  22. vec4 blur = blur9(s_texBlur
  23. , v_texcoord0
  24. , v_texcoord1
  25. , v_texcoord2
  26. , v_texcoord3
  27. , v_texcoord4
  28. );
  29. rgb += 0.6 * blur.xyz;
  30. gl_FragColor = toGamma(vec4(rgb, 1.0) );
  31. }