Без опису

123456789101112131415161718192021222324252627282930313233343536373839
  1. #version 450
  2. layout (binding = 2) uniform samplerCube samplerEnv;
  3. layout (location = 0) in vec3 inUVW;
  4. layout (location = 0) out vec4 outColor;
  5. layout (binding = 1) uniform UBOParams {
  6. vec4 lights[4];
  7. float exposure;
  8. float gamma;
  9. } uboParams;
  10. // From http://filmicworlds.com/blog/filmic-tonemapping-operators/
  11. vec3 Uncharted2Tonemap(vec3 color)
  12. {
  13. float A = 0.15;
  14. float B = 0.50;
  15. float C = 0.10;
  16. float D = 0.20;
  17. float E = 0.02;
  18. float F = 0.30;
  19. float W = 11.2;
  20. return ((color*(A*color+C*B)+D*E)/(color*(A*color+B)+D*F))-E/F;
  21. }
  22. void main()
  23. {
  24. vec3 color = texture(samplerEnv, inUVW).rgb;
  25. // Tone mapping
  26. color = Uncharted2Tonemap(color * uboParams.exposure);
  27. color = color * (1.0f / Uncharted2Tonemap(vec3(11.2f)));
  28. // Gamma correction
  29. color = pow(color, vec3(1.0f / uboParams.gamma));
  30. outColor = vec4(color, 1.0);
  31. }