-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.s
246 lines (213 loc) · 3.61 KB
/
common.s
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
#include "sound_conf.h"
#include "particle_conf.h"
#define PI 3.1415926
#define FLT_(n) n##.0
#define FLT(n) FLT_(n)
float rand(vec3 pos)
{
vec3 p = pos + vec3(2.);
vec3 fp = fract(p*p.yzx*222.)+vec3(2.);
p.y *= p.z * fp.z;
p.x *= p.y * fp.y;
return
fract
(
p.x*p.x
);
}
vec3 rand3(float pos)
{
float x = pos + 2.;
vec3 p = vec3(x, x*x, x*x*x);
vec3 fp = fract(p*222.)+vec3(2.);
return
fract
(
p*fp.yzx*fp.zxy
);
}
float floorN(float v, float n)
{
return floor(v*n)/n;
}
float floorFract(float v, float n, out float frac)
{
float x = v*n;
float flr = floor(x);
frac = x - flr;
return flr/n;
}
float snd_sin(float t)
{
return sin(2.*PI*t)*0.5+0.5;
}
float softnoise(vec3 pos, float scale)
{
vec3 smplpos = pos*scale;
vec3 nsmplpos = floor(smplpos);
float c000 = rand((nsmplpos+vec3(.0,.0,.0))/scale);
float c100 = rand((nsmplpos+vec3(1.,.0,.0))/scale);
float c010 = rand((nsmplpos+vec3(.0,1.,.0))/scale);
float c110 = rand((nsmplpos+vec3(1.,1.,.0))/scale);
float c001 = rand((nsmplpos+vec3(.0,.0,1.))/scale);
float c101 = rand((nsmplpos+vec3(1.,.0,1.))/scale);
float c011 = rand((nsmplpos+vec3(.0,1.,1.))/scale);
float c111 = rand((nsmplpos+vec3(1.,1.,1.))/scale);
vec3 a = smoothstep(0.0, 1.0, fract(smplpos));
return
mix(
mix(
mix(c000, c100, a.x),
mix(c010, c110, a.x),
a.y
),
mix(
mix(c001, c101, a.x),
mix(c011, c111, a.x),
a.y
),
a.z
);
}
float get_second(float smpl)
{
return smpl/SOUND_SAMPLE_RATE;
}
//t[second]
float narrow_wave2(float t)
{
return max(sin(2.0*PI*(sin(t*0.25)+2.)*t*1.0), 0.0);
}
float pulse_fract(float t)
{
return max(fract(t*2.0)*8.0-7.0, 0.0);
}
float pulse_fract_long(float t)
{
return max(fract(t*2.0), 0.0);
}
float pulse2(float t)
{
return max(sin(2.0*PI*t*2.0)*2.0-1.0, 0.0);
}
float pulse2_1(float t)
{
return max(sin(2.0*PI*t*2.0+3.)*2.0-1.0, 0.0);
}
float pulse_double(float t)
{
return pulse2(t)+pulse2_1(t);
}
float gbl_begin(float t)
{
return max(1.-t*t*0.0625, 0.);
}
float lcl_1(float t)
{
return
floor
(
rand3(floor(t*12.0)/12.0/FLT(SOUND_LENGTH_IN_SECOND)).x
*
12.0
)
/
12.0;
}
float gbl_1a(float t)
{
return
max
(
fract(t/FLT(SOUND_LENGTH_IN_SECOND)*2.+0.75)*4. - 3.,
0.
);
}
float gbl_3a(float t)
{
return
max
(
fract(t/FLT(SOUND_LENGTH_IN_SECOND)*2.+0.25)*4. - 3.,
0.
);
}
float gbl_4a(float t)
{
return
max
(
fract(t/FLT(SOUND_LENGTH_IN_SECOND)*2.+0.)*4. - 3.,
0.
);
}
float gbl_1(float t)
{
return
max
(
sin(4.*PI*t/FLT(SOUND_LENGTH_IN_SECOND))*2.0-1.,
0.
);
}
float gbl_2(float t)
{
return
max
(
sin(4.*PI*t/FLT(SOUND_LENGTH_IN_SECOND) - PI*0.5)*2.0-1.,
0.
);
}
float gbl_3(float t)
{
return
max
(
sin(4.*PI*t/FLT(SOUND_LENGTH_IN_SECOND) - PI*0.5 - PI*0.5)*2.0-1.,
0.
);
}
float gbl_4(float t)
{
return
max
(
sin(4.*PI*t/FLT(SOUND_LENGTH_IN_SECOND) - PI*0.5 - PI*0.5 - PI*0.5)*2.0-1.,
0.
);
}
float gbl_end(float t)
{
float t0 = t - FLT(SOUND_LENGTH_IN_SECOND);
return max(1.-t0*t0*0.0625, 0.);
}
float lengthN(vec3 v, float n)
{
vec3 tmp = pow(abs(v), vec3(n));
return pow(tmp.x+tmp.y+tmp.z, 1/n);
}
float sphereNR(vec3 p, float n, float r)
{
return lengthN(p, n) - r;
}
float DF(vec3 pos)
{
vec3 p = pos - vec3(0.05);
p = fract(p*12.)-vec3(0.5);
return -sphereNR(p, 4., 0.55);
}
vec3 getNormal(vec3 p)
{
float d = 0.0001;
return
normalize
(
vec3
(
DF(p+vec3(d,0,0))-DF(p+vec3(-d,0,0)),
DF(p+vec3(0,d,0))-DF(p+vec3(0,-d,0)),
DF(p+vec3(0,0,d))-DF(p+vec3(0,0,-d))
)
);
}