Reputation: 4934
An HTML FFT audio analyzer outputs its data into a UInt32Array(64) type.
According to three.js documentation, this data type is not supported: https://github.com/mrdoob/three.js/wiki/Uniforms-types
How can get my per frame FFT buffer data into my vertex shader, in a cheap way?
I've not been able to compile the shader beacause of the incompatibility.
Any help, suggestions appreciated.
attributes = {
customColor: { type: "c", value: [] },
tick: { type: "f", value: 1.0 }
};
uniforms = {
amplitude: { type: "f", value: 5.0 },
opacity: { type: "f", value: 0.3 },
color: { type: "c", value: new THREE.Color( 0xff0000 ) },
fftSize: { type: "i", value: 63 },
freqData: { type: "fv1", value: freqByteData }
};
...
in the render() loop:
freqByteData = new Uint8Array(analyser.frequencyBinCount);
analyser.getByteFrequencyData(freqByteData)
uniforms.freqData = freqByteData;
and GLSL v-shader:
uniform float freqData[64]; // not working, primitive type conflict
uniform int fftSize;
uniform float amplitude;
attribute vec3 customColor;
attribute int tick;
varying vec3 vColor;
void main() {
vec3 norm = normalize(position);
vec3 newPosition = position * freqData[tick % fftSize] + amplitude;
vColor = customColor;
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
}
Upvotes: 3
Views: 2323
Reputation: 534
I added new uniform type "iv1" to be able to pass in integer arrays. You can try it:
https://github.com/alteredq/three.js/commit/4eedc69fa7344f4a512d6ae17427c7e109e0c550
Upvotes: 2