Hello !
First of all, I apologies for my evident lack of knowledge about GLSL shaders : I just began to learn this language and I don’t understand 90% of what I’m doing…
So I’m trying to modify this example that shows how to use GPU computing to generate birds flying around. What I would like to do seems pretty simple : I want the birds to be simple tetrahedron shapes…
To do that, I just changed the way each “bird” was generated, modifying this part of the code to define a tetrahedron shape with 4 faces:
for(var f = 0; f < birdsNumber; f++)
{
verts_push(
0, 12, 0,
0, 0, 12,
-12, 0, -12
);
verts_push(
0, 12, 0,
-12, 0, -12,
12, 0, -12
);
verts_push(
0, 12, 0,
12, 0, -12,
0, 0, 12
);
verts_push(
0, 0, 12,
-12, 0, -12,
12, 0, -12
);
}
But instead of having tetrahedrons, I get independent triangular faces floating around… Like if the tetrahedron was not told which faces belong to it.
I think it has something to do with the “references” array defined by this formula :
var i = ~~(v / 3);
references.array[ v * 2 ] = (i % WIDTH) / WIDTH;
references.array[ v * 2 + 1 ] = ~~(i / WIDTH) / WIDTH;
Indeed, this array is passed to the vertex shader using THREE.BufferAttribute
like so :
var references = new THREE.BufferAttribute( new Float32Array( points * 2 ), 2 );
this.addAttribute( 'reference', references );
And in the vertex shader:
attribute vec2 reference;
uniform sampler2D texturePosition;
vec4 tmpPos = texture2D( texturePosition, reference );
I absolutely don’t understand how this array is supposed to affect the shape of the bird in any way? I can try and change its values, the effect seems to be random no matter how I change it…
If anyone can explain to me the purpose of the “reference” array in this particular case, I would really appreciate it. And if you have any clue on how I can achieve my little goal, I’m listening
Thanks in advance, and sorry for my laborious explanations!