• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Medo Mex

Particles Engine and Slow FPS

42 posts in this topic

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.

0

Share this post


Link to post
Share on other sites

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.

2

Share this post


Link to post
Share on other sites

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.

0

Share this post


Link to post
Share on other sites

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.

0

Share this post


Link to post
Share on other sites

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.

0

Share this post


Link to post
Share on other sites
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.

0

Share this post


Link to post
Share on other sites

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.

0

Share this post


Link to post
Share on other sites

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.

0

Share this post


Link to post
Share on other sites

You're really giving too little information to work with here.  There are some obvious things wrong with the above code, but without seeing, for example, what type pVertices is, without seeing what type particles is, without seeing the definitions of those types, without seeing some of your draw code - it's difficult to give you any genuinely helpful info.

0

Share this post


Link to post
Share on other sites

Here is the structure of pVertices:


struct Particle_Vertex {        D3DXVECTOR3 pos;        D3DXCOLOR color; };

 

"particles" is std::vector variable that contains information about each particle, I'm trying to fill the vertex buffer from std::vector particles.

0

Share this post


Link to post
Share on other sites

pVertices = new Particle_Vertex();
 


This is a memory leak. Remove this line of code. If you are doing this every frame, you will already see an improvement in your performance.

As for the rest, you do always have the option to actually describe what “incorrect” means. There are a million things it could be and the more information you provide the more easily we can guess where in the pipeline things are going wrong.
You have to help us help you.


Did you actually create the vertex declaration? Correctly? Is the shader correct? Are the matrices passed to the shaders correct? Is your shader’s WORLD matrix set to identity? Did you try debugging with PIX?


L. Spiro Edited by L. Spiro
0

Share this post


Link to post
Share on other sites

Hi L. Spiro,

 

The problem is basically related to the vertex position, I'm setting each vertex position according to std::vector particles:

 

pVertices->pos = particles[i]->position;

But I notice invalid particles position and invalid movement as well.

 

I fill the vertex buffer from std::vector particles and then draw using the following code:

 

D3DXMATRIX worldMatrix;
D3DXMatrixTranslation(&worldMatrix, position.x, position.y, position.z);   // position is the emitter position
d3ddev->SetTransform(D3DTS_WORLD, &worldMatrix);
d3ddev->SetTexture(0, texture);
d3ddev->SetStreamSource(0, vbuffer, 0, sizeof(PARTICLE_VERTEX));
d3ddev->DrawPrimitive(D3DPT_POINTLIST, 0, particles.size());
0

Share this post


Link to post
Share on other sites
If the frame of reference inside the shader is in emitter-local coordinates, what is the frame of reference for particles[ i]->position?
Double-check that you are not filling world coordinates into the vertex buffer directly; if you are, the world matrix sent to the shader needs to be identity.
I don’t see where you ever set the vertex declaration.

What did PIX tell you?


L. Spiro Edited by L. Spiro
0

Share this post


Link to post
Share on other sites

I'm not using shaders, I'm updating each particle position D3DXVECTOR3 particles[i]->position using for() { } statement

 

For the FVF:

 


#define CustomFVF (D3DFVF_XYZ | D3DFVF_TEX1)

 

device->SetFVF(CustomFVF);

 

Here is what I do:

First, I create the vertex buffer using device->CreateVertexBuffer() then I create array of Particle_Vertex and fill it with information from std::vector particles (position and color)

 

 

After that I render it using:

 

device->SetFVF(CustomFVF);
D3DXMATRIX worldMatrix;
D3DXMatrixTranslation(&worldMatrix, emitterPosition.x, emitterPosition.y, emitterPosition.z);
device->SetTransform(D3DTS_WORLD, &worldMatrix);
device->SetTexture(0, texture);
device->SetStreamSource(0, v_buffer, 0, sizeof(PARTICLE_VERTEX));
device->DrawPrimitive(D3DPT_POINTLIST, 0, particles.size());

Hope it's clear now.

0

Share this post


Link to post
Share on other sites

I guess you are updating the vertex declaration every frame. That answers 1 of my 3 points.
Let me clarify my previous reply.

#1: Don’t fill the vertex buffer with particles’ world coordinate if you are going to also be passing a non-identify world matrix to Direct3D. I just have an itching feeling that tells me you are storing raw world coordinates inside particles[ i]->position since that is how most of these kinds of implementations work.
#2: What did PIX tell you? I.e. I know you didn’t actually use PIX but I was trying to give you a chance to take it upon yourself and use it before your reply so that it would seem as though you used it on your own without having to be repeatedly told to do so.
PIX is our greatest source of knowledge in these kinds of situations and at this point no one will likely be able to help you until you have used it and posted some screenshots.

PIX is a tool that comes with the DirectX SDK.
Open it. Start a new project. Browse to your application. Hit the button that says it will take one screen capture when you hit F12, and start the “experiment”.
View your wrong particles and hit F12.
Close your game. PIX now allows you to step through every call you made to Direct3D. There are shortcuts to go directly to draw calls. Use them.
On the right side you have to click the Render tab. This will allow you to find the draw call that draws your particles.
In the list of commands, double-click the last vertex buffer you set (it will be blue and underlined). Check its contents. Are the positions all correct?

You can use this to verify a lot of things.
I suggest you spend a few hours with it before posting back here. You will typically be received better if you have shown a little effort to help yourself first. I don’t want to see you just checking the vertex buffers (or failing to find them because there are also many tutorials/resources online) and then just posting back with a quick, “OK I checked looks fine now what?”

Your mission, should you choose to just accept it, is to use this amazing new resource at your disposal to verify no fewer than 10 points and post back with a bullet list of no fewer than 5 things you checked/verified/thought suspicious.

 

 

L. Spiro

1

Share this post


Link to post
Share on other sites

The position problem was resolved by setting the world matrix to identity, it's now working perfectly, but still I see no difference.

 

The particles are slowing down rendering.

 

Do you still need information from PIX even after resolving the positioning issue?

Let me know what could be slowing down rendering, I'm now doing one draw call per emitter instead of one draw call per particle.

0

Share this post


Link to post
Share on other sites

Did you remove that memory leak I mentioned?

What do you means slowing down rendering?  All the time?  Over time getting unreasonably worse?  Over time getting reasonably worse (getting worse over time but in proportion to the number of particles being drawn)?

 

 

L. Spiro

Edited by L. Spiro
0

Share this post


Link to post
Share on other sites

Yes, I removed the line that was causing memory leak.

 

Not overtime getting worse, neither all the time its slowing rendering.. I'm getting slow rendering when I create some bullet impact smoke based on firing weapon (when I have 10 bullet hits for example I create 10 emitters and so on).

 

However, when I create rain/snow I don't have any problem.

 

Another problem is that when I create some sort of environmental smoke (like a blizzard smoke) I feel like it's flashing. (I didn't have this problem when I was doing one draw call per particle).

0

Share this post


Link to post
Share on other sites

When things start getting slow are the particles quite large and/or taking up a significant portion of the screen?  If so, then it's just simply overdraw and is expected behaviour.

0

Share this post


Link to post
Share on other sites

@mhagain: Not large at all, just a small smoke from bullet impact, when I draw some smoke on different bullet hits infront of the screen, I see well noticed slow rendering.

 

This means that whenever the player is shooting, the rendering will slow down due to smoke particles.

0

Share this post


Link to post
Share on other sites

[quote name='Medo3337' timestamp='1358314169' post='5022064']
This means that whenever the player is shooting, the rendering will slow down due to smoke particles.
[/quote]

 

Is the rendering slowing down only the moment the player shoots or is it slow as long as the particles are visible?

Possibly the way you allocate new particles is slow.

0

Share this post


Link to post
Share on other sites

Are you recreating the dynamic vertex buffer every frame? That's likely to cause slowness. 

0

Share this post


Link to post
Share on other sites

I am doing the following every frame:

 

device->CreateVertexBuffer(particles.size() * sizeof(PARTICLE_VERTEX),
                           D3DUSAGE_DYNAMIC|D3DUSAGE_WRITEONLY|D3DUSAGE_POINTS,
                           CustomFVF,
                           D3DPOOL_DEFAULT,
                           &vbuffer,
                           NULL);

That could be slowing rendering, but I need to update the buffer length every frame since the number of particles will not stay the same.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0