common.sh 618 B

12345678910111213141516171819202122232425262728
  1. /*
  2. * Copyright 2011-2018 Branimir Karadzic. All rights reserved.
  3. * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
  4. */
  5. #include <bgfx_shader.sh>
  6. uniform vec4 u_params;
  7. #define u_textureLod u_params.x
  8. #define u_textureLayer u_params.y
  9. #define u_inLinear u_params.z
  10. #define u_ev u_params.w
  11. vec3 toLinear(vec3 _rgb)
  12. {
  13. return pow(abs(_rgb), vec3_splat(2.2) );
  14. }
  15. vec3 toGamma(vec3 _rgb)
  16. {
  17. return pow(abs(_rgb), vec3_splat(1.0/2.2) );
  18. }
  19. vec4 toEv(vec4 _color)
  20. {
  21. vec3 rgb = mix(toLinear(_color.xyz), _color.xyz, u_inLinear);
  22. return vec4(toGamma(rgb * pow(2.0, u_ev) ), _color.w);
  23. }