THREE.WebGLRenderer:未知制服类型:1009

THREE.WebGLRenderer: Unknown uniform type: 1009

我正在使用 THREE.js r73,我正在尝试使用 THREE.BufferGeometery 来保存顶点并使用 THREE.ShaderMaterial 来为它们添加功能来制作粒子系统。出于某种原因,我收到上面的错误。这是我的代码(使用 Typescript)。错误发生在 gl_FragColor = gl_FragColor * texture2D( texture, gl_PointCoord ); 行(片段着色器中的最后一个)。

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

代码是根据我在网上找的一些例子改编的,但是我理解了。

你没有正确构建制服。应该是...

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