Thursday, 24 January 2013

Lighting and Luna

As a UOIT Game Development and Entrepreneurship student it is a requirement to develop a game every year a team of other students. Over the years, Noble Studios, has developed games several and they have evolved from simple text-based, to 3D games. However, this year marks the first time we will implement shaders into the game to enhance the experience. In this post, I will discuss the possibilities of improving our current game through the use of lighting.

Noble Studios is developing a 2.5 game called Luna. As taken directly from our development webpage, "Play as a magical moon girl who journeys to the Earth searching for a little boy in hopes of finally finding friendship...but all is not right, as someone plots to make sure you will never return home." Currently Luna is a prototype and it features no shaders, only textures and no good lighting. See the example image below.


Our main character Luna with minimal lights.
In the image to the left, there are few shadows, character detail, or any sort of interesting lighting detail. This is because the lights are not properly set up to provide any higher level of detail. Currently, the scene looks very plain. We intend to increase the quality of our visuals by introducing vertex shaders to compute our lighting. We will be using various types of lighting including ambient, diffuse, and specular. By using these types of lighting, I will explain how we will improve our game.

Ambient

An ambient light is a non-directional light that determines the amount of lighting in a scene. In Luna, the game changes from broad daylight to night over the course of the levels. Knowing how our game progresses, we can alter the ambient light in order to achieve certain levels of light or dark between the stages.
In code, we can achieve this with a simple formula
Ambient = K * AmbientIllumination where k is a float value between 0 and 1.

Diffuse

Diffuse lighting is a method to apply shading to an object. While the ambient light applies lighting to an entire scene, a diffuse light will ensure a proper shade of that object. The image below demonstrates this.

We can use diffuse by remembering Lambert's Laws:
  • The illuminance on a surface illuminated by a light falling on it perpendicularly from a point source is proportional to the inverse square of the distance between the surface and the source.
  • If the rays meet on a surface at an angle, then the illuminance is proportional to the cosine of the angle with the normal.
  • The luminous intensity of light decreases exponentially with the distance it travels through an asorbing medium
Using the following code, we can compute diffuse lighting


// Compute the diffuse term
  float3 L = normalize(lightPosition - P);
  float diffuseLight = max(dot(N, L), 0);
  float3 diffuse = Kd * lightColor * diffuseLight;

In our game, we can use this to apply realistic environment and character shading. Players will be able to determine the curvature of objects and the intensity of the lights. This is important because it adds a sense of realism to the characters, and it simply makes things more defined.

Specular lighting (also known as specular highlights)

Specular lighting is the bright spot of light that appears on shiny objects such as metal or water when illuminated. This is important in 3D graphics because it suggests the shape of an object and its position according to the light sources of the scene.

The image below is a good example of specular, diffuse, and ambient lighting. The brightest section of the water is the specular highlight. Along the edges of the highlights the light begins to diffuse. At the far right, it becomes darker because less light is reflecting off that surface. The ambient light is the sun, that provides light to the entire scene.
In our game, we can use specular highlights to show the brightest part of an object. This is useful because we can define an object not only will diffuse lighting, but add additional realism with specular highlights.
Using the following code, we can create a specular light


// Compute the specular term
  float3 V = normalize(eyePosition - P);
  float3 H = normalize(L + V);
  float specularLight = pow(max(dot(N, H), 0), shininess);


In conclusion

By using these three different types of lighting, we'll be able to achieve character and environment lighting that suits our games and its needs. In later posts, I will be describing more ways we will be able to improve our current prototype!

No comments:

Post a Comment