Recommended Posts

hello,
well it's because
1. i'd like my particles to have multiple textures(ie, animating),
2. i want it to rotate,
3. each type uses different textures
4. each type too have their own orientation towards the camera
5. different x,y,z sizes
so does that mean, EACH of my particle has it's own World Transformation and SetTexture now? and now i have to use materials too because i can't go for lock/unlock for each of them,
also, i know this is possible but i don't know how, the texture contains a sequence of frames, say 16, so how do i retrieve each of them, method should be very fast though,
many thanks hope you could give me some advice if there's any other way, especially changing the particle's color
[edited by - mickey on December 5, 2002 8:11:04 AM]

0

Share this post

Link to post

Share on other sites

hiI think the best thing to do is to render each particle as a quad (4 vertices), like in the Billboarding SDK sample.Sort your particles by texture.You should use one big vertex buffer, that you lock each frame just before you render, fill it with your newly computed vertices, unlock and render it.you can write something like (pseudo-C++ code):CParticleList{ int count; LPDIRECT3DTEXTURE8 pTex = ...; YOUR_VERTEX_FORMAT buf[4*count]; void Render(int* pos) { for (int i=0;i m_pd3dDevice->SetTexture(0, pTex); m_pd3dDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, *pos, 2); (*pos) += 4; } }};

Just load your data into the vertex buffer before you render, and you are done. Loading requires that you multiply each vertex by its particle transformation matrix, which can be slow; and that is why current games do not display lots of different particles: it is very expensive.

Again, look at the Billboarding sample code, it will help you with the orientation towards the camera. (in this sample, all the trees are oriented so that they face the camera)

About animating your particles, I suggest using a big texture, containing your 16 frames, and change the vertex texture coordinates each frame, so that only 1 frame is drawn

Hope this helps

0

Share this post

Link to post

Share on other sites

EDIT :: Should've read Tibo's post - before writing this oh well - this may still be somewhat useful.

Well, particles are usually quite small - can't you have a single texture with more than one particle type in it? If you had a 256x256 texture, you could fit (for example) 4 types of particle, each with 8 frames of animation, each frame 32 x 32 pixels big on that one texture, and then you wouldn't need to change texture for each particle. Of course, if you need more types of particle, or larger particles, or longer animations then you'd have to either use bigger textures (which wouldn't necessarily work on all cards), or split the texture up and SetTexture() for each group of particles.

There are two ways of retreiving a specific part of the texture.1) Alter the vertices in the vertex buffer, using different texture coordinates.2) Use a texture transformation matrix to get the card to transform the coords itself.

In the first method you'd need to lock the vertex buffer each frame, and change the texture coordinates (you could also change the colour and position here) - but you would change the coords for every particle at once. Then you'd call DrawPrimitive once to draw every particle.

In the second method you have to group your particles, and set up the texture transform matrix for each group (don't set it for every particle unless).

Share this post

Link to post

Share on other sites

If I remember correctly, the texture transform matrix is different from the normal projection, view and world matrices, as it only uses the first 3x3 section of the matrix. Therefore, using the normal D3DXTranslate function to get the matrix will not work (it works for scaling because scaling uses the inner section of the matrix anyway, but for translations it wouldn't work). I can't remember if there is a special utility function to make a texture transform matrix for you, but I don't think there is, so that means you'll need to produce the matrix yourself (probably best to make an inline function to set a texture matrix up given, for example, a rect specifying which section of the texture to use).