BrightPass.glsl 838 B

123456789101112131415161718192021222324252627282930
  1. uniform sampler2D colorTexture;
  2. uniform float avgLuminance;
  3. uniform float threshold;
  4. uniform float offset;
  5. varying vec2 v_textureCoordinates;
  6. float key(float avg)
  7. {
  8. float guess = 1.5 - (1.5 / (avg * 0.1 + 1.0));
  9. return max(0.0, guess) + 0.1;
  10. }
  11. // See section 9. "The bright-pass filter" of Realtime HDR Rendering
  12. // http://www.cg.tuwien.ac.at/research/publications/2007/Luksch_2007_RHR/Luksch_2007_RHR-RealtimeHDR%20.pdf
  13. void main()
  14. {
  15. vec4 color = texture2D(colorTexture, v_textureCoordinates);
  16. vec3 xyz = czm_RGBToXYZ(color.rgb);
  17. float luminance = xyz.r;
  18. float scaledLum = key(avgLuminance) * luminance / avgLuminance;
  19. float brightLum = max(scaledLum - threshold, 0.0);
  20. float brightness = brightLum / (offset + brightLum);
  21. xyz.r = brightness;
  22. gl_FragColor = vec4(czm_XYZToRGB(xyz), 1.0);
  23. }