compositor_pass.frag.glsl 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #version 450
  2. #define _CGrainStatic
  3. // #define _AutoExposure
  4. uniform sampler2D tex;
  5. #ifdef _AutoExposure
  6. uniform sampler2D histogram;
  7. #endif
  8. uniform float vignetteStrength;
  9. in vec2 texCoord;
  10. out vec4 fragColor;
  11. // Based on Filmic Tonemapping Operators http://filmicgames.com/archives/75
  12. vec3 tonemapFilmic(const vec3 color) {
  13. vec3 x = max(vec3(0.0), color - 0.004);
  14. return (x * (6.2 * x + 0.5)) / (x * (6.2 * x + 1.7) + 0.06);
  15. }
  16. void main() {
  17. fragColor = textureLod(tex, texCoord, 0.0);
  18. #ifdef _CGrainStatic
  19. float x = (texCoord.x + 4.0) * (texCoord.y + 4.0) * 10.0;
  20. fragColor.rgb += vec3(mod((mod(x, 13.0) + 1.0) * (mod(x, 123.0) + 1.0), 0.01) - 0.005) * 0.09;
  21. #endif
  22. fragColor.rgb *= (1.0 - vignetteStrength) + vignetteStrength * pow(16.0 * texCoord.x * texCoord.y * (1.0 - texCoord.x) * (1.0 - texCoord.y), 0.2);
  23. #ifdef _AutoExposure
  24. const float autoExposureStrength = 1.0;
  25. float expo = 2.0 - clamp(length(textureLod(histogram, vec2(0.5, 0.5), 0).rgb), 0.0, 1.0);
  26. fragColor.rgb *= pow(expo, autoExposureStrength * 2.0);
  27. #endif
  28. fragColor.rgb = tonemapFilmic(fragColor.rgb); // With gamma
  29. }