Sunday 10 February 2013

Motion Blur


Motion Blur in today’s games

Today’s HD games demand the use of a lot special effects, which range from HDR, to bloom. All of these effects are done simply like a filter over the game, done as post processing after the scene is rendered.

 One of the more special effects is motion blur, done mainly to first/third person camera games, or any where the player can dynamically move the camera . The main reason is to make the camera movements more blurry, and in a way “more realistic”. Though the effect is most defiantly unique, it also is annoying, as a lot of people prefer to turn it off when playing their game. 

 Heres some examples of motion blur in action
 
Crysis 3 + motion blur 

MW2's trailer using motion blur

 Blurring in games 

The Blurring technique is done in countless games, is quite simple in concept. We start by mixing the color values of each pixel with the ones nearby.  Generally blurring is done with every pixel around it, in a 1 pixel radius, resulting in an area of 3x3 pixels per run. We average out this mixed color, and apply it to the pixels in the area.


 With this we can blur the sharpest pictures. Not only it be used for just for special effects, but it is also an important step used to help create a bloom effect.

How motion blur is done

To go any deeper, we would have to know about frame buffers, which are where the scene is rendered to prior to displaying them. Here in frame buffers we have many different values which we can pass in, and others we may not want to pass in. These may be the color of the scene, or the depth of the objects in the scene. 

For Motion blur, we need the depth buffer as input to a pixel shader program in order to generate the scene's general velocity. This shader program will compute the world positions for each pixel by using the depth value, stored in the depth buffer, and with the current frame's view-projection matrix. Once we determine the world position at that pixel, we can transform it by using the previous frame's view-projection matrix. Then we can compute the difference in the viewport position between the current frame and the previous frame in order to generate the per-pixel velocity values. A motion blur effect can then be achieved by using this velocity vector as a direction to gather multiple samples across the frame buffer, averaging them out along the way to generate a blur.
From all of this we can see how different the game can look after see it with motion blur. With motion blur, some people argue that it is a neccessity to have in future games. Not only does it give the sence of realism but it also allows for game developers to create less detailed games, while maintaining a great look. This is because motion blur warps our perspective, not allowing up to carefully examine objects in the scene. Whether motion blur is seen more in the future, or not, we cannot deny how important these "special effects" are in today's games.

Tuesday 5 February 2013

Lighting in XCOM-EU and games


Lighting in games 

Lighting is a very important part of games, as they help with the atmosphere that the game is trying to make. They can tension for making the environment too dark, or a very mystical feeling with many multicolored light sources. Lighting gives shadows, which helps tell players where they or other objects/ characters are in the scene. There are so many benfits of using lights correctly in today's games, but in order to understand how, we must look at what makes up lighting. Later we will look at how lighting is applied to XCOM: Enemy Unknown. 

Lighting, in games, is made of 3 parts, Ambient, diffuse, and specular lighting. 

Components of lighting

Ambient lighting- is the amount of lighting in scene and is from a non-directional light source. Generally tells the player if they are indoor, or outdoor, if it is day or night.
Diffuse lighting- is the reflection of the light from a surface, which is reflected at many angles rather than one, in the case of specular reflection below. This can show how powerful the light source is

Specular lighting is the use of bright spot highlights to give visual clues for light source locations. For example a red sphere with just ambient and diffuse lighting looks like the following:

Now if we add a white specular highlight we get the following result: 


Specular lighting is most commonly used to give light reflection off of metallic surfaces such as mirrors and highly polished/reflective metal surfaces. It is also used on other materials such as reflecting sunlight off of water. Used well it can add a degree of photo realism to most 3D scenes. All of this is from the source below www.rastertek.com/dx11tut10.html

Now we shall apply this to one of my favorite recent game, Xcom:Enemy Unknown! 

Xcom Gameplay

All my pictures are from the video provided in the link, about the introduction, and tutorial mission of XCOM: Enemy Unknown. Playing the tutorial mission of XCOM:EU, which was a pretty immersive experience, due to the fact it was taking place at night. After carefully examining each picture, we can see how lighting can affect the immersion of the game in each scene. How lighting can emphasize specific objects, or can convey a feeling to the players.

 This first picture takes place in the base of XCOM headquarters, right when we see the Xcom project being activated in the mission room. 
 The first picture seems to use a lot of diffuse but no specular, due to the fact there isn't metallic, or highly reflective surfaces. However there is a great amount of diffuse lighting from in this scene, as we can see with the huge amount of light reflected from the staff. This emphasizes how strong, and /or how close the light source, which in this case is a detailed hologram of the Earth. Important for the Xcom organization to monitor the state of the world, and lighting shows how important this globe is to XCOM.

This second picture also takes place in the base but focuses more on the soldiers, rather than the staffs. 
This shows specular lighting, with the metallic parts of the gun as the light source is probably in scene. Sure there is some diffuse here, but not as strong as the previous picture, showing how far the we are from a light source. What we should really focus on are the guns of the soldiers, which are affected by the specular lighting. If you notice, only the guns have specular lighting, but no the walls right beside it. Not only do the walls look more bland, but it draws your eyes more easily to the guns which will be used. This shows us how the omission of light/detail to nearby objects, can emphasize some objects in the scene.

The third and fourth picture takes place during the mission, where the soliders are outside during the mission in Germany. This is the first missions, and we are to meet up with an allied squad which seems to have gone missing.

As you can this takes place at night, greatly reducing brightness, and ambient lighting. However from a game designer's perspective, there may be some parts of the level, such as the detail on the dead soilder, which the designer might want the user to see well. For this the ambient has to be just right, too dark, and no details are visible, too bright, and it doesn't look like night.

Finally, during the mission, our squad goes inside to follow the radio sign which is being sent out. This radio signal seems to be from last surviving allied squad member, and we approach him in the picture below. 
The last solider of the allied squad is seen to be found to be in a state of unresponsiveness, however he is armed, and dangerous. In this picture our squad member approaches him however the only thing he says is "help me", suspiciously under the only spot light in the room . With this scene the ambient is turned down alot more the previous scene, and not just because we are indoors at night. This will make the soilder the focal point in the room, while increase the tension that player experiences, because we all know the darkness the hiting some secrets. Lack of lighting can obscure details, and this case the solider, and what is truely happening in this room. This obscurity, is what designers will use to add tension to games, especially when the player has just started the game.

Unfortunately what see is the solider is being mind controlled by some sort of alien creature, shown in the second picture. The situation quickly escalates as this becomes an alien ambush, and your first encounter with the extraterrestrial threat.


We can try to make out what this alien looks like, however the lack of lighting hides what the true identity of this creature is. We can make out with the lighting, that the alien is usual its head and hands to control the solider, due to its glowing appearance. There is no specular reflection, but that doesn't eliminate the fact it could have metal objects on it somewhere.
Also no diffuse lighting as maybe it isn't showing its true potential in this ambush.

In this case, ambient lighting is at its lowest, obscuring the whole alien darkness. This not only hides the alien's details, but it gives it that mysterious authority figure, like  the leader of the counsel of nations show earlier. All this obscurity will be haunt the player, until they truly can face this alien as a boss of a later level.

Applying the fundamentals of the lighting in games, from a game designers perspective, can truely enhance the game.Trying to implement the lighting is one problem for the engine designers, but properly using it in game would fit under the game designer's role. Hopefully we will see more games using light more effectively in the future, creating an immersive environment.

Friday 1 February 2013

Warhammer 40k Dawn of war 2- Shaders and Lighting


Warhammer 40k: Dawn of War 2- Chaos Rising is an expansion to the Dawn of war 2 RTS released in March of 2010. In this game, humans in the future of 40k will face the horrors of thier brothers who are corrupted by the forces of Choas. With this game the shaders, and other effects enhance the viciousness of the game, while immerse the player in the world. 
One place where shaders are apparently used are whenever the forces of chaos destroy major structures. We can tell that this effect is done with applying shaders to 2 different types of simple 2d shape, a circle, and a skyward rectangle. For the skyward rectangle seems to use a similar effect to "the god ray", having a dissipating, strong ray. For the bottom circle, there seems to be a rotating "fog effect" which changes as the long as the effect remains to functioning. With these shaders, this makes the destruction of the building look that much more like the work of choas.

Playing through the game I wanted to see if character lighting/shadow was truly global, and if there were actual lights there in the scene. For this I did a simple experiment, as I found a simple light, the lamp post in the middle of the map, and moved some units on each side.
To the right of the lamp post
To the left of the lamp post
Unfortunately, after examining this, I can see character lighting isn't calculated on the fly, as other "light sources", such as the lamp, don't truly seem to influence the character's shadows. Though the lamp seem to just be a source of light, with glow. However the shadows from the light seems to be non-dynamic, as they're just baked into the environment.

Finally there seems to shaders with the explosions of the game, which is best demonstrated by a brutal artillery strike on my squad.
During the artillery strike

After the artillery strike
We can see the destruction of the ground, there are multiple forces which emphasize the destruction of the battlefield. The deformation of the ground is probably done by changing of the object's vertices and/or change in the normals, into craters, based on the force of the artillery shells which hit.  This is most likely done with a vertex shader, altering all the locations of the vertices and normals. Another effect would be the application of "burnt ground" textures on the these craters, based on where the shells hit, to give it a burnt feeling. However just with a simple texture would be too bland so there seams to the red marks of freshly scorched Earth done by shaders. Each shader seems to apply the this scorched earth in patches, of random size and density to the texture. As we learned, this is passing through the text coord, and color, which makes it a fragment shader.

In the end, these effects are done with shaders, and lighting, make the game feel that much more chaotic. Not only are theses effects possible for us to implement, but also they show us how these effects can add to the immersion of the game. With these effects I look forward to seeing what future RTSs will do, and trying to implement them in future projects.