-
-
Notifications
You must be signed in to change notification settings - Fork 172
/
mixOklab.msl
51 lines (42 loc) · 1.39 KB
/
mixOklab.msl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "space/srgb2rgb.msl"
#include "space/rgb2srgb.msl"
#include "space/oklab2rgb.msl"
#include "space/rgb2oklab.msl"
/*
contributors: [Bjorn Ottosson, Inigo Quiles]
description: |
Mix function by Inigo Quiles (https://www.shadertoy.com/view/ttcyRS)
utilizing Bjorn Ottosso's OkLab color space, which is provide smooth stransitions
Learn more about it [his article](https://bottosson.github.io/posts/oklab/)
use: <float3\float4> mixOklab(<float3|float4> colorA, <float3|float4> colorB, float pct)
options:
- MIXOKLAB_SRGB: color argument are sRGB and returns sRGB
examples:
- /shaders/color_mix.frag
license:
- MIT License (MIT) Copyright (c) 2020 Björn Ottosson
- MIT License (MIT) Copyright (c) 2020 Inigo Quilez
*/
#ifndef FNC_MIXOKLAB
#define FNC_MIXOKLAB
float3 mixOklab( float3 colA, float3 colB, float h ) {
#ifdef MIXOKLAB_SRGB
colA = srgb2rgb(colA);
colB = srgb2rgb(colB);
#endif
float3 lmsA = pow( RGB2OKLAB_B * colA, float3(0.33333) );
float3 lmsB = pow( RGB2OKLAB_B * colB, float3(0.33333) );
// lerp
float3 lms = mix( lmsA, lmsB, h );
// cone to rgb
float3 rgb = OKLAB2RGB_B*(lms*lms*lms);
#ifdef MIXOKLAB_SRGB
return rgb2srgb(rgb);
#else
return rgb;
#endif
}
float4 mixOklab( float4 colA, float4 colB, float h ) {
return float4( mixOklab(colA.rgb, colB.rgb, h), mix(colA.a, colB.a, h) );
}
#endif