4
\$\begingroup\$

I've combined all of my vertex data for many particles into a single array. How would I batch draw all of those particles in a manner that preserves their unique translations?

Any code examples would be greatly appreciated.

\$\endgroup\$
1

3 Answers 3

2
\$\begingroup\$

I've combined all of my vertex data for many particles into a single array.

How did you do this exactly? Details?

You could "secretly contain" the transformation matrix for each particle's vertex in 4 texture coordinates.

So, you'd have a vertex format like:

vec4 position
vec4 color
vec4 matTexcoord0
vec4 matTexcoord1
vec4 matTexcoord2
vec4 matTexcoord3
vec4 texturingTexcoord

Little does the shader know that matTexcoord0-matTexcoord3 are not actually texture coordinates. No. They are a transformation matrix in disguise.

Da da da dah!!

Effectively a mat4x4 is passed using 4 vec4's. So you apply the transformation matrix contained in matTexcoord0-3 in the shader as a kind of world transform. If you use point sprites this can be very efficient.

\$\endgroup\$
0
\$\begingroup\$

Perform the translation in your vertex shader. You must either have a parallel array which contains the translations for each vertex, or store the translations in a texture which you lookup in using some attribute of each particle.

(Note: Answering as if for WebGL; I have no actual GL ES experience.)

\$\endgroup\$
0
\$\begingroup\$

Each particle needs it's own transformation matrix, so a parallel array or third element to the array of a unique tranform matrix is needed. Then before you draw a particle, multiply the current Modelview matrix by the particle's transform matrix.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .