HTML FFT 音频分析器将其数据输出到 UInt32Array(64) 类型。
根据three.js文档,不支持这种数据类型:https ://github.com/mrdoob/three.js/wiki/Uniforms-types
如何以便宜的方式将我的每帧 FFT 缓冲区数据放入我的顶点着色器?
由于不兼容,我无法编译着色器。
任何帮助,建议表示赞赏。
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 }
};
...
在 render() 循环中:
freqByteData = new Uint8Array(analyser.frequencyBinCount);
analyser.getByteFrequencyData(freqByteData)
uniforms.freqData = freqByteData;
和 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 );
}