Friday, 31 January 2014

Theory Time: The Last Of Us

So the last two weeks have sort of been off weeks for me and I haven't quite been up to trying to get my thoughts to congeal into something useful...Needless to say that Particles 2: The Re-Particling is being saved for another day and will probably be a lot bigger than anticipated (I'll try not to make part 2 have its own two parts). I also don't want to just sit here and type up a blog regurgitating everything we learned in class because that would literally be me just drawing out things like toon shading into 3 paragraphs when it could be summed up pretty quickly. 

Instead what I'm going to do is take this chance to introduce what will (hopefully) become a regular thing I do: Attempting to break down how they created an effect in a game without actually looking it up! This is just because I think it'd be a fun exercise and a nice way to actually think about the application of what we've learned. So without further preamble...I will now talk about The Last of Us.

In The Last of Us the player can enter a mode where sounds are more amplified for the character. In order to convey the change in action to the player and to simulate the effect, the screen becomes desaturated and sound sources are given a white glow. This is a demonstration of multiple effects working together as we have the fullscreen effect (desaturation) and the target specific effect (glow around sources). 

                       

I believe the method for this effect was done by first getting an outline of the targets with a glow using a similar method for getting an outline with a toon shader so we would check and see if the dot product of the normal of the fragment and the vector from the position to the eye meets a certain specification (e.g. it's equal to 0) to determine if it should be used for the outline. Once we have the outline we would use that to create a new texture to store and then blur (to give the fuzzy outline). In order to give the clear outline of the body we would again use the target but instead of trying to find an outline we would want to generate a silhouette which we could use to create a mask. When we go to combine the two we only render the parts of the blurred outline which are not blocked by the mask. Once this is done we now have a white fuzzy outline of all the entities which are producing sound in the game, we can then apply a shader to the FBO to desaturate it before overlaying and blending the glow outlines resulting in the final product that you see above.

And so there's my post! In the coming weeks I may spend some time trying to recreate this effect as I just described here to see if I was right or not, but until then it's just fun to theorize. Here's hoping that next week I'll have a lot more to write about.

Cheers,
Cameron Nicoll

Friday, 17 January 2014

Particle Fun

So in this past week my group managed to get particles working in the game, the system used is one that I had made last term and it was updated by the lead programmer (Kenny) to work with the rest of the game. In light of this, I'm going to take the chance to talk about the development of the system, any future plans for it as well as what interesting effects we should be able to attempt later on in the term as well as particles in general.

Introduction
So to give a bit of an overview of what our system contains: We have a Particle class, which is used for each individual particle in the system and contains the force being applied to the particle, the position, colours, etc. The particles I use are simple billboards, that is to say they consist of two triangles with a sprite applied to them; A Particle System class, which contains is used to update the list of particles as well as all the information relative to spawning new particles (e.g. the spawn deviation (the area around the center of the system in which a particle can spawn), the spread deviation (the range for the particles impulse velocity), etc.); A Particle Manager, which is a singleton that holds a list of Particle Systems which can are all updated and drawn through this manager. The specifics of each of these will be explained in more detail as I go through the development.

The Particle and Particle System
So I'm going to sort of speed through the first few hours of the development. I started off with a single Particle, it wasn't tied to any system (the System class not having been made yet) and lacked some of the functionality it has today. The particle could have an impulse force applied giving it acceleration which would make it move and such.

Once I had the particle moving and rendering properly, I started work on the System aspect. This started it's life as something that would just spawn a bunch of particles and let them loose...It was pretty boring. That's when I began to go a little crazy with it and began to add all these little extra things as they popped into my head. I think it's easier if I just list them at this point so here's all the extra features I went ahead and added as time went on (in order):
Spawn Deviation - This allowed me to specify an area around the center of the system which a particle would be randomly spawned in. So if I specify a minimum spread of [-5,-5,-5] and a max of [5,5,5] then the particle will spawn anywhere within a 10x10x10 cube, treating the System's position as the origin.
Spread Deviation - This  would add an impulse velocity of a random value to a particle, based on the same min-max idea as the Spawn Deviation. This is particularly useful as it can let me make particles spread out from a source or fly in random directions along a plain or make it look like a steady wind is affecting the particles.
Decay Values - I decided to spruce up the particles themselves by adding an initial/decay colour and initial/decay transparency. The initial values are the values of the particle when it spawns and the decay values are the values of the particle when it dies. I then interpolate between these values LERP and the particle's current life (normalized) to figure out what the current colour should be.
Life Range - So the standard particle has a life time to it, which basically says how much long the particle will be around for before it dies. To make the system appear a bit more dynamic I made it so that you could specify a range which will change how long the particle is alive for. For example, if you add a Life Range of 0.5 and the life of the particle is 2, then particles will have a life time that will be randomly determined to be within 1.5 and 2.5
Scale Deviation - This lets you add a randomization to the scale of each particle so that some will appear smaller and some will appear larger. This is also to help with the more dynamic appearance of the system.
Volume Types - This let me specify the different volume types for the systems. This really only impacts the spawn positions of the particles so that they're limited to be within a cylinder or a sphere, rather than a regular and boring cube. When coupled with the next feature it can also lead to other things such as rings.
Min-Max Radii - This let's you specify a minimum radius and a maximum radius within which the particle should spawn. This discards any particles which are spawned outside of the specified range.
Explosion Types - To make things a bit more interesting I added the ability to set the system to an explosion type. These will make the particles fly away from the center of the system or towards the center of the system to simulate an explosion or an implosion respectively.

Okay. That's it for the development of my System (the manager was introduced later but it doesn't add any interesting visuals to it, and then Kenny updated it to render in newer versions of OpenGL using the GPU). To take a break from the wall of text I'm going to just show you a couple of examples of what the results of the system are. I'll include the sprite beside the system it's used with.





 So these are the kinds of particles we have now. Really simple, just slight modifications to the colours of the actual sprite and letting them blend with each other. Some of the results can be quite impressive but it is pretty limited in terms of the types of visuals you can pull off, even with shaders...
OR SO I THOUGHT!

Particles with Frame Buffer Objects
So FBOs (Frame Buffer Objects)are just fantastic with shaders. They let you take things up to another level by allowing you to influence the raw final data of the system during each update rather than being able to only affect each individual particle. For example, let's break down this ink particle effect from the game Brutal Legends which can be found here: http://vimeo.com/10082765

So as you can tell right off the bat, each particle is just a semi-transparent black spot which is moving around (though that's going into Fluid Dynamics which is a tale for another day). We let the particles move around according to their dynamics and when we go to render we begin thresholding in the fragment shader. If a value that will be outputted is below a certain value then it will be discarded, eliminating the more translucent aspects from the render process while they can still be used to calculate the positions of the other particles. After the values have been discarded we do another pass of the image and add a blur to it which gives the particles their lighter outline. The result is a flowing ink effect.

Naturally there's plenty more we can do now that we can actually apply effects to the final results of a particle system rather than each individual particle, which should help make things plenty interesting. Though that doesn't mean we should make each system render using a FBO, in some instances like the first particle system I showed we may just want to use it as is, in which case a VBO would be better as it would not be as stressing on the hardware though this goes more into optimization than anything else.

Looking back I may have jumped the gun on this blog a bit. It's starting to drag out a bit so I think I'll call this part 1 of a series of posts on particles. Next time (which may or may not be next week, we'll find out) I'll go into other interesting things we can do with particles as well as how we can use the GPU to help improve the current system.

Until next time, cheers!

Friday, 10 January 2014

From Humble Beginnings and Other Cliche First Titles

So before I get into talking about the course there is something I should probably get off my chest and out into the open:
FLUIDDYNAMICSANDREFLECTIONANDPARTICLESANDALLTHEFUNSTUFFICAN'TWAITTOGETSTARTED!

Okay now that I've gotten that out of my system I can move on to the actual blog. This course has been the focus of much of my excitement once I began to properly understand the implications of shaders and such so I'm coming in with a handful of topics that greatly interest me (aside from the standard ones such as shadow mapping).

One thing I'd really like to cover in-depth a bit is the different effects we can now achieve with particle systems. I had worked on one last term which had become my pride and joy as it was quite versatile in terms of the effects that could be pulled off with it as well as looking quite good. However, being a CPU based system, it was pretty limited. I know that one effect which we'll be able to achieve by the end of the term is the ink particle used in Brutal Legends but being given a demonstration of how it would work as well as what other interesting particle effects we could do would be really interesting.

I'd also like to get into Fluid Dynamics as it's an interesting topic and produces such interesting effects (such as the ink particle previously mentioned). I think that it could be used for a lot of interesting particle systems as well as applications for other things such as cloth.

Finally I would love to go into making realistic water with reflection and refraction as I find it to be an interesting effect that can add nice little touches to the appearances of games in some cases and can be hugely important in others.

I'm sure that all of these topics will be covered at one point or another and I'm really looking forward to it. That being said, it'd be fantastic if we had a lecture that was just going over interesting particle systems and covering how they were created. 

That's it until the next time. Cheers!