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

THREE.WebGLRenderer: Unknown uniform type: 1009

本文关键字:类型 1009 制服 未知 WebGLRenderer      更新时间:2023-09-26

我正在使用 THREE.js r73,我正在尝试使用 THREE.BufferGeometery 来保存顶点并THREE.ShaderMaterial为它们添加功能来制作一个粒子系统。出于某种原因,我收到了上面的错误。这是我的代码(使用打字稿)。错误发生在第 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 }
}