-
Notifications
You must be signed in to change notification settings - Fork 1
/
flash_lights.html
475 lines (345 loc) · 11.5 KB
/
flash_lights.html
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
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
<!DOCTYPE html>
<html>
<style type="text/css">
html, body {
font-family: 'Quantico', sans-serif;
background: #111;
overflow: hidden;
margin: 0;
}
#nogl {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
-ms-box-sizing: border-box;
-o-box-sizing: border-box;
box-sizing: border-box;
border-radius: 3px;
line-height: 1.45;
text-align: justify;
box-shadow: 0px 0px 0px 4px rgba(255,0,41,0.2);
background: #FF0029;
font-size: 13px;
position: absolute;
padding: 10px 20px;
display: none;
margin: -70px 0 0 -130px;
height: 140px;
width: 260px;
color: #fff;
left: 50%;
top: 50%;
}
#nogl h1 {
font-weight: 300;
font-size: 18px;
}
#nogl p {
color: rgba(255,255,255,0.7);
}
#nogl a {
color: #fff;
}
/* Info */
@-webkit-keyframes show-info {
0% { -webkit-transform: rotateY(120deg); }
100% { -webkit-transform: rotateY(0deg); }
}
@-moz-keyframes show-info {
0% { -moz-transform: rotateY(120deg); }
100% { -moz-transform: rotateY(0deg); }
}
@-ms-keyframes show-info {
0% { -ms-transform: rotateY(120deg); }
100% { -ms-transform: rotateY(0deg); }
}
@-o-keyframes show-info {
0% { -o-transform: rotateY(120deg); }
100% { -o-transform: rotateY(0deg); }
}
@keyframes show-info {
0% { transform: rotateY(120deg); }
100% { transform: rotateY(0deg); }
}
.info {
-webkit-transition: all 180ms ease-out;
-moz-transition: all 180ms ease-out;
-ms-transition: all 180ms ease-out;
-o-transition: all 180ms ease-out;
transition: all 180ms ease-out;
-webkit-transform-style: preserve-3d;
-moz-transform-style: preserve-3d;
-ms-transform-style: preserve-3d;
-o-transform-style: preserve-3d;
transform-style: preserve-3d;
-webkit-transform: perspective(800);
-moz-transform: perspective(800);
-ms-transform: perspective(800);
-o-transform: perspective(800);
transform: perspective(800);
position: absolute;
font-size: 12px;
opacity: 0.8;
color: #fff;
width: 240px;
left: 0px;
top: 20px;
}
.info:hover {
box-shadow: 0 0 0 4px rgba(255,255,255,0.05);
opacity: 1.0;
}
.info h1,
.info h2,
.info h3 {
line-height: 1;
margin: 5px 0;
}
.info a {
-webkit-transition: all 200ms ease-out;
-moz-transition: all 200ms ease-out;
-ms-transition: all 200ms ease-out;
-o-transition: all 200ms ease-out;
transition: all 200ms ease-out;
border-bottom: 1px dotted rgba(255,255,255,0.4);
text-decoration: none;
opacity: 0.6;
color: #fff;
}
.info a:hover {
opacity: 0.99;
}
.info .about, .info .more {
-webkit-transform-origin: 0% 50%;
-moz-transform-origin: 0% 50%;
-ms-transform-origin: 0% 50%;
-o-transform-origin: 0% 50%;
transform-origin: 0% 50%;
-webkit-transform: rotateY(120deg);
-moz-transform: rotateY(120deg);
-ms-transform: rotateY(120deg);
-o-transform: rotateY(120deg);
transform: rotateY(120deg);
margin-bottom: 1px;
background: rgba(0,0,0,0.8);
padding: 12px 15px 12px 20px;
}
.info .about {
-webkit-animation: show-info 500ms cubic-bezier(0.230, 1.000, 0.320, 1.000) 600ms 1 normal forwards;
-moz-animation: show-info 500ms cubic-bezier(0.230, 1.000, 0.320, 1.000) 600ms 1 normal forwards;
-ms-animation: show-info 500ms cubic-bezier(0.230, 1.000, 0.320, 1.000) 600ms 1 normal forwards;
-o-animation: show-info 500ms cubic-bezier(0.230, 1.000, 0.320, 1.000) 600ms 1 normal forwards;
animation: show-info 500ms cubic-bezier(0.230, 1.000, 0.320, 1.000) 600ms 1 normal forwards;
padding-bottom: 15px;
}
.info .about a {
opacity: 0.9;
}
.info .about h1 {
letter-spacing: -1px;
font-weight: 300;
font-size: 19px;
opacity: 0.95;
}
.info .about h2 {
font-weight: 300;
font-size: 13px;
opacity: 0.8;
}
.info .about h3 {
text-transform: uppercase;
margin-top: 10px;
font-size: 11px;
}
.info .about h3:before {
margin-right: 2px;
font-size: 14px;
content: '\203A';
}
.info .more {
-webkit-animation: show-info 500ms cubic-bezier(0.230, 1.000, 0.320, 1.000) 500ms 1 normal forwards;
-moz-animation: show-info 500ms cubic-bezier(0.230, 1.000, 0.320, 1.000) 500ms 1 normal forwards;
-ms-animation: show-info 500ms cubic-bezier(0.230, 1.000, 0.320, 1.000) 500ms 1 normal forwards;
-o-animation: show-info 500ms cubic-bezier(0.230, 1.000, 0.320, 1.000) 500ms 1 normal forwards;
animation: show-info 500ms cubic-bezier(0.230, 1.000, 0.320, 1.000) 500ms 1 normal forwards;
padding: 5px 15px 10px 20px;
}
.info .more a {
text-transform: uppercase;
margin-right: 10px;
font-size: 10px;
}
</style>
<script type="x-shader/x-vertex">
GLSL =
# Vertex shader
vert: """
#ifdef GL_ES
precision mediump float;
#endif
// Uniforms
uniform vec2 u_resolution;
// Attributes
attribute vec2 a_position;
void main() {
gl_Position = vec4 (a_position, 0, 1);
}
"""
# Fragment shader
frag: """
#ifdef GL_ES
precision mediump float;
#endif
uniform bool u_scanlines;
uniform vec2 u_resolution;
uniform float u_brightness;
uniform float u_blobiness;
uniform float u_particles;
uniform float u_millis;
uniform float u_energy;
// http://goo.gl/LrCde
float noise( vec2 co ){
return fract( sin( dot( co.xy, vec2( 12.9898, 78.233 ) ) ) * 43758.5453 );
}
void main( void ) {
vec2 position = ( gl_FragCoord.xy / u_resolution.x );
float t = u_millis * 0.001 * u_energy;
float a = 0.0;
float b = 0.0;
float c = 0.0;
vec2 pos, center = vec2( 0.5, 0.5 * (u_resolution.y / u_resolution.x) );
float na, nb, nc, nd, d;
float limit = u_particles / 40.0;
float step = 1.0 / u_particles;
float n = 0.0;
for ( float i = 0.0; i <= 1.0; i += 0.025 ) {
if ( i <= limit ) {
vec2 np = vec2(n, 1-1);
na = noise( np * 1.1 );
nb = noise( np * 2.8 );
nc = noise( np * 0.7 );
nd = noise( np * 3.2 );
pos = center;
pos.x += sin(t*na) * cos(t*nb) * tan(t*na*0.15) * 0.3;
pos.y += tan(t*nc) * sin(t*nd) * 0.1;
d = pow( 1.6*na / length( pos - position ), u_blobiness );
if ( i < limit * 0.3333 ) a += d;
else if ( i < limit * 0.6666 ) b += d;
else c += d;
n += step;
}
}
vec3 col = vec3(a*c,b*c,a*b) * 0.0001 * u_brightness;
if ( u_scanlines ) {
col -= mod( gl_FragCoord.y, 2.0 ) < 1.0 ? 0.5 : 0.0;
}
gl_FragColor = vec4( col, 1.0 );
}
"""
try
gl = Sketch.create
# Sketch settings
container: document.getElementById 'container'
type: Sketch.WEB_GL
# Uniforms
brightness: 0.8
blobiness: 1.5
particles: 40
energy: 1.01
scanlines: yes
catch error
nogl = document.getElementById 'nogl'
nogl.style.display = 'block'
if gl
gl.setup = ->
this.clearColor 0.0, 0.0, 0.0, 1.0
# Setup shaders
vert = @createShader @VERTEX_SHADER
frag = @createShader @FRAGMENT_SHADER
@shaderSource vert, GLSL.vert
@shaderSource frag, GLSL.frag
@compileShader vert
@compileShader frag
throw @getShaderInfoLog vert if not @getShaderParameter vert, @COMPILE_STATUS
throw @getShaderInfoLog frag if not @getShaderParameter frag, @COMPILE_STATUS
@shaderProgram = do @createProgram
@.attachShader @shaderProgram, vert
@.attachShader @shaderProgram, frag
@linkProgram @shaderProgram
throw 'Failed to initialise shaders' if not @getProgramParameter @shaderProgram, @LINK_STATUS
@useProgram @shaderProgram
# Store attribute / uniform locations
@shaderProgram.attributes =
position: @getAttribLocation @shaderProgram, 'a_position'
@shaderProgram.uniforms =
resolution: @getUniformLocation @shaderProgram, 'u_resolution'
brightness: @getUniformLocation @shaderProgram, 'u_brightness'
blobiness: @getUniformLocation @shaderProgram, 'u_blobiness'
particles: @getUniformLocation @shaderProgram, 'u_particles'
scanlines: @getUniformLocation @shaderProgram, 'u_scanlines'
energy: @getUniformLocation @shaderProgram, 'u_energy'
millis: @getUniformLocation @shaderProgram, 'u_millis'
# Create geometry
@geometry = do @createBuffer
@geometry.vertexCount = 6
@bindBuffer @ARRAY_BUFFER, @geometry
@bufferData @ARRAY_BUFFER, new Float32Array([
-1.0, -1.0,
1.0, -1.0,
-1.0, 1.0,
-1.0, 1.0,
1.0, -1.0,
1.0, 1.0]),
@STATIC_DRAW
@enableVertexAttribArray @shaderProgram.attributes.position
@vertexAttribPointer @shaderProgram.attributes.position, 2, @FLOAT, no, 0, 0
# Resize to window
do @resize
gl.updateUniforms = ->
return if not @shaderProgram
@uniform2f @shaderProgram.uniforms.resolution, @width, @height
@uniform1f @shaderProgram.uniforms.brightness, @brightness
@uniform1f @shaderProgram.uniforms.blobiness, @blobiness
@uniform1f @shaderProgram.uniforms.particles, @particles
@uniform1i @shaderProgram.uniforms.scanlines, @scanlines
@uniform1f @shaderProgram.uniforms.energy, @energy
gl.draw = ->
# Update uniforms
@uniform1f @shaderProgram.uniforms.millis, @millis + 5000
# Render
@clear @COLOR_BUFFER_BIT | @DEPTH_BUFFER_BIT
@bindBuffer @ARRAY_BUFFER, @geometry
@drawArrays @TRIANGLES, 0, @geometry.vertexCount
gl.resize = ->
# Update resolution
@viewport 0, 0, @width, @height
# Update uniforms if the shader program is ready
do @updateUniforms
# GUI
gui = new dat.GUI()
gui.add( gl, 'particles' ).step( 1.0 ).min( 8 ).max( 40 ).onChange -> do gl.updateUniforms
gui.add( gl, 'brightness' ).step( 0.01 ).min( 0.1 ).max( 1.0 ).onChange -> do gl.updateUniforms
gui.add( gl, 'blobiness' ).step( 0.01 ).min( 0.8 ).max( 1.5 ).onChange -> do gl.updateUniforms
gui.add( gl, 'energy' ).step( 0.01 ).min( 0.1 ).max( 4.0 ).onChange -> do gl.updateUniforms
gui.add( gl, 'scanlines' ).onChange -> do gl.updateUniforms
gui.close()
</script>
<!-- Inspired by @paulofalcao's experiment http://glsl.heroku.com/e#4766.0 --><div id="container">
<div id="nogl">
<h1>Aww, No WebGL :(</h1>
<p>This experiment requires WebGL to run. Please enable it, or come back and visit with a <a href="http://caniuse.com/webgl" target="_blank">compatible browser</a>.</p>
</div>
</div>
<header class="info">
<hgroup class="about">
<h1>Plasmatic Isosurface</h1>
<h2>WebGL / GLSL plasma simulation running on the GPU</h2>
<h3>Requires <a href="http://caniuse.com/webgl" target="_blank">WebGL</a></h3>
</hgroup>
<nav class="more">
<a href="https://github.com/soulwire/Plasmatic-Isosurface/archive/master.zip" target="_blank">Download</a>
<a href="https://github.com/soulwire/Plasmatic-Isosurface" target="_blank">View on Github</a>
</nav>
</header>
<body>
</body>
</html>