i2350 Blog Two – Lighting

Lights,

Today in class we reviewed the topic of light as well as explored shader and how they are implemented with lighting. We discussed the importance of light and how it can greatly affect the feel of the scene. We talked about how different colour can be used to direct the player’s attention and also change the player’s behavior. The absence and presence of light really helps emerge the player as well.

Programming light seems like a really daunting task, but once I understood how the math would work out it wasn’t too complicated. Lighting in games is either static or dynamic. Static is when the light source is fixed into its location in the scene such as ceiling lights or lamp. Calculating static light in real time is going to be a waste of computation so it’s common to bake the lighting right into the texture with Maya. Dynamic lighting is a light source that is moving in the scene, some examples of dynamic lights in games are things like gun fire or flash lights.

In this course were using the phong reflection model to simulate light. Phong’s model is a close enough approximation to reality of light material interactions through physical models. There are 3 parts to the Phong lighting model, the three of which are combined to create the final image.

Ambient – is the base light in the whole scene. lowest level of brightness in the scene.

Diffuse – light rays are reflected in many directions after making contact with the surface.

Specular – the highlight of the area that is reflecting into the viewer.

File:Phong components version 4.png

(http://en.wikipedia.org/wiki/File:Phong_components_version_4.png)

we also talked about Emissive light which is light that emitting from the object surface itself such as a cellphone, electronic devices, and even fire.

(http://www.sketchupartists.org/tutorials/sketchup-and-v-ray/lighting-with-v-ray-for-sketchup-definitive-guide-part-2/)

Phongs model relies on 4 pieces of information to calculate these light interactions. At an Arbitrary Point P, there is a light normal, a directional from p to the viewers eye, light source, and a perfectly reflected ray.

N: normal at P,                                                                                                                                                                                                                                                                                                                     V: direction from p to viewer or camera                                                                                                                                                                                                                                                               I: direction from p to light source                                                                                                                                                                                                                                                                             R: perfectly reflected ray.

The Phong Lighting Model

(http://www.unc.edu/~zimmons/cs236/BRDFmap.html)

Ambient light- is directly proportional to the angle between the light source ray and the surface normal.  When N and L are aligned, the reflection is at its peak. when N and L are perpendicular, no diffuse light is reflected.  We calculate the dot product between N and L which gives us a value between 0 and 1.  we take this normalized value and multiply it by a intensity value to give us the final value or diffuse light. 

Diffuse Light = Diffuse Intensity * N · L

Specular light – simulates the glossiness of an object when reflecting light into the viewer. The formula for specular light requires the dot product between the perfectly reflected ray R and the viewer V. The closer this angle is between R and V the higher the value is between 0 and 1.  Like the diffuse formula there is also a intensity factor which lets the programmer control its contribution in the final color.

Specular light =  Ks * (R · V)^n

Ambient light – Ambient light does not require any big calculations, ambient light as a  component of the final image is just designer preference. Basically you can just code in a vec3 and incorporate a ambient constant as well.

Ambient Light = K * vec3(0.1,0.1,0.1);

Finally with all our interactions calculated we simply summat them together to return a final value. Below is a code snip of how all there light interactions are found and combined.

http://gyazo.com/40c81c6ec19e92b641afbcfa249faee8 (click this link).

(http://ogldev.atspace.co.uk/www/tutorial19/tutorial19.html).

My understanding of shaders and how they are used with lighting is not clear enough for me to articulate. From what i understand so far, all of these calculations should be done on the hardware and they need to be fast. We can calculate lighting in many ways such as per surface, per vertex or per pixel. With per pixel shaders, we need to send in all the appropriate data for each pixel and have it updated per frame.

Again, like i said at the moment i’m not confident in explaining my understanding of shaders. Ill have to post another blog later on when i am.

-Prudhvi

Leave a comment