2012-07-24 32 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