-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathautoeffect.glsl
More file actions
111 lines (68 loc) · 2.05 KB
/
autoeffect.glsl
File metadata and controls
111 lines (68 loc) · 2.05 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
Vector field visualization script.
(relative btw)
Red channel indicates divergence at each point
Blue channel indicates curl at each point
Green channel indicates magnitude of each vector
This shader uses automatic differentiation in the form
of taking finite differences and calculating the gradient
from there.
The step size used is capped at 0.002 for now
*/
uniform float dscale;
uniform float doffset;
uniform float cscale;
uniform float coffset;
uniform float mscale;
uniform float moffset;
uniform float sx;
uniform float sy;
uniform float w;
uniform float h;
uniform float CAP;
float F(float x, float y){ return sin(y) - cos(x*x); }
float G(float x, float y){ return cos(x) - sin(y*y); }
float df_dx(float x, float y){
return (F(x+0.001,y) - F(x-0.001,y))/0.002;
}
float df_dy(float x, float y){
return (F(x,y-0.001) - F(x,y+0.001))/0.002;
}
float dg_dx(float x, float y){
return (G(x+0.001,y) - G(x-0.001,y))/0.002;
}
float dg_dy(float x, float y){
return (G(x,y+0.001) - G(x,y-0.001))/0.002;
}
float magnitude(float x, float y){
vec2 mag;
mag.x = F(x,y);
mag.y = G(x,y);
return (length(mag)-moffset)/mscale;
}
float curl(float x, float y){
return ((dg_dx(x,y) - df_dy(x,y))-coffset)/cscale;
}
float divergence(float x, float y){
return ((df_dx(x,y) + dg_dy(x,y))-doffset)/dscale;
}
vec2 plotCords(float X, float Y, float sx, float sy, float w, float h){
Y = CAP - Y;//invert, because in love2d, y=0 is at top
vec2 ret = vec2(0.0,0.0);
ret[0] = w * (X / CAP) + sx;
ret[1] = h * (Y / CAP) + sy;
return ret;
}
vec4 effect(vec4 color, Image tex, vec2 texture_coords, vec2 screen_coords)
{
vec2 vc;
vc = plotCords(screen_coords.x, screen_coords.y, sx, sy, w, h);
vec4 mod;
mod.x = 0.5-(divergence(vc.x, vc.y)); // r For some reason this is -inf :/
mod.y = 0.5-(curl(vc.x,vc.y)); // b NVM fixed
mod.z = 0.5-(magnitude(vc.x, vc.y)); // g
mod.w = 1;
vec4 tc;
tc = Texel(tex, texture_coords);
return mod * color * tc;
}