Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

share|improve this question
    
SO post: stackoverflow.com/questions/14084334/… –  Tetrad Jan 4 '13 at 18:11
add comment

3 Answers

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.

share|improve this answer
add comment

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.)

share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.