Programming with DirectX : Basic Lighting Information - Diffuse Light , Specular Light , Blinn-Phong Specular Model

1/21/2014 12:55:25 AM

A lighting algorithm is the specific mathematical operation performed on a surface to shade it to produce the desired lighting effect. Lighting algorithms can be used to represent the different values of the lighting equation. Commonly this includes, but is not limited to, the following lighting values.

  • Ambient

  • Diffuse

  • Specular

Ambient Light

The ambient value of the lighting equation is used for various purposes. In simple lighting algorithms, it is often used to add a fill color to lighten the scene. This fill color is a way to simulate basic area light by using nothing more than a single color value. This does not lead to realistic lighting conditions and is just a value used to brighten the scene.

On the other hand, the ambient value can be used as the occluding factor. This means the ambient value is used to store a percentage of how many surfaces in the scene can possibly block light rays from reaching the surface. This technique is known as ambient occlusion.

In ambient occlusion you essentially trace many rays from the surface being evaluated into the scene. The percentage of those rays that hit some surface in the scene is recorded and used as the ambient occlusion value. This value is multiplied by the other lighting terms to create shadows in the scene. These shadows appear soft when many rays going in many different directions from the surface are used. This is because some points on a surface might be lit differently than others, creating a smooth gradient of gray values across the surface.

Regardless of whether the algorithm used involves nothing more than adding a static color value to the scene or is as complicated as ambient occlusion, the ambient value itself is generally used to simulate light coming to the surface from the environment. Global illumination algorithms go a step further to account for light bouncing off of a surface and evaluate the resulting color bleed onto the surface. An example of this is to take a bright blue ball and place it on a plain sheet of paper. If you place a bright light on top of the ball so that the light is shinning down on it, the white piece of paper should have some tints of blue on it because the blue reflecting off of the ball is reaching the paper. This color bleeding effect is common in global illumination.

Diffuse Light

The diffuse lighting value is light that has reached a surface and has reflected off of it evenly, or at least it seems even. When light hits a surface, it is scattered back into the scene. The smoother the surface is, the more light reflects in the direction from which it came. Surfaces such as mirrors are extremely smooth, and lights reflect back so that a mirror image appears on the surface. For surfaces that are not as smooth, light often hits microscopic grooves along the surface that cause the light to scatter in different directions. Since so much light is hitting such a surface from so many different angles, diffusely lit surfaces look as if light is being evenly reflected in all directions.

Specular Light

Specular light is light that hits a smooth surface and reflects sharply in specific directions. With diffuse light, the millions of light rays in nature strike the surface and scatter in so many different directions that objects look evenly lit regardless of the viewing angle as far as light reflection is concerned.

With specular light the sharp reflection of light, instead of the scattering reflection, in many angles is what creates a highlight on the surface. Mirrors are so smooth that the light can create clear reflections on them. For objects that are smooth enough to reflect light more sharply than others, highlights appear that can be seen from certain orientations. Since light reflects more sharply in some directions than others, the appearance of the highlight can change depending on your viewing angle. This differs from diffuse light, because a diffusely lit object looks the same regardless of the viewing angle (aside from shadows, but we’ll assume shadows are not present), but an object reflecting specular highlights looks different as the object’s orientation or the viewing orientation changes. This is similar to rotating a plastic soda bottle while standing in sunlight. The highlights from the light hitting the object shimmer and change as the orientation changes since the reflection isn’t evenly dispersed in all directions.

Lambert Diffuse Model

The Lambertian reflection model is used to simulate light rays striking a surface and reflecting back into the scene, where the brightness of a point on that surface looks the same regardless of where the observer is located. In other words, Lambertian reflection is ideal for diffuse light, where the nature of diffuse light is to illuminate a surface so that it looks the same around all angles.

The Lambert equation for diffuse light is fairly straightforward and very popular. To calculate the diffuse contribution, you need the light vector and the surface normal. With these two pieces of information you can calculate the dot product between them, and the resulting floating-point value is what you use as the diffuse contribution. This is commonly referred to as N dot L, where N is the normal and L is the light vector. You take this dot product value and multiply it by the surface color, material color (e.g., textures etc.), and so forth.

Blinn-Phong Specular Model

The Blinn-Phong reflection model is used to perform real-time lighting in computer graphics. The Blinn-Phong reflection model is actually a modification of the Phong reflection model. A reflection model can be thought of as an algorithm that is used to describe how light reflects off of objects.

The Blinn-Phong reflection model is used to create the specular contribution of the lighting equation. The steps to create the specular contribution using the Blinn-Phong model are as follows.

Retrieve the normal vector.

Compute the light vector as the light’s position minus the vertex position and normalize it.

Compute the view vector as the light’s position minus the camera’s position and normalize it.

Compute the half vector that is necessary for the Blinn-Phong algorithm as the light vector plus the view vector.

The specular value is the dot product of the normal and the half vector raised to a specific power (this power is known as the specular power and is used for shininess).

To use the Blinn-Phong reflection model, the first pieces of data necessary are the normal, the view vector, and the light vector. The normal is the surface normal. The view vector is the vector that describes the direction from the camera’s position to the point being shaded, which allows the specular contribution to be view-based. The last vector, the light vector, is a vector from the light’s position to the point being shaded. If these vectors are calculated in the vertex shader and sent to the pixel shader, the results can be interpolated to point not from the original vertex position but from the pixel’s point being shaded. You could also calculate them in the pixel shader, but the interpolated values from the vertex shader work just as well.

Once you have these vectors, you calculate a new vector called the half vector. This vector is used instead of finding the reflection vector as is done in the Phong reflection model. It is faster to calculate than the method used in the Phong reflection model. Like the diffuse contribution that is calculated using N dot L, the specular value is found using N dot H, where N is the normal and H is the half vector. Raising this value by a power, known as the specular power, allows us to control the amount of shine an object has.


Material is a term used to describe the representation of a surface. For example, a brick wall in a video game might have as part of the “brick” material a texture image of bricks, a normal map used for bump mapping to increase the detail of the bricks, a diffuse modifier, and anything else the artist creates to make the wall look like a brick wall.

These days a material is a collection of pieces of data used to create the look of a surface. In the early days of 3D graphics, most games used textures as the main or sole source of the material. Materials can include, but are not limited to, the following.

  • Decal color texture map

  • Normal map

  • Alpha map

  • Diffuse color

  • Specular color

  • Emissive color

  • Ambient color

  • Vertex shader

  • Pixel shader

  • Geometry shader

In today’s games, materials are complex assets, and some game engines have their own material systems built into the rendering system. With the amount of content that goes into games, materials will most likely continue to grow in complexity as the amount of data necessary to represent certain surfaces increases.

  •  Programming with DirectX : Light Types - Directional Lights,Point Lights,Spot Lights, Area Lights
  •  Programming with DirectX : Overview of Lighting - Pros and Cons of Per-Vertex Lighting, Per-Pixel Lighting
  •  What Will 2014 Bring To Tech Lovers?
  •  DirectX 10 Game Programming : Direct3D - Textures and Details (part 3) - Drawing the Textured Object
  •  DirectX 10 Game Programming : Direct3D - Textures and Details (part 1) - Adding Support for Texture Mapping - Texturing Coordinates and Sampling
  •  DirectX 10 Game Programming : Direct3D - Textures and Details (part 1) - Adding Support for Texture Mapping - The Vertex Format
  •  DirectX 10 Game Programming : Shaders and Effects - Geometry Shaders
  •  Adobe Photoshop CS5 : Managing Color from Monitor to Print - Working with Rendering Intents
  •  Adobe Photoshop CS5 : Managing Color from Monitor to Print - Changing from Additive (RGB) to Subtractive (CMYK) Color
  •  Adobe Photoshop CS5 : Managing Color from Monitor to Print - Setting Up Soft-Proof Colors
    Most View
    Spring Is Here (Part 2)
    Is 802.11ac Worth Adopting?
    BlackBerry Z10 - A Touchscreen-Based Smartphone (Part 1)
    LG Intuition Review - Skirts The Line Between Smartphone And Tablet (Part 5)
    Fujifilm X-E1 - A Retro Camera That Inspires (Part 4)
    My SQL : Replication for High Availability - Procedures (part 6) - Slave Promotion - A revised method for promoting a slave
    10 Contenders For The 'Ultimate Protector' Crown (Part 3) : Eset Smart Security 6, Kaspersky Internet Security 2013, Zonealarm Internet Security 2013
    HTC Desire C - Does It Have Anything Good?
    Windows Phone 7 : Understanding Matrix Transformations (part 2) - Applying Multiple Transformations
    How To Lock Windows By Image Password
    - First look: Apple Watch

    - 10 Amazing Tools You Should Be Using with Dropbox
    - How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 1)

    - How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 2)

    - How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 3)
    Popular Tags
    Microsoft Access Microsoft Excel Microsoft OneNote Microsoft PowerPoint Microsoft Project Microsoft Visio Microsoft Word Active Directory Biztalk Exchange Server Microsoft LynC Server Microsoft Dynamic Sharepoint Sql Server Windows Server 2008 Windows Server 2012 Windows 7 Windows 8 Adobe Indesign Adobe Flash Professional Dreamweaver Adobe Illustrator Adobe After Effects Adobe Photoshop Adobe Fireworks Adobe Flash Catalyst Corel Painter X CorelDRAW X5 CorelDraw 10 QuarkXPress 8 windows Phone 7 windows Phone 8 BlackBerry Android Ipad Iphone iOS
    Top 10
    OPEL MERIVA : Making a grand entrance
    FORD MONDEO 2.0 ECOBOOST : Modern Mondeo
    BMW 650i COUPE : Sexy retooling of BMW's 6-series
    BMW 120d; M135i - Finely tuned
    PHP Tutorials : Storing Images in MySQL with PHP (part 2) - Creating the HTML, Inserting the Image into MySQL
    PHP Tutorials : Storing Images in MySQL with PHP (part 1) - Why store binary files in MySQL using PHP?
    Java Tutorials : Nested For Loop (part 2) - Program to create a Two-Dimensional Array
    Java Tutorials : Nested For Loop (part 1)
    C# Tutorial: Reading and Writing XML Files (part 2) - Reading XML Files
    C# Tutorial: Reading and Writing XML Files (part 1) - Writing XML Files