Jump to content

  • Log In with Google      Sign In   
  • Create Account

Sample Particle Engine


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
11 replies to this topic

#1 Medo3337   Members   -  Reputation: 665

Like
0Likes
Like

Posted 05 June 2012 - 02:55 AM

I am looking for example on Particle Engine to create fire/smoke effect and rain.

Sponsor:

#2 DJTN   Members   -  Reputation: 207

Like
0Likes
Like

Posted 05 June 2012 - 06:30 PM

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.

#3 Medo3337   Members   -  Reputation: 665

Like
0Likes
Like

Posted 05 June 2012 - 07:50 PM

If I have fire texture, how can I create vertex buffer for that? any example?

Thanks,

#4 Medo3337   Members   -  Reputation: 665

Like
0Likes
Like

Posted 05 June 2012 - 11:45 PM

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.

Attached Thumbnails

  • particle.jpg

Edited by Medo3337, 05 June 2012 - 11:50 PM.


#5 DJTN   Members   -  Reputation: 207

Like
0Likes
Like

Posted 06 June 2012 - 05:15 AM

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!

#6 Medo3337   Members   -  Reputation: 665

Like
0Likes
Like

Posted 06 June 2012 - 11:13 AM

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

#7 Medo3337   Members   -  Reputation: 665

Like
0Likes
Like

Posted 06 June 2012 - 01:24 PM

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

Edited by Medo3337, 06 June 2012 - 01:29 PM.


#8 Medo3337   Members   -  Reputation: 665

Like
0Likes
Like

Posted 06 June 2012 - 04:13 PM

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.

Attached Thumbnails

  • particles.png
  • particle side.png

Edited by Medo3337, 06 June 2012 - 10:18 PM.


#9 DJTN   Members   -  Reputation: 207

Like
0Likes
Like

Posted 07 June 2012 - 08:37 AM

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

Edited by DJTN, 07 June 2012 - 08:45 AM.


#10 Medo3337   Members   -  Reputation: 665

Like
0Likes
Like

Posted 07 June 2012 - 12:25 PM

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.

#11 DJTN   Members   -  Reputation: 207

Like
0Likes
Like

Posted 08 June 2012 - 09:15 AM

There is no general standard when it comes to particle engines or games engines for that matter. Only the API on which it is written (DirectX, HLSL, OpenGL, etc…). In most cases the technology created to render effects like particles are usually driven by the game’s requirements and specs.

A good developer always thinks in advance in order to maintain OOP and flexibility. Since Point Sprites are no longer supported by directX (no support in DX 10, 11 and 12) you can be sure hardware support will be limited with new iterations. Even when they were supported through hardware and DirectX 9, there were issues with how the hardware handled Point Sprites, particularly scaling in my situation.

The only "real" advantages of Point Sprites are that the hardware automatically transformed them to always face the camera and a smaller CPU footprint, but looking forward you can accomplish the same thing with geometry shaders – giving you a lot more flexibility.

For me, the "to use or not to use Point Sprites" is a no brainer but I cannot speak for you as I do not know your target hardware, requirements, or expectations.


Regards.

#12 Medo3337   Members   -  Reputation: 665

Like
0Likes
Like

Posted 08 June 2012 - 06:20 PM

What they use in most games out there to create particles (point sprite or 4 vertices quad)?

Is it possible to make the particles always face the camera through code?

Can you post example?




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS