-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
333 lines (280 loc) · 9.53 KB
/
index.html
File metadata and controls
333 lines (280 loc) · 9.53 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
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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>TransformFeedback</title>
<script src="https://wgld.org/j/minMatrixb.js" type="text/javascript"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/stats.js/r16/Stats.min.js" type="text/javascript"></script>
<link href="https://fonts.googleapis.com/css2?family=Sen:wght@700&display=swap" rel="stylesheet">
<script src="main.js" type="text/javascript"></script>
<script id="vs_transform" type="x-shader/x-vertex">#version 300 es
#define PI 3.1415926535
layout (location = 0) in vec4 position;
layout (location = 1) in vec3 velocity;
uniform float uTime;
uniform float uRange;
uniform float uLifeStep;
uniform float uAmplitude;
out vec4 vPosition;
out vec3 vVelocity;
float random (vec2 st) {
return fract(sin(dot(st.xy, vec2(12.9898, 78.233))) * 43758.5453123);
}
// snoise 4D
vec4 mod289(vec4 x) {
return x - floor(x * (1.0 / 289.0)) * 289.0; }
float mod289(float x) {
return x - floor(x * (1.0 / 289.0)) * 289.0; }
vec4 permute(vec4 x) {
return mod289(((x*34.0)+1.0)*x);
}
float permute(float x) {
return mod289(((x*34.0)+1.0)*x);
}
vec4 taylorInvSqrt(vec4 r)
{
return 1.79284291400159 - 0.85373472095314 * r;
}
float taylorInvSqrt(float r)
{
return 1.79284291400159 - 0.85373472095314 * r;
}
vec4 grad4(float j, vec4 ip)
{
const vec4 ones = vec4(1.0, 1.0, 1.0, -1.0);
vec4 p,s;
p.xyz = floor( fract (vec3(j) * ip.xyz) * 7.0) * ip.z - 1.0;
p.w = 1.5 - dot(abs(p.xyz), ones.xyz);
s = vec4(lessThan(p, vec4(0.0)));
p.xyz = p.xyz + (s.xyz*2.0 - 1.0) * s.www;
return p;
}
// (sqrt(5) - 1)/4 = F4, used once below
#define F4 0.309016994374947451
float snoise(vec4 v)
{
const vec4 C = vec4( 0.138196601125011, // (5 - sqrt(5))/20 G4
0.276393202250021, // 2 * G4
0.414589803375032, // 3 * G4
-0.447213595499958); // -1 + 4 * G4
// First corner
vec4 i = floor(v + dot(v, vec4(F4)) );
vec4 x0 = v - i + dot(i, C.xxxx);
// Other corners
// Rank sorting originally contributed by Bill Licea-Kane, AMD (formerly ATI)
vec4 i0;
vec3 isX = step( x0.yzw, x0.xxx );
vec3 isYZ = step( x0.zww, x0.yyz );
// i0.x = dot( isX, vec3( 1.0 ) );
i0.x = isX.x + isX.y + isX.z;
i0.yzw = 1.0 - isX;
// i0.y += dot( isYZ.xy, vec2( 1.0 ) );
i0.y += isYZ.x + isYZ.y;
i0.zw += 1.0 - isYZ.xy;
i0.z += isYZ.z;
i0.w += 1.0 - isYZ.z;
// i0 now contains the unique values 0,1,2,3 in each channel
vec4 i3 = clamp( i0, 0.0, 1.0 );
vec4 i2 = clamp( i0-1.0, 0.0, 1.0 );
vec4 i1 = clamp( i0-2.0, 0.0, 1.0 );
// x0 = x0 - 0.0 + 0.0 * C.xxxx
// x1 = x0 - i1 + 1.0 * C.xxxx
// x2 = x0 - i2 + 2.0 * C.xxxx
// x3 = x0 - i3 + 3.0 * C.xxxx
// x4 = x0 - 1.0 + 4.0 * C.xxxx
vec4 x1 = x0 - i1 + C.xxxx;
vec4 x2 = x0 - i2 + C.yyyy;
vec4 x3 = x0 - i3 + C.zzzz;
vec4 x4 = x0 + C.wwww;
// Permutations
i = mod289(i);
float j0 = permute( permute( permute( permute(i.w) + i.z) + i.y) + i.x);
vec4 j1 = permute( permute( permute( permute (
i.w + vec4(i1.w, i2.w, i3.w, 1.0 ))
+ i.z + vec4(i1.z, i2.z, i3.z, 1.0 ))
+ i.y + vec4(i1.y, i2.y, i3.y, 1.0 ))
+ i.x + vec4(i1.x, i2.x, i3.x, 1.0 ));
// Gradients: 7x7x6 points over a cube, mapped onto a 4-cross polytope
// 7*7*6 = 294, which is close to the ring size 17*17 = 289.
vec4 ip = vec4(1.0/294.0, 1.0/49.0, 1.0/7.0, 0.0) ;
vec4 p0 = grad4(j0, ip);
vec4 p1 = grad4(j1.x, ip);
vec4 p2 = grad4(j1.y, ip);
vec4 p3 = grad4(j1.z, ip);
vec4 p4 = grad4(j1.w, ip);
// Normalize gradients
vec4 norm = taylorInvSqrt(vec4(dot(p0,p0), dot(p1,p1), dot(p2, p2), dot(p3,p3)));
p0 *= norm.x;
p1 *= norm.y;
p2 *= norm.z;
p3 *= norm.w;
p4 *= taylorInvSqrt(dot(p4,p4));
// Mix contributions from the five corners
vec3 m0 = max(0.6 - vec3(dot(x0,x0), dot(x1,x1), dot(x2,x2)), 0.0);
vec2 m1 = max(0.6 - vec2(dot(x3,x3), dot(x4,x4) ), 0.0);
m0 = m0 * m0;
m1 = m1 * m1;
return 49.0 * ( dot(m0*m0, vec3( dot( p0, x0 ), dot( p1, x1 ), dot( p2, x2 )))
+ dot(m1*m1, vec2( dot( p3, x3 ), dot( p4, x4 ) ) ) ) ;
}
void main(void) {
float t = uTime;
vec3 vel = velocity;
vec3 pos = position.xyz;
float life = position.w;
life -= uLifeStep;
if (life < 0.0) {
pos = vec3(random(vec2(uTime)), random(vec2(0.0, uTime)), random(vec2(uTime, 0.0))) * uRange - uRange * 0.5;
life = 1.0;
}
pos += vel * uAmplitude;
vel += 0.05 * vec3(
snoise(vec4(0.3 * pos.xyz, 7.255 + t)),
snoise(vec4(0.4 * pos.yzx, 3.553 + t)),
snoise(vec4(0.5 * pos.zxy, 1.259 + t))
);
vPosition = vec4(pos, life);
vVelocity = vel;
}
</script>
<script id="fs_transform" type="x-shader/x-fragment">#version 300 es
precision highp float;
out vec4 outColor;
void main(void){
outColor = vec4(1.0);
}
</script>
<script id="vs_main" type="x-shader/x-vertex">#version 300 es
layout (location = 0) in vec4 iPosition;
layout (location = 1) in vec3 iVelocity;
uniform mat4 mvpMatrix;
out vec4 vPosition;
out vec3 vVelocity;
void main(void){
vPosition = iPosition;
vVelocity = iVelocity;
gl_Position = mvpMatrix * vec4(iPosition.xyz, 1.0);
gl_PointSize = 1.0;
}
</script>
<script id="fs_main" type="x-shader/x-fragment">#version 300 es
precision highp float;
in vec4 vPosition;
in vec3 vVelocity;
uniform bool isColor;
#define PI 3.1415926535
out vec4 outColor;
float random (vec2 st) {
return fract(sin(dot(st.xy, vec2(12.9898, 78.233))) * 43758.5453123);
}
vec3 hsv2rgb(float h, float s, float v) {
h = mod(h, 360.0);
if (s == 0.0) {
return vec3(0.0, 0.0, 0.0);
}
float c = v * s;
float i = h / 60.0;
float x = c * (1.0 - abs(mod(i, 2.0) - 1.0));
return vec3(v - c) + (i < 1.0 ? vec3(c, x, 0.0) :
i < 2.0 ? vec3(x, c, 0.0) :
i < 3.0 ? vec3(0.0, c, x) :
i < 4.0 ? vec3(0.0, x, c) :
i < 5.0 ? vec3(x, 0.0, c) :
vec3(c, 0.0, x));
}
void main(void) {
float rad = atan(vVelocity.y, vVelocity.x) + PI;
float hue = 360.0 * rad / (2.0 * PI);
float brightness = min(1.0, length(vVelocity.xy) / 0.5);
vec3 hsv = hsv2rgb(hue, 1.0, brightness);
vec3 mono = vec3(random(vPosition.xy) * 0.3 + 0.7);
vec3 color = vec3(0.0);
if (isColor) {
color = hsv;
} else {
color = mono;
}
outColor = vec4(color, 1.0);
}
</script>
</head>
<body>
<canvas id="canvas"></canvas>
<div id="container"></div>
<h1>TransformFeedback</h1>
<div id="parameter_container">
<div class="parameter"><div class="parameter_name">Color<input type="checkbox" id="color"/><span id="disp_color" class="value"></span></div></div><br>
<div class="parameter"><div class="parameter_name">Birth Range<span id="disp_birth_range" class="value"></span></div><input type="range" id="birth_range" min="1.0" max="15.0" value="15.0" step="0.1"/></div><br>
<div class="parameter"><div class="parameter_name">Point Num<span id="disp_point_num" class="value"></span></div><input type="range" id="point_num" min="10000" max="1000000" value="100000" step="10"/></div><br>
<div class="parameter"><div class="parameter_name">Life Step<span id="disp_life_step" class="value"></span></div><input type="range" id="life_step" min="0.001" max="0.01" value="0.01" step="0.00001"/></div><br>
<div class="parameter"><div class="parameter_name">Amplitude<span id="disp_amplitude" class="value"></span></div><input type="range" id="amplitude" min="0.001" max="0.01" value="0.01" step="0.001"/></div><br>
</div>
</body>
</html>
<style>
#container {
padding-top: 50px;
position: fixed;
}
canvas {
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
margin: auto;
}
#parameter_container {
background: rgba(20, 20, 20, 0.95);
border-radius: 3%;
padding: 2% 2.5%;
width: calc(10% + 120px);
font-family: 'Sen';
font-size: calc(0.75vw + 11.35px);
font-weight: 700;
color: white;
position: fixed;
display: block;
right: 50px;
transition: all 500ms;
}
.parameter_name {
width: 100%;
padding-bottom: 10px;
}
.parameter {
padding-top: 5px;
}
span {
float: right;
}
input[type="range"] {
-webkit-appearance: none;
appearance: none;
cursor: pointer;
outline: none;
background: rgba(255, 255, 255, 1.0);
height: 3px;
width: calc(100%);
}
input[type="range"]::-webkit-slider-thumb {
-webkit-appearance:none;
background:rgba(0.0, 0.0, 0.0, 0.0);
height: 15px;
width: 15px;
border: 2px solid #494949;
border-radius: 50%;
}
h1 {
font-family: 'Sen';
font-size: calc(1vw + 25px);
font-weight: 700;
left: 100px;
bottom: 10px;
position: fixed;
color: white;
transition: all 500ms;
}
::-webkit-scrollbar {
display: none;
}
</style>