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 );
}
答案 0 :(得分:2)
我添加了新的统一类型“iv1”,以便能够传入整数数组。你可以尝试一下:
https://github.com/alteredq/three.js/commit/4eedc69fa7344f4a512d6ae17427c7e109e0c550