-
-
Notifications
You must be signed in to change notification settings - Fork 172
/
mixOklab.hlsl
49 lines (41 loc) · 1.47 KB
/
mixOklab.hlsl
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
#include "space/srgb2rgb.hlsl"
#include "space/rgb2srgb.hlsl"
#include "space/oklab2rgb.hlsl"
#include "space/rgb2oklab.hlsl"
/*
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: by default colA and colB use linear RGB. If you want to use sRGB define this flag
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(mul(RGB2OKLAB_B, colA), float3(0.33333, 0.33333, 0.33333));
float3 lmsB = pow(mul(RGB2OKLAB_B, colB), float3(0.33333, 0.33333, 0.33333));
float3 lms = lerp( lmsA, lmsB, h );
// cone to rgb
float3 rgb = mul(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), lerp(colA.a, colB.a, h) );
}
#endif