Sample Particle Engine

Started by
10 comments, last by Medo Mex 11 years, 10 months ago
I am looking for example on Particle Engine to create fire/smoke effect and rain.
Advertisement
It's pretty simple. Create a dynamic vertex buffer and a collection of textured quads. On every frame update the position of the quad and then render the collection. In the function you create to update (move) the quads you can also change their color, lifetime, size, etc... Just create a structure to hold this information and calculate their movement based on velocity vectors.

In my past experience I've learned to avoid point sprites for particles because there is no guarantee of how different cards handle point sprite as well I've run into some scaling issues. I also think point sprites are no longer supported on some newer hardware (dx 10/11). Go with quads / triangles.
If I have fire texture, how can I create vertex buffer for that? any example?

Thanks,
I have also tried to remove the black from the fire texture by using color key in D3DXCreateTextureFromFileInMemoryEx() but it doesn't work.

I have attached the fire texture that I am trying to use.
You remove the black by way of your D3D device's renderstates. Turn on Alpha Blending. Set the appropriate source and destination blend. Render your quads. Then turn off the alphablend so it doesn't affect the next object you draw.

Vertex buffers store the data that your video card will need to render objects to the screen. They are the fundamental building blocks for everything directx. Since you don't know what they are I suggest you start off with rendering a simple object and build your way up to particles.

Here is a link that describes vertex buffers and how to create them:
http://www.toymaker.info/Games/html/buffers.html

But you're also going to need an understanding of Index buffers, vertex formats, structures and the render options available to you like drawtrianglelist, drawindexprimitives, etc...

I'd also recommend you get a good book. There is a section on this site that is devoted to books on directx.

Cheers!
I do understand vertex buffer, vertex formats, etc...

But I have been trying different render options but it doesn't work.

Can you post the appropriate rendering option to remove the black from the texture I posted?

BTW, I have created 4 vertices for each particle (rectangle shape).
I am also not sure about how to update the particles position to create different things such as fire, explosion, snow, etc...

Of course, the way that the particles position will be updated in explosion will not going to be the same in fire, snow, rain...

Maybe you can show an example on moving the particles towards a direction (fire) or moving particles on all directions (explosion).
After trying, I attached what I have created so far.

As you can see, I still have a problem with removing the black from the fire texture.

Additionally, I am able to set direction for the particles but not sure about how to make the particles go on all directions (so I can create explosion).

One more problem I noticed is when I look at the particles from the SIDE, I see the side of the rectangle instead of particles, see the particle side attachment.

As you can see, I still have a problem with removing the black from the fire texture.

Additionally, I am able to set direction for the particles but not sure about how to make the particles go on all directions (so I can create explosion).

One more problem I noticed is when I look at the particles from the SIDE, I see the side of the rectangle instead of particles, see the particle side attachment.


What is your source and destination blend? For source blend try "source alpha" and for desitnation blend try "invert source alpha".

You also need to have the particle always face the camera. You can do this in the shader or when calculating your world matrix.

As for the movement, you just take the current position and add a velocity vector each frame. The velocity vector should be part of the particle's data structure so that each particle has a different velocity vector. A lifetime var is important too. With these basics you can create fire, smoke, rain, snow, etc...
I created a particle engine using point sprites, not sure if it will compatible with most used cards out there or not.

Maybe if you know what kind of particles engine are used in well known games, you can give me an idea.

This topic is closed to new replies.

Advertisement