Sunday, January 19, 2014

Particle System!

So as I mentioned in my Lacadia blog post, I've gotten a little side tracked and started a new project with particle systems in Monogame/XNA. The whole point of this project is to see how many particles I could have on the screen without falling below 30 fps. It was an interesting challenge, and it has definitely taken me places I did not expect to go. And by that I mean shaders. From my understanding, a shader is code that is run on your GPU with input from your CPU. So the big thing is take all of the computation and stuff you're doing on your CPU and does it on the GPU; it's much faster.

So in order to do this I had to learn about HLSL or high level shader language. It was pretty interesting to learn about actually! I hit a couple bumps in the road, but now I've gotten my shader working quite nicely. It can now do lighting, color fades, and color changes! Pretty cool stuff.

So let me take you through the events so far. I first start my project, using the same strategies I used in Lacadia for particles... I end up only being able to render ~2200 particles before I get down to 30 fps. Not cool! I don't quite remember how I found out about using shaders, but I investigated thoroughly, and after quite a lot of fiddling and learning, I was then able to get ~4000 particles rendering before 30 fps. You'd probably expect more, but I was actually making a really dumb error. So the way I was passing all the particles information to the GPU before was looping through each particle, and sending its information to the GPU, drawing it, then moving on to the next one... Well I ended up compiling all the vertices of the particles into a list of vertices, and sending them all at once to the GPU... HUGE increase in the number of particles.... I went from ~4000 to ~24,000 particles with 30 fps. 6 times as many! It was an awesome discovery! That puts me where I am today, and honestly i'm not quite sure what else I can do as of now to increase that number even more.

So what I've been doing lately, is investigating light sources with shaders, because I think I want my next game to have some sort of dynamic lighting, its pretty cool looking! So I've implemented a point light, that can have different colors of lights. I'll put the video down below as it's much more clear!

Hope you enjoy!

No comments:

Post a Comment