2012-07-24 31 views
3

HTML FFT音频分析器将其数据输出为UInt32Array(64)类型。在WebGL着色器中使用UInt8Array数据

据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 } 
     }; 

... 
在渲染()循环

 freqByteData = new Uint8Array(analyser.frequencyBinCount); 
     analyser.getByteFrequencyData(freqByteData) 

     uniforms.freqData = freqByteData; 

和GLSL V-着色器:

 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); 

     } 

回答

2

我添加新的统一类型 “IV1” 为能够在整数数组传递。您可以试试:

https://github.com/alteredq/three.js/commit/4eedc69fa7344f4a512d6ae17427c7e109e0c550

+0

非常感谢您的帮助! 我在Mac OS X 10.7.4(Lion)上使用我的OpenGL版本遇到各种问题。 '错误:0:75:'国防部':没有匹配的重载函数发现'看到这里:http://theworldmoves.me/graphics/fft_1.html – Alex 2012-07-24 22:46:29

+0

我试着向着色器添加'#version 140',但它必须出现在着色器的顶部。哪里可以添加? – Alex 2012-07-25 09:24:24

+0

我收到了同样的错误。尝试使用mod与所有相同类型的参数,目前你调用mod(float,int),所以也许mod(int,int)或mod(float,float)。 – alteredq 2012-07-25 13:46:17