A WebGL music visualizer demo
A music visualizer experiment simply powered by shaders–which are programs that tell the GPU how to render the material its applied to–and audio Fourier transform data that can easily be accessed by the Web Audio API.
Staccato simply takes data from a playing song, updates uniforms
–which are variables that are passed into shaders for them to use–and now shapes in the scene using these shaders have tastefully modified vertices/color.
The two most important uniforms currently used include time
and frequency
, which is the elapsed time and a 32-bit float array for audio volume data, respectively. These two variables are alone enough to make powerful scenes, the beauty comes from simply how they're used in the shaders.
Staccato
exists as an easily modifiable object, which handles setting up the audio stream, loading songs, shaders, and adding shapes to the scene.
Some attributes/methods to modify:
-
shaders
: list of shaders that Staccato will load when you calladdShape
, make sure to have elements inindex.html
for your vertex ([shaderName]-vertex
) and fragment ([shaderName]-fragment
)shader. -
uniforms
: object literal containing all uniform variables that each added shape receives -
addShape()
: this is the function which adds a mesh to the scene with a specifiedgeometry
,shader
, and vectorposition
-
update()
: should be called every frame to update uniforms, objects, etc -
There are several functions for setting up the audio which can be modified and used in plenty of other ways