我正在使用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 );
}
`
})
);
代码改编自我在网上找到的一些例子,但我明白了。
答案 0 :(得分:1)
你没有正确地构造制服。它应该是......
uniforms: {
texture: { type: 't', value: wTex }
}