【问题标题】:THREE.WebGLRenderer: Unknown uniform type: 1009三.WebGLRenderer:未知统一类型:1009
【发布时间】:2016-03-08 13:29:43
【问题描述】:

我正在使用 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 );
            }
        `
    })
);

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

【问题讨论】:

    标签: javascript three.js glsl


    【解决方案1】:

    你没有正确地构造制服。应该是……

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

    【讨论】:

      猜你喜欢
      • 2022-12-12
      • 2022-11-12
      • 2015-01-02
      • 2020-08-01
      • 2022-06-15
      • 1970-01-01
      • 2020-01-03
      • 1970-01-01
      • 2011-01-31
      相关资源
      最近更新 更多