SHARE
TWEET

White Point Adaptation + ACES

a guest Jul 18th, 2019 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #version 150
  2.  
  3. uniform sampler2D source[];
  4. in Vertex { vec2 texCoord; };
  5. out vec4 fragColor;
  6.  
  7. const mat3x3 XYZ_to_LMS = mat3x3(0.7328, 0.4296, -0.1624, -0.7036, 1.6975, 0.0061, 0.0030, 0.0136, 0.9834);
  8.  
  9. const mat3x3 LMS_to_XYZ = mat3x3(1.09612382083551, -0.278869000218287, 0.182745179382773, 0.454369041975359, 0.473533154307412, 0.0720978037172291, -0.00962760873842935, -0.00569803121611342, 1.01532563995454);
  10.  
  11. const vec3 D65 = vec3(0.9504, 1.0000, 1.0888);
  12. const vec3 D9300 = vec3(0.95271,1.00000,1.39177);
  13.  
  14. //  ---  sRGB and XYZ  ---  //{
  15. vec3 XYZ_to_sRGB(vec3 x) {
  16.     x = x * mat3x3( 3.2404542, -1.5371385, -0.4985314, -0.9692660, 1.8760108, 0.0415560, 0.0556434, -0.2040259, 1.0572252 );
  17.     x = mix(1.055*pow(x, vec3(1./2.4)) - 0.055, 12.92*x, step(x,vec3(0.0031308)));
  18.     return x;
  19. }
  20.  
  21. vec3 sRGB_to_XYZ(vec3 x) {
  22.     x = mix(pow((x + 0.055)/1.055,vec3(2.4)), x / 12.92, step(x,vec3(0.04045)));
  23.     x = x * mat3x3( 0.4124564, 0.3575761, 0.1804375, 0.2126729, 0.7151522, 0.0721750, 0.0193339, 0.1191920, 0.9503041 );
  24.     return x;
  25. }
  26. //}
  27.  
  28. //  ---  XYZ and ACES  ---  //{
  29. const mat3x3 XYZ_to_ACES = mat3x3(1.0498110175, 0.0, -0.0000974845, -0.4959030231, 1.3733130458, 0.0982400361, 0.0, 0.0, 0.9912520182);
  30. const mat3x3 ACES_to_XYZ = mat3x3(0.9525523959, 0.0000000000, 0.0000936786, 0.3439664498, 0.7281660966, -0.0721325464, 0.0000000000, 0.0000000000, 1.0088251844);
  31. //}
  32.  
  33. vec3 Adapt(vec3 Photo) {
  34.     vec3 D65LMS = D65 * XYZ_to_LMS;
  35.     vec3 D9300LMS = D9300 * XYZ_to_LMS;
  36.     Photo = sRGB_to_XYZ(Photo) * XYZ_to_LMS;
  37.     Photo = Photo * (D9300LMS / D65LMS);
  38.     Photo = XYZ_to_sRGB(Photo * LMS_to_XYZ);
  39.     return Photo;
  40. }
  41.  
  42. vec3 AdaptACES(vec3 Photo) {
  43.     Photo = sRGB_to_XYZ(Photo) * XYZ_to_ACES;
  44.     Photo = pow(Photo,vec3(1.0/0.89, 1.0/0.93, 1.0/1.20));
  45.     Photo = XYZ_to_sRGB(Photo * ACES_to_XYZ);
  46.     return Photo;
  47. }
  48.  
  49. void main() {
  50.     vec3 Picture = texture(source[0], texCoord).xyz;
  51.    
  52.     Picture = Adapt(Picture);
  53.     //Picture = AdaptACES(Picture);
  54.  
  55.     fragColor = vec4(Picture,1.0);
  56. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top