View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# Particle Engine, Creating alot of Rain/Snow

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.

12 replies to this topic

### #1Medo3337  Members

Posted 07 June 2012 - 08:20 PM

I have created a particle engine, basically, it create ONE single vertex using CreateVertexBuffer() and rendering it as much as particles we need.

Using the class I assign the number of particles that I want to generate at once, I am using "for() { }" statement to generate that number each time like the following:

void RenderParticles(...)
{
// Some other codes goes here...

for(DWORD i = 0; i < maxNumOfParticles; i++)
CreateNewParticle();

}


When I create a rain usually I set a high number for maxNumOfParticles number like 150-250, so I can have alot of rains rendering (if the weather is so rainy).

However, the rendering SLOW down when 'maxNumOfParticles' is high, making the game slow even on a modern graphic card.

Edited by Medo3337, 07 June 2012 - 08:23 PM.

### #2jefferytitan  Members

Posted 07 June 2012 - 08:56 PM

It's hard to tell from this sample how you're using it. Are you instantiating objects every frame? Are you drawing each particle with a separate call instead of batching? Is each particle literally one raindrop? I would think that if you had a few different rain textures (each containing a few randomly scattered raindrops with alpha), players wouldn't notice that each raindrop wasn't an individual particle.

### #3Medo3337  Members

Posted 07 June 2012 - 10:56 PM

Each time DirectX render, I create particles according to

maxNumOfParticles, here is what I use on each frame:

for(DWORD i = 0; i < maxNumOfParticles; i++)
CreateNewParticle();


### #4jefferytitan  Members

Posted 08 June 2012 - 12:16 AM

Hmm, I don't think we're quite on the same page. Here are my questions:
• Does one particle = one raindrop?
• How many textures are you using for your particles?
• What does CreateNewParticle do?
• Are you allocating new vertices or textures in CreateNewParticle?
• Is each particle rendered as a separate batch? One thread on here concerned a developer who was drawing a circle using approximately 100 line segments. With begin and end after each line segment the speed was terrible. As one batch it was very fast.
• Does CreateNewParticle just perform rendering of an existing particle, or create a particle?
• Where is the code for moving a particle?

### #5Medo3337  Members

Posted 08 June 2012 - 12:27 AM

1. Yes, one particle = one raindrop.
2. I am using only one texture for the rain, each particle (raindrop) set the same texture.
3.
1. Only ONE single vertex created at loading time, and used in rendering to create different raindrops.
3.

CreateNewParticle() ONLY create new particles and it does that only during rendering process.

4. The code for moving particles is inside RenderParticles() method

Basically, I ONLY create ONE single vertex for ALL the particles, this vertex is rendered as many as the particles with different matrix world so I can get the particles to move in different positions, I am using point sprite.

### #6mhagain  Members

Posted 08 June 2012 - 05:36 AM

The key question being asked here is how many draw calls do you have? Do you have one draw call that handles all of your particles, or do you have one draw call per-particle? The fact that you have a different matrix for each particle suggests the latter, in which case - yes - it's going to perform terribly. You really need to post the code you have for CreateNewParticle and RenderParticle here - and the full code, not just an excerpt. It's not enough to describe what they do as it's not possible to correctly analyse why you're running slow based on a mere description - hence all the questions.

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.

### #7dAND3h  Members

Posted 08 June 2012 - 09:22 AM

As pointed out above, it seems as though you are rendering and updating for each particle! Think about that and you will see why it will slow down. If you have 10,000 particles, each one has to create a new transformation matrix (10,000+ operations) and each one will render itself separately(10,000+ draw calls).

Most modern particle systems use the GPU for both rendering and calculating positions. And then some sort of particle collision system on the CPU. Using the GPU , you will then batch alot of particles together, in a DynamicVertexBuffer which will be sent to the graphics card at once! Turning 10,000 draw calls into maybe 2 or 3!
You should post both the CreateNewParticle and RenderParticle methods.

Edited by dAND3h, 08 June 2012 - 09:25 AM.

### #8DJTN  Members

Posted 08 June 2012 - 09:44 AM

I'm confused because in your other post (that I just repied to) you stated you were using Point Sprites. In this post your refering to vertices, implying quads. In any event, like the above posts, we'll need to see your render function at the very least. Performing a transformation and a draw call for each particle is highly inefficient.

### #9Hornsj3  Members

Posted 08 June 2012 - 11:08 AM

So I'm reading this and wondering. Would the best way to do this be to have 1 particle and instance it with separate transformation matrices? Sorry if I just hijacked your thread.

### #10DJTN  Members

Posted 08 June 2012 - 02:04 PM

So I'm reading this and wondering. Would the best way to do this be to have 1 particle and instance it with separate transformation matrices? Sorry if I just hijacked your thread.

I'd use a list of particles, updating their positions in a dynamic vertex buffer, calculate the world matrix once and then draw with the D3DDevice->DrawIndexedPrimitive (triangle list) method. But depending on your target hardware and version of DX, you can do almost all of it on the GPU these days.

Edited by DJTN, 08 June 2012 - 02:05 PM.

### #11Medo3337  Members

Posted 08 June 2012 - 03:24 PM

@DJNT: I am using point sprites (billboarding) each vertex contains one texture.

### #12mhagain  Members

Posted 08 June 2012 - 05:51 PM

I personally use one vertex (containing initial position, velocity, gravity factors, acceleration, time-since-spawn, etc) with forward/left/up values as shader constants, combined with instancing - everything is computed on the GPU from there and up to 16384 (arbitrary choice) particles are drawn per draw-call. There's no need whatsoever for any matrix changes and it runs faster than a slippery snot on a slope.

Again - show some more code, and how many draw calls?

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.

### #13jefferytitan  Members

Posted 08 June 2012 - 08:26 PM

I think the other posters are on the same page as me. You may be making savings on the CPU by using a single vertex, but you're punishing the GPU by making many separate draw calls. It would probably run better if you had 200 vertices but pushed them through in a single batch.

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.