Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411476 Posts in 69369 Topics- by 58424 Members - Latest Member: FlyingFreeStudios

April 23, 2024, 02:43:53 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Box2D: Creating Many Particles at Once
Pages: [1]
Print
Author Topic: Box2D: Creating Many Particles at Once  (Read 1260 times)
xgibbousx
Level 1
*


View Profile
« on: June 20, 2017, 12:40:35 AM »

I have created a simple particle system with Box2D that instantiates multiple physics bodies at once or in a tight interval. On slower computers, there is a large delay while trying to create say 20 bodies at once or in a tight interval. It seems that body creation is expensive.

What would you recommend in order for me to create multiple bodies at once in Box2D to be used for a particle system?

Is there a way to pre-create the bodies and then emit them once I need them?

Thank you!
Logged
xgibbousx
Level 1
*


View Profile
« Reply #1 on: June 20, 2017, 08:17:51 PM »

I have done some deeper debugging (using debug breakpoint timing) and found that the slowdown is actually due to me constantly re-compiling a lighting shader for each particle that is instantiated. I now have to figure out a way to compile that shader once during game load and then reuse it... Should be an interesting exercise.

Box2D is actually impressively performant. Once I removed the lighting shader (just for testing) all the physics bodies instantiated with zero delay. I am now looking forward to splattering physics particles everywhere once I solve the shader issue above.
Logged
JWki
Level 4
****


View Profile
« Reply #2 on: June 20, 2017, 10:33:04 PM »

I have done some deeper debugging (using debug breakpoint timing) and found that the slowdown is actually due to me constantly re-compiling a lighting shader for each particle that is instantiated. I now have to figure out a way to compile that shader once during game load and then reuse it... Should be an interesting exercise.

Box2D is actually impressively performant. Once I removed the lighting shader (just for testing) all the physics bodies instantiated with zero delay. I am now looking forward to splattering physics particles everywhere once I solve the shader issue above.

Be careful with that, idk what size your particle systems have on average but usually treating every single particle as a physics object will eventually be VERY slow once they get a bit bigger which is why in modern engines you'll usually find GPU simulated particles to allow for actual collision and dynamics simulation.
Logged
xgibbousx
Level 1
*


View Profile
« Reply #3 on: June 21, 2017, 08:12:36 PM »

Be careful with that, idk what size your particle systems have on average but usually treating every single particle as a physics object will eventually be VERY slow once they get a bit bigger which is why in modern engines you'll usually find GPU simulated particles to allow for actual collision and dynamics simulation.

Agreed!

I actually got rid of the performance issue by making the shaders instantiated as static member variables inside static member functions so they get reused across all particles.

You are right though.  Once you get a ton of particles on screen, things start to slow down.  Therefore, I will have to implement some kind of short lifespan for the particles.  But it's fun for a while to just splatter blood and gibs everywhere before it slows down.
Logged
xgibbousx
Level 1
*


View Profile
« Reply #4 on: June 22, 2017, 07:40:25 AM »

Here's a video of what I've created so far in case anyone is interested:



Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic