FilmicTonemapping.glsl 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. uniform sampler2D colorTexture;
  2. varying vec2 v_textureCoordinates;
  3. #ifdef AUTO_EXPOSURE
  4. uniform sampler2D autoExposure;
  5. #endif
  6. // See slides 142 and 143:
  7. // http://www.gdcvault.com/play/1012459/Uncharted_2__HDR_Lighting
  8. void main()
  9. {
  10. vec4 fragmentColor = texture2D(colorTexture, v_textureCoordinates);
  11. vec3 color = fragmentColor.rgb;
  12. #ifdef AUTO_EXPOSURE
  13. float exposure = texture2D(autoExposure, vec2(0.5)).r;
  14. color /= exposure;
  15. #endif
  16. const float A = 0.22; // shoulder strength
  17. const float B = 0.30; // linear strength
  18. const float C = 0.10; // linear angle
  19. const float D = 0.20; // toe strength
  20. const float E = 0.01; // toe numerator
  21. const float F = 0.30; // toe denominator
  22. const float white = 11.2; // linear white point value
  23. vec3 c = ((color * (A * color + C * B) + D * E) / (color * ( A * color + B) + D * F)) - E / F;
  24. float w = ((white * (A * white + C * B) + D * E) / (white * ( A * white + B) + D * F)) - E / F;
  25. c = czm_inverseGamma(c / w);
  26. gl_FragColor = vec4(c, fragmentColor.a);
  27. }