-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
287 lines (257 loc) · 9.18 KB
/
index.html
File metadata and controls
287 lines (257 loc) · 9.18 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
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>GPU Line Tralis</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/stats.js/r16/Stats.min.js"></script>
<!--↓doxas's minMatrixb.js-->
<script src="https://wgld.org/j/minMatrixb.js"></script>
<script src="main.js"></script>
<script type="x-shader/x-vertex" id="buffer_vs">#version 300 es
const vec3[4] POSITIONS = vec3[](
vec3(-1.0, -1.0, 0.0),
vec3(1.0, -1.0, 0.0),
vec3(-1.0, 1.0, 0.0),
vec3(1.0, 1.0, 0.0)
);
const int[6] INDICES = int[](
0, 1, 2,
3, 2, 1
);
void main(void) {
vec3 position = POSITIONS[INDICES[gl_VertexID]];
gl_Position = vec4(position, 1.0);
}
</script>
<script type="x-shader/x-fragment" id="init_trails_fs">#version 300 es
precision highp float;
layout (location = 0) out vec3 o_position;
layout (location = 1) out vec3 o_velocity;
float random(float p) {
return fract(sin(p * 12.9898) * 43758.5453);
}
void main(void) {
vec3 position = vec3(0.0);
position.x = random(gl_FragCoord.x * 0.234 + 432.43);
position.y = random(gl_FragCoord.x * 0.342 + 342.34);
position.z = random(gl_FragCoord.x * 0.423 + 423.42);
o_position = 1.0 * (position * 2.0 - 1.0);
o_velocity = vec3(0.0);
}
</script>
<script type="x-shader/x-fragment" id="update_trails_fs">#version 300 es
precision highp float;
uniform sampler2D uPositionTexture;
uniform sampler2D uVelocityTexture;
uniform float uTime;
uniform float uDeltaTime;
uniform float uMaxSpeed;
uniform float uBoundRadius;
uniform float uNoiseScale;
uniform float uMaxForce;
layout (location = 0) out vec3 o_position;
layout (location = 1) out vec3 o_velocity;
float random(vec4 x) {
return fract(sin(dot(x,vec4(12.9898, 78.233, 39.425, 27.196))) * 43758.5453);
}
float valuenoise(vec4 x) {
vec4 i = floor(x);
vec4 f = fract(x);
vec4 u = f * f * (3.0 - 2.0 * f);
return mix(
mix(
mix(
mix(random(i + vec4(0.0, 0.0, 0.0, 0.0)), random(i + vec4(1.0, 0.0, 0.0, 0.0)), u.x),
mix(random(i + vec4(0.0, 1.0, 0.0, 0.0)), random(i + vec4(1.0, 1.0, 0.0, 0.0)), u.x),
u.y
),
mix(
mix(random(i + vec4(0.0, 0.0, 1.0, 0.0)), random(i + vec4(1.0, 0.0, 1.0, 0.0)), u.x),
mix(random(i + vec4(0.0, 1.0, 1.0, 0.0)), random(i + vec4(1.0, 1.0, 1.0, 0.0)), u.x),
u.y
),
u.z
),
mix(
mix(
mix(random(i + vec4(0.0, 0.0, 0.0, 1.0)), random(i + vec4(1.0, 0.0, 0.0, 1.0)), u.x),
mix(random(i + vec4(0.0, 1.0, 0.0, 1.0)), random(i + vec4(1.0, 1.0, 0.0, 1.0)), u.x),
u.y
),
mix(
mix(random(i + vec4(0.0, 0.0, 1.0, 1.0)), random(i + vec4(1.0, 0.0, 1.0, 1.0)), u.x),
mix(random(i + vec4(0.0, 1.0, 1.0, 1.0)), random(i + vec4(1.0, 1.0, 1.0, 1.0)), u.x),
u.y
),
u.z
),
u.w
);
}
float fbm(vec4 x) {
float sum = 0.0;
float amp = 0.5;
for (int i = 0; i < 5; i++) {
sum += amp * valuenoise(x);
amp *= 0.5;
x *= 2.01;
}
return sum * 2.0 - 1.0;
}
float noiseX(vec4 x) {
return fbm(x * 0.34 + vec4(4324.32, 7553.13, 5417.33, 1484.43));
}
float noiseY(vec4 x) {
return fbm(x * 0.71 + vec4(1614.43, 8439.32, 4211.93, 8546.29));
}
float noiseZ(vec4 x) {
return fbm(x * 0.54 + vec4(4342.34, 7569.34, 3812.42, 1589.54));
}
vec3 curlnoise(vec3 x, float time) {
float e = 0.01;
vec3 dx = vec3(e, 0.0, 0.0);
vec3 dy = vec3(0.0, e, 0.0);
vec3 dz = vec3(0.0, 0.0, e);
return vec3(
(noiseZ(vec4(x + dy, time)) - noiseZ(vec4(x - dy, time))) - (noiseY(vec4(x + dz, time)) - noiseY(vec4(x - dz, time))),
(noiseX(vec4(x + dz, time)) - noiseX(vec4(x - dz, time))) - (noiseZ(vec4(x + dx, time)) - noiseZ(vec4(x - dx, time))),
(noiseY(vec4(x + dx, time)) - noiseY(vec4(x - dx, time))) - (noiseX(vec4(x + dy, time)) - noiseX(vec4(x - dy, time)))
) / (2.0 * e);
}
vec3 limit(vec3 v, float max) {
if (length(v) > max) {
return normalize(v) * max;
}
return v;
}
void main(void) {
ivec2 coord = ivec2(gl_FragCoord.xy);
vec3 nextPosition, nextVelocity;
if (coord.y == 0) {
vec3 position = texelFetch(uPositionTexture, coord, 0).xyz;
vec3 velocity = texelFetch(uVelocityTexture, coord, 0).xyz;
// update position & velocity
vec3 acceleration = curlnoise(position * uNoiseScale, uTime * 0.05);
acceleration = uMaxForce * mix(acceleration, -normalize(position), smoothstep(uBoundRadius, uBoundRadius * 1.005, length(position)));
nextVelocity = limit(velocity + uDeltaTime * acceleration, uMaxSpeed);
nextPosition = position + uDeltaTime * nextVelocity;
} else {
nextPosition = texelFetch(uPositionTexture, coord - ivec2(0, 1), 0).xyz;
nextVelocity = texelFetch(uVelocityTexture, coord - ivec2(0, 1), 0).xyz;
}
o_position = nextPosition;
o_velocity = nextVelocity;
}
</script>
<script type="x-shader/x-vertex" id="render_vs">#version 300 es
uniform sampler2D uPositionTexture;
uniform mat4 vpMatrix;
uniform bool uRenderType;
out vec3 trailColor;
float random(float p) {
return fract(sin(p * 12.9898) * 43758.5453);
}
void main(void) {
vec3 position = texelFetch(uPositionTexture, ivec2(gl_InstanceID, gl_VertexID), 0).xyz;
float id = float(gl_InstanceID);
vec3 color = vec3(0.0);
color.r = random(id * 0.234 + 432.43);
color.g = random(id * 0.342 + 342.34);
// color.b = random(id * 0.432 + 234.23);
color.b = 1.0;
trailColor = color;
gl_Position = vpMatrix * vec4(position, 1.0);
if (!uRenderType) {
gl_PointSize = 1.0;
}
}
</script>
<script type="x-shader/x-fragment" id="render_trails_fs">#version 300 es
precision highp float;
in vec3 trailColor;
out vec4 fragColor;
void main(void) {
fragColor = vec4(trailColor, 1.0);
}
</script>
</head>
<body>
<canvas id="canvas"></canvas>
<div id="container"></div>
<h1>GPU Line Trails</h1>
<div id="parameter_container">
<div class="parameter"><div class="parameter_name">Max Speed<span id="disp_max_speed" class="value"></span></div><input type="range" id="max_speed" min="0.01" max="100.0" value="50.0" step="0.01"/></div><br>
<div class="parameter"><div class="parameter_name">Max Force<span id="disp_max_force" class="value"></span></div><input type="range" id="max_force" min="0.01" max="100.0" value="100.0" step="0.01"/></div><br>
<div class="parameter"><div class="parameter_name">Bound Radius<span id="disp_bound_rad" class="value"></span></div><input type="range" id="bound_rad" min="50.0" max="400.0" value="200.0" step="0.1"/></div><br>
<div class="parameter"><div class="parameter_name">Noise Scale<span id="disp_noise_scale" class="value"></span></div><input type="range" id="noise_scale" min="0.001" max="0.02" value="0.003" step="0.0001"/></div><br>
<div class="parameter"><div class="parameter_name">FOV<span id="disp_fov" class="value"></span></div><input type="range" id="fov" min="15.0" max="100.0" value="100.0" step="0.01"/></div><br>
<div class="parameter"><div class="parameter_name">Camera Dist<span id="disp_cam_dist" class="value"></span></div><input type="range" id="cam_dist" min="10.0" max="500.0" value="200.0" step="0.1"/></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-color:rgba(20, 20, 20, 0.95);
border-radius: 3%;
padding: 2% 2.5%;
width: calc(10% + 120px);
font-family: 'Sen';
font-size: calc(0.5vw + 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;
}
</style>