Sign in to follow this  
arthurprs

optimized rendering for particle system

Recommended Posts

I'm thinking in 3 options (my pseudocode) 1º glbegin(gl_quads) loop in particles: ..glvertex ..gltexcoord glend 2º loop in particles: ..glbegin(gl_trianglestrip) ..glvertex ..gltexcoord ..glend 3º glEnableClientState(GL_VERTEX_ARRAY) glVertexPointer(2, GL_FLOAT, SizeOf(TVector), dst) glEnableClientState(GL_TEXTURE_COORD_ARRAY) glTexCoordPointer(2, GL_FLOAT, SizeOf(TVector), tex) glDrawArrays(GL_QUADS, 0, 2 * 4) It's a 2d particlesystem, and another doubt, on the 3º method, how can i draw the particles rotated?

Share this post


Link to post
Share on other sites
Quote:
Original post by V-man
Quote:
Original post by arthurprs
and another doubt, on the 3º method, how can i draw the particles rotated?


glRotatef


i know, but particles have different angles

[Edited by - arthurprs on July 28, 2008 12:11:08 AM]

Share this post


Link to post
Share on other sites
Then you either calculate the position/rotation on the CPU before sending the coordinates to the GPU or use a vertex shader/program to calculate position/rotation on the GPU (best option available nowadays).

Share this post


Link to post
Share on other sites
Quote:
Original post by arthurprs
Quote:
Original post by V-man
Quote:
Original post by arthurprs
and another doubt, on the 3º method, how can i draw the particles rotated?


glRotatef


i know, but particles have different angles


I would use a vertex shader.
You can pass the angle in radians as a texture coordinate and in the shader, compute a rotation matrix and you can even translate if you submit translation factors as texcoordinates.
The other way is to submit rotation and translation as a uniform array. Submit an index using a texcoord and access the array.

Share this post


Link to post
Share on other sites
I'm not very experienced on opengl and i have to say that i don't know how to do much of the options you guys talked about :(
i know rotating the vextex on the cpu, but i think this method is not very fast,
can you guys post some snippets of the other ways?


thanks.

ps: sorry my english errors, i'm from brazil

Share this post


Link to post
Share on other sites
I don't have any code snippets.
I recommend learning some GLSL and then you'll know what to, or ask GLSL related questions. A nice tut site is http://www.lighthouse3d.com/opengl/glsl/

If performance is not an issue, if you aren't rendering several thousand particles, then just stick with doing things on the CPU.

Share this post


Link to post
Share on other sites
Quote:
Original post by OrangyTang
glBegin is slow slow slow. Draw your particles with vertex arrays (the third method), and if needed manually rotate the particles on the cpu.
As a general statement, glBegin being slow actually depends on a few things, if used in conjunction with Display Lists, the state changes can be compiled as well (Yann L stated this, and I have noted it to be true in some situations), and may infact run slightly faster. I would say that is unlikely to hold with this example (because each particle would have a unique positional update). The expensive part of a particle systems are overdraw and state-update (position, colour, intensity, collision etc.) so design your system to take these into account. My planned system is spread across cores for updates and uses GPU processing and GPU memory residency to speed things up.

[EDIT: if you're using DX10/GL2.1 with ext_gpu_program4, you can use attribute streams or Texture buffer objects to do the particle transform/rotation entirely on the GPU]

Share this post


Link to post
Share on other sites
after some research i have thinked on 3 ways to render then
witch one will be more suitable?
(i'm not sure if the 2º way is correct (first contact with displaylists))


eachframe:
..eachparticle:
....colorpointer
....texpointer
....{vertexes rotated on cpu}
....vertexpointer
..glDrawArrays


make displaylist
eachframe:
..eachparticle:
....pushmatrix
....rotate
....translate
....calllist
....popmatrix


eachframe:
..eachparticle:
....pushmatrix
....rotate
....translate
....glbegin(gl_trianglestrip)
....
....glend
....popmatrix

Share this post


Link to post
Share on other sites
display lists are only good for static stuff (thus not particle systems)

all 3 methods youve listed there are terribly slow

I prefer doing calcs on the CPU (others the GPU) but anyways
A/ calc all the vertices of the particles
B/ set that particl systems material (shader/texture etc)
C/ draw all the particles in one draw call

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this