I just came across a problem for my particle system which I'm currently using to create weather effects like snow, etc.. Due to the fact the my particles, as supposed, use transparent textures, I have to order them manually from back to front. I got that working, but my speed is heavily decreased. Under normal circumstances, I can display about 100000 particles and the framerate stays at least acceptable (didn't do any culling or stuff) at around ~30-45. As for the sorting, since I do it I can't even have 10000 particles (a decrease by a factor of 10) without the game getting unplayable slow (~10 FPS). I do know why: I'm using a std::map<float, CParticle*>-object to store my particles depending on their distance to the camera and draw them reversly. As I already know map's are somewhat slow when they are used with huge amounts of containing objects, and 100.00 isn't such a small value at all. So my question here is: Is there any way to optimize my sorting? Any option to using map's? Can I use vertex/pixelshader for that? I just included shaders so I can basically use them but I'm not so experienced, so if there is an option can you explain to me how to do it? This is my rendering/sorting-method:
void CEmitter::Render(void)
{
m_lpDevice->SetRenderState(D3DRS_LIGHTING, FALSE);
m_lpDevice->SetVertexShader(NULL);
m_lpDevice->SetPixelShader(NULL);
map<float, CParticle*> Particles;
D3DXVECTOR3 Pos = m_Camera->GetPosition();
D3DXVECTOR3 Dist;
float Lenght;
for(int i= 0; i!=m_Data.Rate; i++)
{
Dist = Pos - m_Particles.GetPosition();
Lenght = D3DXVec3Length(&Dist);
Particles[Lenght] = &m_Particles;
}
for(map<float, CParticle*>::reverse_iterator ii = Particles.rbegin(); ii!=Particles.rend(); ++ii)
{
ii->second->Render();
ii->second->Update();
}
m_lpDevice->SetRenderState(D3DRS_LIGHTING, TRUE);
}
m_Data.Rate is the value of particles. Anyone got a solution here?