|
57 | 57 | <link rel="stylesheet" href="css/codemirror.css">
|
58 | 58 | <link rel="stylesheet" href="css/default.css">
|
59 | 59 |
|
| 60 | + <script src="https://unpkg.com/meyda/dist/web/meyda.min.js"></script> |
60 | 61 | <script src="js/lzma.js"></script>
|
61 | 62 | <script src='js/jquery.js'></script>
|
62 | 63 | <script src='js/helpers.js'></script>
|
63 | 64 | <script src="js/codemirror.js"></script>
|
64 | 65 | <script src="js/glsl.js"></script>
|
| 66 | + <script src="js/audio.js"></script> |
65 | 67 |
|
66 | 68 | <script id="example" type="x-shader/x-fragment">precision mediump float;
|
67 | 69 |
|
|
70 | 72 | uniform float time;
|
71 | 73 | uniform vec2 mouse;
|
72 | 74 | uniform vec2 resolution;
|
| 75 | +uniform vec3 audio; |
73 | 76 |
|
74 | 77 | void main( void ) {
|
75 | 78 |
|
|
81 | 84 | color += sin( position.x * sin( time / 5.0 ) * 10.0 ) + sin( position.y * sin( time / 35.0 ) * 80.0 );
|
82 | 85 | color *= sin( time / 10.0 ) * 0.5;
|
83 | 86 |
|
84 |
| - gl_FragColor = vec4( vec3( color, color * 0.5, sin( color + time / 3.0 ) * 0.75 ), 1.0 ); |
| 87 | + gl_FragColor = vec4( audio + vec3( color, color * 0.5, sin( color + time / 3.0 ) * 0.75 ), 1.0 ); |
85 | 88 |
|
86 | 89 | }</script>
|
87 | 90 |
|
|
167 | 170 | var code, canvas, gl, buffer, currentProgram, vertexPosition, screenVertexPosition, panButton,
|
168 | 171 | parameters = { startTime: Date.now(), time: 0, mouseX: 0.5, mouseY: 0.5, screenWidth: 0, screenHeight: 0 },
|
169 | 172 | surface = { centerX: 0, centerY: 0, width: 1, height: 1, isPanning: false, isZooming: false, lastX: 0, lastY: 0 },
|
170 |
| - frontTarget, backTarget, screenProgram, getWebGL, resizer = {}, compileOnChangeCode = true; |
| 173 | + frontTarget, backTarget, screenProgram, getWebGL, resizer = {}, compileOnChangeCode = true, audio; |
171 | 174 |
|
172 | 175 | init();
|
173 | 176 | if (gl) { animate(); }
|
|
464 | 467 |
|
465 | 468 | compileScreenProgram();
|
466 | 469 |
|
| 470 | + audio = new Audio(); |
| 471 | + |
467 | 472 | }
|
468 | 473 |
|
469 | 474 | function isCodeVisible() {
|
|
615 | 620 |
|
616 | 621 | // Cache uniforms
|
617 | 622 |
|
| 623 | + cacheUniformLocation( program, 'audio' ); |
618 | 624 | cacheUniformLocation( program, 'time' );
|
619 | 625 | cacheUniformLocation( program, 'mouse' );
|
620 | 626 | cacheUniformLocation( program, 'resolution' );
|
|
873 | 879 | if ( !currentProgram ) return;
|
874 | 880 |
|
875 | 881 | parameters.time = Date.now() - parameters.startTime;
|
| 882 | + audio.tick(); |
876 | 883 |
|
877 | 884 | // Set uniforms for custom shader
|
878 | 885 |
|
879 | 886 | gl.useProgram( currentProgram );
|
880 | 887 |
|
| 888 | + gl.uniform3f( currentProgram.uniformsCache[ 'audio' ], audio.fft[0], audio.fft[1], audio.fft[2]); |
881 | 889 | gl.uniform1f( currentProgram.uniformsCache[ 'time' ], parameters.time / 1000 );
|
882 | 890 | gl.uniform2f( currentProgram.uniformsCache[ 'mouse' ], parameters.mouseX, parameters.mouseY );
|
883 | 891 | gl.uniform2f( currentProgram.uniformsCache[ 'resolution' ], parameters.screenWidth, parameters.screenHeight );
|
|
0 commit comments