• Sign Up
• Login
• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# White Point Adaptation

a guest Jul 18th, 2019 58 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. vec3 Adapt(vec3 Photo) {
29.     vec3 D65LMS = D65 * XYZ_to_LMS;
30.     vec3 D9300LMS = D9300 * XYZ_to_LMS;
31.     Photo = sRGB_to_XYZ(Photo) * XYZ_to_LMS;
32.     Photo = Photo * (D9300LMS / D65LMS);
33.     Photo = XYZ_to_sRGB(Photo * LMS_to_XYZ);
34.     return Photo;
35. }
36.
37. void main() {
38.     vec3 Picture = texture(source[0], texCoord).xyz;
39.
40.     Picture = Adapt(Picture);
41.
42.     fragColor = vec4(Picture,1.0);
43. }
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.
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!

Top