Particles Engine and Slow FPS

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

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.

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

Advertisement

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.


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

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

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());
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

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

I'm not using shaders, I'm updating each particle position D3DXVECTOR3 particles->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.

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

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

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.

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

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

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

This topic is closed to new replies.

Advertisement