Particles Engine and Slow FPS

Started by
41 comments, last by Medo Mex 11 years, 3 months ago

Hi!

I made point sprite based Particle Engine and sometimes I experience slow rendering when I create particles.

I'm trying to figure out why the particles are slowing down rendering.

Advertisement

One draw call per particle?

You're really going to need to give some more info about how your particle engine is set up, even provide some of your code, because right now the best you'll get from anyone is a guess. And the above is my guess, but without that additional info that's all I can do.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

Yep probably one draw call per particle. Batch your particles into a single draw call and that will speed things up. Another guess would be, depending on your code if your creating lots of particles in a single frame then that would cause that frame to be rather slow relative to frames that create no particles.

Exactly, that's what I was expecting. one draw call per particle.

I have been trying to make all the particles draw in one single call, but have some problems.

How do I make each vertex have its own texture? Usually I use device->SetTexture() but this will set only one texture for all the particles which is a problem.

So in that case, if different particles have different textures I'd group all the particles together that use the same texture then render each group, one draw call per group.

@Nyssa: What if the same group use 2 textures?

A common solution is to put multiple images into the same texture, then have each particle use only a portion of the entire texture.

What if the same group use 2 textures?

Hodgmans solution would fix that up for you :)

Another solution would be to simply make the particles that use 2 textures another group. What I'm getting at is grouping all the particles that share the same states together. Hodgmans solution performance wise would be better though! wink.png.

Yep, try to fit everything in one texture. You can even use 3D textures.

If you have order dependent transparency and multiple batches you can (will) run into problems, too.

Currently, I'm trying to fill the vertex buffer and currently running into problems:


device->CreateVertexBuffer(particles.size() * sizeof(PARTICLE_VERTEX),
                                              D3DUSAGE_DYNAMIC|D3DUSAGE_WRITEONLY|D3DUSAGE_POINTS,
                                              CustomFVF,
                                              D3DPOOL_DEFAULT,
                                              &vbuffer,
                                              NULL);
pVertices = new Particle_Vertex();
if (particles.size() > 0)
{
     vbuffer->Lock(0, particles.size() * sizeof(Particle_Vertex), (void**)&pVertices, D3DLOCK_DISCARD);
     for(int i = 0; i < particles.size(); ++i)
     {
          pVertices->pos = particles[i]->position;
          pVertices++;
     }
vbuffer->Unlock();

The particles are not rendering correctly, let me know how the above code should be fixed.

This topic is closed to new replies.

Advertisement