I am using THREE.PointCloud
for better performance, I have to animate 100K objects. But the problem is I couldn't find a way to set different texture for particles.
How to use uniforms with different texture in this code.
Can I pass shaderMaterial
as array which has equal number as particles with different textures ?
Or in fragment shader how can I pass different texture ?
var uniforms = {
amplitude: {
type: "f",
value: 1.0
},
color: {
type: "c",
value: new THREE.Color("#fff")
},
texture: {
type: "t",
value: new THREE.TextureLoader().load("./images/shape1.png")
// I have to set different shapes randomly
}
};
var vertexShader = [
"uniform float amplitude;",
"attribute float size;",
"attribute vec3 customColor;",
"varying vec3 vColor;",
"void main() {",
"vColor = customColor;",
"vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
"gl_PointSize = size * ( 300.0 / length( mvPosition.xyz ) );",
" gl_Position = projectionMatrix * mvPosition;",
"}"
].join("\n"),
fragmentShader = [
"uniform vec3 color;",
"uniform sampler2D texture;",
"varying vec3 vColor;",
"void main() {",
"gl_FragColor = vec4( color * vColor, 1.0 );",
"gl_FragColor = gl_FragColor * texture2D( texture, gl_PointCoord );",
"}"
].join("\n");
var shaderMaterial = new THREE.ShaderMaterial({
uniforms: uniforms,
//attributes: attributes,
vertexShader: vertexShader,
fragmentShader: fragmentShader,
blending: THREE.AdditiveBlending,
depthTest: true,
transparent: false
});
// particles.colors = colors;
var particles = new THREE.BufferGeometry();
particles.addAttribute('position', new THREE.BufferAttribute(positions, 3));
particles.addAttribute('customColor', new THREE.BufferAttribute(colors, 3));
particles.addAttribute('size', new THREE.BufferAttribute(sizes, 1));
particleSystem = new THREE.PointCloud(particles, shaderMaterial); // can i pass shaderMaterial as array which has equal number as particles with different textures