Hello Guest

Author Topic: Best Solution for Rendering Particles?  (Read 6224 times)

Krin

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 7
    • View Profile
Best Solution for Rendering Particles?
« on: August 28, 2013, 11:11:38 am »
Hey,

I've written a custom particle system to work with tk2d and I'm looking to improve its speed. I'm targeting mobile, and looking to render around 300-500 particles at a given time. My current solution has each particle as a monoBehavior, attached to a GameObejct with a tk2dSprite. But I'm wondering if there is a faster way to do this? Perhaps without involving GameObjects?

For example, I could make the particle just an abstract class, shove them all into a big List and then (somehow) draw the entire List as once so that I don't need to have hundreds of GameObjects in the scene?

Any advice or suggestions would be appreciated! Thank you :)

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Best Solution for Rendering Particles?
« Reply #1 on: August 28, 2013, 11:15:04 am »
If you create them as GameObjects you'll be limited by that.
Your best bet is to create a buffer as you suggest, and fill it dynamically using the sprite data. Its pretty straightforward, and even more so if you limit that all your particles are quads, etc.

Krin

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Best Solution for Rendering Particles?
« Reply #2 on: August 28, 2013, 11:30:05 am »
Ah yes, buffering and filling with sprite data sounds like the thing I'm looking for. Is there any documentation on how to do that? And will I still be able to use vertex colors and images from SpriteCollections?


unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Best Solution for Rendering Particles?
« Reply #3 on: August 28, 2013, 11:33:30 am »
You can do whatever you like if you're filling your own buffers ;)
I'd take a sprite class (eg. clipped sprite) and then modify it so it can display 2 sprites as a start - you should be able to work your way from there...

Krin

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Best Solution for Rendering Particles?
« Reply #4 on: August 28, 2013, 11:38:32 am »
Alright cheers, I'm gonna give it a shot :)

Krin

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Best Solution for Rendering Particles?
« Reply #5 on: August 28, 2013, 01:47:11 pm »
I've been trying to do as you suggested and am modifying a new Sprite class to buffer the draw.

Now for the actual drawing part - am I correct in thinking that I would need to Clear() / rebuild the mesh each Update (perhaps override the Build() method) with the calibrated Verticies + UVs with the Particle data? Or am I missing something?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Best Solution for Rendering Particles?
« Reply #6 on: August 28, 2013, 01:56:07 pm »
You'll have to clear the buffer and fill it up. Overriding the Build method will work too.
I suggested that class simply as reference on how to get the geometry to fill up the buffer. Filling up the buffer is pretty straightforward, but you'll need some way of actually controlling your particles, etc.

Krin

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Best Solution for Rendering Particles?
« Reply #7 on: August 28, 2013, 02:48:26 pm »
Huzzah! I think it works :D I tested it with 5000 particles and it ran at 60 FPS on a standalone build, so I think the concept is correct. I basically pass in a list of particle data (x, y, z, scale, color, rotation) and it clears the meshes and UVs and re-draws it with the new data each update (which I guess is the way I'm supposed to do it?)

Just wanted to say thanks for the quick support and pointing me in the right direction.

Now it's time to test and optimize it for mobile... Wish me luck :P


unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Best Solution for Rendering Particles?
« Reply #8 on: August 28, 2013, 04:08:40 pm »
Yup. Thats it pretty much.
As long as you don't go crazy, this should run pretty well on mobile too :)