I am trying to create a moving triangulation-effect backdrop for my website, and I would like every to vary the “size”-attribute of the material I am using for each white point between 0.3 and 2. Currently they are all set to size:1 as seen in the code below.
Here is the current code for showing the points:
var sz = { x: 200, z: 200 };
var pointsCount = 1000;
var points3d = [];
for (let i = 0; i < pointsCount; i++) {
let x = THREE.MathUtils.randFloatSpread(sz.x);
let z = THREE.MathUtils.randFloatSpread(sz.z);
let y = 10;
points3d.push(new THREE.Vector3(x, y, z));
}
const sprite = new THREE.TextureLoader().load( 'disc.png' );
var geom = new THREE.BufferGeometry().setFromPoints(points3d);
var material = new THREE.PointsMaterial( { size: 1, sizeAttenuation: true, map: sprite, alphaTest: 0.5, transparent: true } );
var cloud = new THREE.Points(
geom,
material
);
cloud.rotation.x = -Math.PI / 2;
scene.add(cloud);
Current image:
Currently I am using sprites for this as billboarding is enough, but perhaps this is not the correct approach if I want varied size on the white dots?
Ah, sorry, maybe I formulated it badly. Is it possible to have element-wise sizes within the same buffer? For example one circle has size 0.5 whilst another has 2.0 and a third one 1.2 or something. In other words 2 billboarded stars from the same buffer having different size-parameters.
I don’t know a simple way to do this with one cloud of points. All I can think of needs either more objects, or custom shader, or visual tricks, or instancing of circles/spheres.
Exactly! I see, I am running into the same issue, it feels like the cheapskate option with one buffer and billboarding is not enough for this I would later want to use the mesh for triangulation, so i would like to have it in one buffer for that. In theory maybe I could instantiate 4 or 5 buffers with dots of specific sizes, and then it if lets me, add them to the same BufferGeometry to render, do you know if this is possible?
The video above uses one cloud + visual tricks. Each point moves forward and backward along the line to the camera, so the point changes its size, but remains on the same position on the screen.
Several clouds sounds plausible, but you have to manage the transfer of points from one cloud to another one. Is this worth the headache?
I’m not familiar with Three.js internals, but if size becomes an array of sizes, there must be some gl.enableVertexAttribArray(...) command, so that each vertex has its own size. Can this be done by a modified PointsMaterial?
Nice! I tried @PavelBoytchev’s solution, but it becomes a bit tricky as I want to use the same points for triangulation, so moving the points back to change their size messes with the triangulation unless i make a second buffer, but this makes things convoluted later on in the code and the depth messes with the billboards. Will try your solution with PointsMaterial when I get back from work, the Nova animation looks like it would achieve what I would like concerning the point sizes. Thank you guys!