-
Notifications
You must be signed in to change notification settings - Fork 3
/
foo.txt
154 lines (112 loc) · 5.83 KB
/
foo.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
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
// Number of advection substeps to use. Useful to increase this for large ADVECTION_SCALE. Must be >= 1
// Advection distance multiplier.
// Scales the effect of turbulence on advection.
// Scales the effect of turbulence on velocity. Use small values.
// Scales the effect of vorticity confinement on velocity.
// Scales diffusion.
// Scales the effect of vorticity confinement on advection.
// Scales the effect of divergence on advection.
// Scales the effect of velocity on advection.
// Amount of divergence minimization. Too much will cause instability.
// If 0.0, compute the gradient at (0,0). If 1.0, compute the gradient at the advection distance.
// If 0.0, compute the laplacian at (0,0). If 1.0, compute the laplacian at the advection distance.
// Scales damping force.
// Overall velocity multiplier
// Mixes the previous velocity with the new velocity (range 0..1).
// These control the (an)isotropy of the various kernels
// These define weighting functions applied at each of the scales, i=0 being the finest detail.
////
////
//////
////////
// Scales pressure advection distance.
// // Pressure diffusion.
// Mixes the previous pressure with the new pressure.
// Scales mouse interaction effect
// Scales mouse interaction radius
// If defined, "pump" velocity in the center of the screen. If undefined, alternate pumping from the sides of the screen.
//// Amplitude and cycle time for the "pump" at the center of the screen.
float laplacian_poisson(vec2 fragCoord) {
const float _K0 = -20.0/6.0, _K1 = 4.0/6.0, _K2 = 1.0/6.0;
vec2 texel = 1.0/iResolution.xy;
vec2 uv = fragCoord * texel;
vec4 t = vec4(texel, -texel.y, 0);
float mip = 0.0;
float p = textureLod(POIS_SAMPLER, fract(uv+t.ww), mip).POIS_CH; float p_n = textureLod(POIS_SAMPLER, fract(uv+t.wy), mip).POIS_CH; float p_e = textureLod(POIS_SAMPLER, fract(uv+t.xw), mip).POIS_CH;
float p_s = textureLod(POIS_SAMPLER, fract(uv+t.wz), mip).POIS_CH; float p_w = textureLod(POIS_SAMPLER, fract(uv+-t.xw), mip).POIS_CH; float p_nw = textureLod(POIS_SAMPLER, fract(uv+-t.xz), mip).POIS_CH;
float p_sw = textureLod(POIS_SAMPLER, fract(uv+-t.xy), mip).POIS_CH; float p_ne = textureLod(POIS_SAMPLER, fract(uv+t.xy), mip).POIS_CH; float p_se = textureLod(POIS_SAMPLER, fract(uv+t.xz), mip).POIS_CH;
return _K0 * p + _K1 * (p_e + p_w + p_n + p_s) + _K2 * (p_ne + p_nw + p_se + p_sw);
}
void tex(vec2 uv, inout mat3 mx, inout mat3 my, inout mat3 mp, int degree) {
vec2 texel = 1.0/iResolution.xy;
float stride = float(1 << degree);
float mip = float(degree);
vec4 t = stride * vec4(texel, -texel.y, 0);
vec2 d = textureLod(VORT_SAMPLER, fract(uv+t.ww), mip).VORT_CH; vec2 d_n = textureLod(VORT_SAMPLER, fract(uv+t.wy), mip).VORT_CH; vec2 d_e = textureLod(VORT_SAMPLER, fract(uv+t.xw), mip).VORT_CH;
vec2 d_s = textureLod(VORT_SAMPLER, fract(uv+t.wz), mip).VORT_CH; vec2 d_w = textureLod(VORT_SAMPLER, fract(uv+-t.xw), mip).VORT_CH; vec2 d_nw = textureLod(VORT_SAMPLER, fract(uv+-t.xz), mip).VORT_CH;
vec2 d_sw = textureLod(VORT_SAMPLER, fract(uv+-t.xy), mip).VORT_CH; vec2 d_ne = textureLod(VORT_SAMPLER, fract(uv+t.xy), mip).VORT_CH; vec2 d_se = textureLod(VORT_SAMPLER, fract(uv+t.xz), mip).VORT_CH;
float p = textureLod(POIS_SAMPLER, fract(uv+t.ww), mip).POIS_CH; float p_n = textureLod(POIS_SAMPLER, fract(uv+t.wy), mip).POIS_CH; float p_e = textureLod(POIS_SAMPLER, fract(uv+t.xw), mip).POIS_CH;
float p_s = textureLod(POIS_SAMPLER, fract(uv+t.wz), mip).POIS_CH; float p_w = textureLod(POIS_SAMPLER, fract(uv+-t.xw), mip).POIS_CH; float p_nw = textureLod(POIS_SAMPLER, fract(uv+-t.xz), mip).POIS_CH;
float p_sw = textureLod(POIS_SAMPLER, fract(uv+-t.xy), mip).POIS_CH; float p_ne = textureLod(POIS_SAMPLER, fract(uv+t.xy), mip).POIS_CH; float p_se = textureLod(POIS_SAMPLER, fract(uv+t.xz), mip).POIS_CH;
mx = mat3(d_nw.x, d_n.x, d_ne.x,
d_w.x, d.x, d_e.x,
d_sw.x, d_s.x, d_se.x);
my = mat3(d_nw.y, d_n.y, d_ne.y,
d_w.y, d.y, d_e.y,
d_sw.y, d_s.y, d_se.y);
mp = mat3(p_nw, p_n, p_ne,
p_w, p, p_e,
p_sw, p_s, p_se);
}
float reduce(mat3 a, mat3 b) {
mat3 p = matrixCompMult(a, b);
return p[0][0] + p[0][1] + p[0][2] +
p[1][0] + p[1][1] + p[1][2] +
p[2][0] + p[2][1] + p[2][2];
}
vec2 pois(vec2 fragCoord)
{
vec2 uv = fragCoord.xy / iResolution.xy;
float k0 = 0.16 // [0..0.5];
float k1 = 1.0 - 2.0*(0.16 // [0..0.5]);
mat3 pois_x = mat3(
k0, 0.0, -k0,
k1, 0.0, -k1,
k0, 0.0, -k0
);
mat3 pois_y = mat3(
-k0, -k1, -k0,
0.0, 0.0, 0.0,
k0, k1, k0
);
mat3 gauss = mat3(
0.0625, 0.125, 0.0625,
0.125, 0.25, 0.125,
0.0625, 0.125, 0.0625
);
mat3 mx, my, mp;
vec2 v = vec2(0);
float wc = 0.0;
for (int i = 0; i < DEGREE; i++) {
tex(uv, mx, my, mp, i);
float w = 1.0;
wc += w;
v += w * vec2(reduce(pois_x, mx) + reduce(pois_y, my), reduce(gauss, mp));
}
return v / wc;
}
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
vec2 p = pois(fragCoord);
if (USE_PRESSURE_ADVECTION) {
float mip = 0.0;
vec2 tx = 1.0 / iResolution.xy;
vec2 uv = fragCoord * tx;
float prev = textureLod(POIS_SAMPLER, fract(uv+0.0002 * 0.0002 * tx * textureLod(VORT_SAMPLER, fract(uv+vec2(0)), mip).zw), mip).POIS_CH;
fragColor = vec4(mix(p.x + p.y, prev + 0.1 // [0..0.3] higher values more likely to cause blowup * laplacian_poisson(fragCoord), 0.0 // [0..1]));
} else {
fragColor = vec4(p.x + p.y);
}
// Adding a very small amount of noise on init fixes subtle numerical precision blowup problems
if (iFrame==0) fragColor=1e-6*rand4(fragCoord, iResolution.xy, iFrame);
}