-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathpaletteshader_dunno.txt
68 lines (60 loc) · 1.77 KB
/
paletteshader_dunno.txt
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// helper function, please ignore
number _hue(number s, number t, number h)
{
h = mod(h, 1.);
number six_h = 6.0 * h;
if (six_h < 1.) return (t-s) * six_h + s;
if (six_h < 3.) return t;
if (six_h < 4.) return (t-s) * (4.-six_h) + s;
return s;
}
// input: vec4(h,s,l,a), with h,s,l,a = 0..1
// output: vec4(r,g,b,a), with r,g,b,a = 0..1
vec4 hsl_to_rgb(vec4 c)
{
if (c.y == 0)
return vec4(vec3(c.z), c.a);
number t = (c.z < .5) ? c.y*c.z + c.z : -c.y*c.z + (c.y+c.z);
number s = 2.0 * c.z - t;
return vec4(_hue(s,t,c.x + 1./3.), _hue(s,t,c.x), _hue(s,t,c.x - 1./3.), c.w);
}
// input: vec4(r,g,b,a), with r,g,b,a = 0..1
// output: vec4(h,s,l,a), with h,s,l,a = 0..1
vec4 rgb_to_hsl(vec4 c)
{
number low = min(c.r, min(c.g, c.b));
number high = max(c.r, max(c.g, c.b));
number delta = high - low;
number sum = high+low;
vec4 hsl = vec4(.0, .0, .5 * sum, c.a);
if (delta == .0)
return hsl;
hsl.y = (hsl.z < .5) ? delta / sum : delta / (2.0 - sum);
if (high == c.r)
hsl.x = (c.g - c.b) / delta;
else if (high == c.g)
hsl.x = (c.b - c.r) / delta + 2.0;
else
hsl.x = (c.r - c.g) / delta + 4.0;
hsl.x = mod(hsl.x / 6., 1.);
return hsl;
}
vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords) {
vec4 texturecolor = Texel(texture, texture_coords);
texturecolor = texturecolor * color;
vec4 texturehsb = rgb_to_hsl(texturecolor);
vec4 outc = texturehsb;
//make color closer to tint
if(outc.x > 0.8) outc.x -= 1;
outc.x -= 0.3;
if(outc.z < 0.1) outc.x = outc.x * (0.4);
else outc.x = outc.x * (0.9); //make color more tinted if the color is dark
outc.x += 0.3;
if(outc.x < 0.0) outc.x += 1;
//end
if(outc.y == 0) outc.x = 0.3;
outc.y = max(0.1, outc.y);
outc.z = outc.z * 0.9 + 0.1;
outc = hsl_to_rgb(outc);
return outc;
}