Tag Archives: Ambient

A look at Prince of Persia: The Forgotten Sands game engine

In my last Game Engine Design class which was on Halloween, the disappointment of my professor’s lack of costume was neutralized by showing us videos of two Prince of Persia games; The Forgotten Sands and Warrior Within. We were tasked with identifying different aspects of the game engine of the former, often criticizing some of the inner mechanics despite its blockbuster production values and technological achievement.


Prince of Persia: The Forgotten Sands is a 2010 multi-platform game developed by Ubisoft. Any developer will tell you how tasking it is to design the engine to work with certain consoles, similar to car engines, they need to be carefully constructed with the capabilities and limitations in mind. The version we looked at to my recollection is either the PS3 or Xbox 360 version.

My primary grievance with the engine is the sloppily put together animation layering. Most of what I know from animating layering comes from Uncharted 2 and their hierarchal structure of their character kinematics. How it works is that limbs, hands, feet and other body parts are each animated separately while using triggers to switch between animation states according to either your character’s relation to the world and/or according to your character’s action.

The issue with Prince of Persia: The Forgotten Sands’s animation layering is that it lacks detail and feels rushed, for example. When your character grabs onto ledges or walks on the wall for a few seconds, the hands don’t seem to grip on anything, it feels like that Game Jam game Surgeon Simulator where your hand can’t grip on anything.

Spider Prince, spider prince, the bad layering and lack of collision makes me wince.


A major part of gaming is investment, it’s difficult to invest in your player’s actions if something like grabbing onto something doesn’t feel solid. Internet critic and entertainer Doug Walker, under his persona the Nostalgia Critic, attested Tom & Jerry’s effectiveness in its craft due to how solid the animators can make objects, hence enhancing the slapstick.

This technique can also apply to games. Take Ninja Gaiden Sigma for example, when I look at what Prince of Persia: The Forgotten Sands did wrong, Ninja Gaiden Sigma did right. When Ryu climbs, runs along, or jumps off of the walls, you can feel every one of his steps colliding with force on the wall. An example of lack of solidity would be Sonic Heroes a game I loved since my youth, has an issue with enemies feeling too not rigid to the point where you can almost breeze through them like air when your character’s get strong enough. (I may blog about that game’s engine some time down the future) Naruto Shippuden Ultimate Ninja Storm 3 is a game that manages to have both soft and hard collisions. A combat based game at its core, you have your strong, medium and weak attacks, and naturally they make for collisions of the same level of force provided your attack damages your opponent.

It’s difficult to really attest for the force of collisions in games for a lot of people without really playing the games. Though gaming veterans and people involved in the field should be able to immediately identify such deficiencies.

The game’s biggest issue is its AI and how incompetent they are. You know how in movies every enemy attacks one at a time rather than all at once? That’s the game’s AI to a tee. If that’s what the programmers were going for then I’d still protest that they robbed players of a challenge. It doesn’t help that the AI moves at a snail’s pace, both in traversing towards you as well as their attacks. It takes then, no lie, 4 seconds to land a hit on you. Though your attacks are delayed as well, so it all balances out right? WRONG! That’s just bad combat. It’s not even satisfying to kill them due to the sound effects which sound like you’re being blocked rather than tearing away at their flesh.


Yeah just stand there and look intimidating, I’m sure that’ll scare the guy who can move himself more than 2 meters per second.

Once again I must refer to Ninja Gaiden Sigma, when your attacks are blocked, you hear a metallic sound effect, but when you hit you can hear the sound of your weapon tearing his flesh off his skin or bones being broken. It also helps that said game has brilliantly programmed AI whom are nearly as capable as your character, presenting a lot of challenge, a demand for skill on your part and the satisfaction of overcoming said challenge. Which means you better bring it in the boss battle.
Seriously, have I hammered it into your brains already? Go play any of the Ninja Gaiden Sigma games.

I’ve been pretty hard of Prince of Persia The Forgotten Sands all this long. The truth is, despite its shortcomings, its engine has many positive aspects. One of them is its marriage of the camera system and trigger system. The camera manages to follow your character all over the level, placing itself in dynamic and interesting angles whilst capturing the emotions of the environment and situation. This means that when an explosion happens, the camera moves to emphasize the collision.


Perhaps the best example is when the character swings on poles, the camera very subtly moves along with him as he swings, seemingly taking you as the player along with the ride. Parts where you’re assigned an object through an in-game cutscene, the camera will pan to point out where you’re supposed accomplish your task.

Despite the faults of the animation layering, the kinematics is above average by industry, AAA standards. The screen space ambient occlusion is top notch, and gameplay is most likely fun as ever, wouldn’t know though as I haven’t played it. Modelling, texturing, shader rendering, and movement is all top notch as well.


Warrior Within proves to be a superior product despite its technological inferiority; the engine provides much better animation layering, combat kinetics and overall collisions for all the reasons opposite to that of The Forgotten Sands. The former simply has more polished mechanics. In this battle of supremacy, the old proved superior to the new; hopefully developers take not of what it means to deliver on a polished engine.

Ambient, Diffuse, Specular and Emissive lighting

The Light Model covers ambient, diffuse, specular, and emissive lighting. This is enough flexibility to solve a wide range of lighting situations. You refer to the total amount of light in a scene as the global illumination and compute it using the following equation.

Global Illumination = Ambient Light + Diffuse Light + Specular Light + Emissive Light


Ambient Lighting is constant lighting. It is the light an object gives even in the absence of strong light. It is constant in all directions and it colors all pixels of an object the same. It is fast to calculate but leaves objects looking flat and unrealistic. 


Diffuse Lighting relies on both the light direction and the object surface normal. It varies across the surface of an object because of the changing light direction and the changing surface numeral vector. It takes longer to calculate diffuse lighting because it changes for each object vertex, however the benefit of using it is that it shades objects and gives them three-dimensional depth.


Specular Lighting recognizes the bright specular highlights that occur when light hits an object surface and reflects back toward the camera. It is more intense than diffuse light and falls off more rapidly across the object surface.


It takes longer to calculate specular lighting than diffuse lighting, however the benefit of using it is that it adds more detail to a surface.


Emissive Lighting is light that is emitted by an object such as a light bulb.


Realistic lighting can be accomplished by applying each of these types of lighting to a 3D scene. The values calculated for ambient, emissive, and diffuse components are output as the diffuse vertex colour; the value for the specular lighting component is output as the specular vertex color. Ambient, diffuse, and specular light values can be affected by a light’s attenuation and spotlight factor.

To achieve a more realistic lighting effect, you add more lights; however, the scene takes a longer time to render. To achieve all the effects a designer wants, some games use more CPU power than is commonly available. In this case, it is typical to reduce the number of lighting calculations to a minimum by using lighting maps and environment maps to add lighting to a scene while using texture maps.

Lighting is computed in the camera space. Optimized lighting can be computed in model space, when special conditions exist: normal vectors are already normalized (D3DRS_NORMALIZENORMALS is True), vertex blending is not necessary, transformation matrices are orthogonal, and so forth.

For example there is the OpenGL lighting model with ambient, diffuse, specular and emissive lighting. This model is mainly used but there are many other models for lighting. In fixed-function OpenGL only this lighting model could be used, no other.


With Shaders you are able to write your own lighting model. But that’s only one feature of shaders. There are thousands of other really nice possibilities: Shadows, Environment Mapping, Per-Pixel Lighting, Bump Mapping, Parallax Bump Mapping, HDR, and much more!

Screen Space Ambient Occlusion – Application in games

I’ve been working on a screen space ambient occlusion code for a few weeks and I’ve managed to get a working project going, so I feel I’m qualified to talk about it. So let us begin. In computer graphics, ambient occlusion attempts to approximate the way light radiates in real life, especially off what are normally considered non-reflective surfaces. Like in my example here:


Unlike conventional methods such as Phong shading, ambient occlusion is a global method, meaning the illumination at each point is a function of other geometry in the scene. However, it is a very crude approximation to full global illumination. The soft appearance achieved by ambient occlusion alone is similar to the way an object appears on an overcast day.

The first major game title with Ambient Occlusion support was released in 2007, yes, we’re talking about Crytek’s Crysis 1. Then we have it’s sequel Crysis 2 as shown here:


It’s a really cheap approximation to real ambient occlusion, it’s used in many games. It is cheap, although it does draw out a significant overhead compared to running without SSAO on. Mafia II churns out 30-40 fps when I turn on AO on max settings without PhysX, but when I turn AO off it’s silky-smooth at 50-75.

Without ambient occlusion:


Screen space ambient occlusion is improved in Crysis 2 with higher quality levels based on higher resolution and two passes while the game’s water effects – impressive on all platforms – are upgraded to full vertex displacement on PC (so the waves react more realistically to objects passing into the water). Motion blur and depth of field also get higher-precision upgrades on PC too.

With ambient occlusion, note the presence of darker areas. 


 While there may only be three different visual settings, it’s actually surprising just how low the graphics card requirement is to get a decent experience in Crysis 2. In part, PC owners have the console focus to thank here – Crytek’s requirement of supporting the game on systems with limited GPUs and relatively tiny amounts of RAM required an optimisation effort that can only benefit the computer version.

According to the developer, the base hardware is a 512MB 8800GT: an old, classic card that’s only really started to show its age in the last year or so. On the lowest setting (which is still a visual treat), this is still good for around 30-40FPS at lower resolutions such as 720p and 1280×1024. If you’re looking for decent performance at 1080p, a GTX260 or 8800GTX is recommended while 1080p60 at the Extreme level really requires a Radeon HD 6970 or GTX580.

In terms of the CPU you’ll need, things have definitely moved on from the days of the original Crysis, where the engine code was optimised for dual-core processors. Crysis 2 is quad-core aware, and while it runs perfectly well with just the two cores, ideally you should be targeting something along the lines of a Q6600 or better.

Nowadays we have a bunch of DX10 & DX11 games that make use of Ambient Occlusion natively ( via their own engine ), Crysis 2, Aliens vs Predator 3, BattleField 3, Gears of War 2, etc.

Still, there are several new titles without Ambient Occlusion support, and also older games that would benefit from it. nVIDIA came to the rescue a couple of years ago with an option to force Ambient Occlusion on various games by enabling the corresponding option in their drivers Control Panel.

Initially you could only choose from “Off” and “On”, but from the 25x.xx drivers and on you have three options to choose from, “Off”, “Performance” which balances the effect’s application to enhance your image while keeping the performance numbers relatively close to what you had without A.O. enabled, and “Quality”, this option sacrifices performance, often at a massive rate, but gives you the best image quality you can achieve with A.O.

As a result of extensive testing of all 3 settings of Ambient Occlusion in a couple of games, this is our result:

Ambient occlusion is related to accessibility shading, which determines appearance based on how easy it is for a surface to be touched by various elements (e.g., dirt, light, etc.). It has been popularized in production animation due to its relative simplicity and efficiency. In the industry, ambient occlusion is often referred to as “sky light”.[citation needed]

The Terrain Ambient Occlusion system controls the amount of ambient light in a scene. For example, a dense forest has less ambient light near the ground because most of the light is stopped by the trees. In the current implementation, occlusion information is stored in textures and the effect is applied to the scene in a deferred way.

The images below show the difference (in a scene) when Terrain Ambient Occlusion is enabled and when it is not.


The ambient occlusion shading model has the nice property of offering better perception of the 3d shape of the displayed objects. This was shown in a paper where the authors report the results of perceptual experiments showing that depth discrimination under diffuse uniform sky lighting is superior to that predicted by a direct lighting model.

High 32 is highest smooth frame rate (steady 60fps) that I’ve found while testing with a MSI GTX 680 Lightning.


What are we looking at here? Alright, the best example is the vase held up to the candle. Notice the blurry yet real time shadow effect which is cast behind the vase? There you go, that’s SSAO in Amnesia. The thing is SSAO is entirely dependent on angle: if you were to stand behind the vase the shadow wouldn’t show up yet the vase would have a black glow to it. The bookcase, the fireplace and the dresser show other examples of SSAO effects you’ll see throughout the game. SSAO maxed out on High/128 killed my framerate down to 14 FPS and there was little difference compared to the much more playable setting at Medium/64. Overall, the game looks better with some form of SSAO enabled. In some areas it made things look engulfed in some ugly blurry black aura. Still, a good feature to have in a game that uses shadows for its overall atmosphere and I appreciate the effect SSAO tries to achieve yet I think it does a pretty sloppy job at emulating ‘darkness’. Setting this setting maxed out isn’t a good idea either, you’ll actually get less “black glowing” if it’s set to around 16/32. Now if only they had some form of Anti-Aliasing to play with.

The occlusion at a point on a surface with normal can be computed by integrating the visibility function over the hemisphere with respect to projected solid angle as shown below:


where  is the visibility function at , defined to be zero if  is occluded in the direction  and one otherwise, and  is the infinitesimal solid angle step of the integration variable . A variety of techniques are used to approximate this integral in practice: perhaps the most straightforward way is to use the Monte Carlo method by casting rays from the point  and testing for intersection with other scene geometry (i.e., ray casting). Another approach (more suited to hardware acceleration) is to render the view from  by rasterizing black geometry against a white background and taking the (cosine-weighted) average of rasterized fragments. This approach is an example of a “gathering” or “inside-out” approach, whereas other algorithms (such as depth-map ambient occlusion) employ “scattering” or “outside-in” techniques.

Along with the ambient occlusion value, a bent normal vector is often generated, which points in the average direction of samples that aren’t occluded. The bent normal can be used to look up incident radiance from an environment map to approximate image-based lighting. However, there are some situations in which the direction of the bent normal doesn’t represent the dominant direction of illumination.


So that’s SSAO in a nutshell, it was quite difficult to understand let alone implement due to the amount of calculations, as well as the fact that is puts heavy burdens on your processor. But like since the beginning, games sought to be as realistic as possible in order to uphold its role as a medium that immerses players into experience. Screen Space Ambient Occlusion is another means of doing to simulate the nature of lights and shadows.