2016-03-07 21 views
0

我正在使用THREE.js r73,我試圖製作一個使用THREE.BufferGeometery來保存頂點的粒子系統,THREE.ShaderMaterial向它們添加功能。出於某種原因,我收到上述錯誤。這是我的代碼(使用Typescript)。錯誤發生在行gl_FragColor = gl_FragColor * texture2D(texture, gl_PointCoord);(片段着色器中的最後一個)。THREE.WebGLRenderer:未知的統一類型:1009

this.particleSystem = new THREE.PointCloud(
    this.particles, 
    new THREE.ShaderMaterial({ 
     uniforms: { 
      texture: wTex 
     }, 
     vertexShader: ` 
      attribute vec3 color; 
      attribute float size; 

      varying vec3 vColor; 
      varying vec2 vUv; 

      void main() { 
       vUv = uv; 
       vColor = color; // set color associated to vertex; use later in fragment shader 
       vec4 mvPosition = modelViewMatrix * vec4(position, 1.0); 
       gl_PointSize = size * (300.0/length(mvPosition.xyz)); 
       gl_Position = projectionMatrix * mvPosition; 
      } 
     `, 
     fragmentShader: ` 
      uniform sampler2D texture; 

      varying vec3 vColor; // colors associated to vertices; assigned by vertex shader 
      varying vec2 vUv; 

      void main() { 
       // calculates a color for the particle 
       gl_FragColor = vec4(vColor, 1.0); 
       // sets particle texture to desired color 
       gl_FragColor = gl_FragColor * texture2D(texture, gl_PointCoord); 
      } 
     ` 
    }) 
); 

代碼是根據我在網上找到的一些例子改編的,但我理解它。

回答

1

你沒有正確地構造制服。它應該是...

uniforms: { 
    texture: { type: 't', value: wTex } 
} 
+1

謝謝!工作完美:)。 – Pixelrobin