optimized rendering for particle system
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?
Quote:Original post by arthurprs
and another doubt, on the 3º method, how can i draw the particles rotated?
glRotatef
Quote:Original post by V-manQuote: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]
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).
glBegin is slow slow slow. Draw your particles with vertex arrays (the third method), and if needed manually rotate the particles on the cpu.
Quote:Original post by arthurprsQuote:Original post by V-manQuote: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.
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
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
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.
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.
Quote:Original post by OrangyTangAs 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.
glBegin is slow slow slow. Draw your particles with vertex arrays (the third method), and if needed manually rotate the particles on the cpu.
[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]
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))
1º
eachframe:
..eachparticle:
....colorpointer
....texpointer
....{vertexes rotated on cpu}
....vertexpointer
..glDrawArrays
2º
make displaylist
eachframe:
..eachparticle:
....pushmatrix
....rotate
....translate
....calllist
....popmatrix
3º
eachframe:
..eachparticle:
....pushmatrix
....rotate
....translate
....glbegin(gl_trianglestrip)
....
....glend
....popmatrix
witch one will be more suitable?
(i'm not sure if the 2º way is correct (first contact with displaylists))
1º
eachframe:
..eachparticle:
....colorpointer
....texpointer
....{vertexes rotated on cpu}
....vertexpointer
..glDrawArrays
2º
make displaylist
eachframe:
..eachparticle:
....pushmatrix
....rotate
....translate
....calllist
....popmatrix
3º
eachframe:
..eachparticle:
....pushmatrix
....rotate
....translate
....glbegin(gl_trianglestrip)
....
....glend
....popmatrix
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement