-
Notifications
You must be signed in to change notification settings - Fork 0
/
effect.glsl
96 lines (56 loc) · 1.72 KB
/
effect.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
/*
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
*/
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 y*y - x; }
float G(float x, float y){ return x*x - y; }
float df_dx(float x, float y){ return -1; }
float df_dy(float x, float y){ return 2*y; }
float dg_dx(float x, float y){ return 2*x; }
float dg_dy(float x, float y){ return -1; }
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;
}