-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsharp.glsl
96 lines (74 loc) · 2.47 KB
/
sharp.glsl
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
precision mediump float;
uniform sampler2D shampler;
uniform vec2 dims;
uniform vec2 mouse;
varying vec2 uv;
//
// HSV FUNCTIONS
//
vec3 rgb2hsv(vec3 c) {
vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));
vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));
float d = q.x - min(q.w, q.y);
float e = 1.0e-10;
return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
}
vec3 hsv2rgb(vec3 color) {
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
vec3 p = abs(fract(color.xxx + K.xyz) * 6.0 - K.www);
vec3 rgb = vec3(color.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), color.y));
return rgb;
}
void main() {
vec2 tc = uv;
// output
vec4 color = vec4(0.0);
// constant zoom/rotate
float scalex = 0.995 + (0.01 * mouse.x);
float scaley = 0.995 + (0.01 * mouse.y);
float fixangle = 0.001;
tc -= vec2(0.5);
tc *= mat2(scalex, 0.0, 0.0, scaley);
tc *= mat2(cos(fixangle), sin(fixangle), -sin(fixangle), cos(fixangle));
tc += vec2(0.5);
// zoom/rotate based on hue/saturation
vec3 pixel = texture2D(shampler, tc).rgb;
vec3 s = rgb2hsv(pixel);
float angle = ((tc.s + 0.4) * 0.04) * ((s.r * s.g) - 0.5);
angle *= 0.275;
tc -= vec2(0.5);
tc *= mat2(cos(angle), sin(angle), -sin(angle), cos(angle));
tc += vec2(0.5);
float xscale = 1. - (-s.r * 0.009);
float yscale = 1. - (s.g * 0.009);
tc -= vec2(0.5);
tc *= mat2(xscale, 0., 0., yscale);
tc += vec2(0.5);
// these aren't too different...
float d = dot(s.bg, tc);
float e = dot(s.rb, tc.ts);
// d = length(s.bg);
// d = 1.0;
// get a neighboring pixel based on the above value
vec4 prelook = texture2D(shampler, tc + (d * 0.3));
// don't look at me, idk man
d *= prelook.b;
d += length(prelook) / 4.0;
d -= length(s) / 4.0;
// final texture sample
vec4 bc_out = texture2D(shampler, tc + (d * 0.001)) * ((d * 0.001) + 1.0);
// shift hue and saturation
vec3 shift = s;
shift.r += (d / 10.0);
shift.g += (d * 0.08);
// mix between the shifted and repositioned values
float q = 40.0 * (-s.g);
color += mix(bc_out, vec4(hsv2rgb(shift), 1.0), (mouse.x + 0.3) * 0.4);
// spatial differencing using intermediate pixel value (`prelook`)
color += 0.005;
// color *= 1.005;
color *= .99 + (e * .015);
color -= (prelook * 0.02);
gl_FragColor = color;
}