MULTIMEDIA

Programming with DirectX : Overview of Lighting - Pros and Cons of Per-Vertex Lighting, Per-Pixel Lighting

1/21/2014 12:53:15 AM
Lighting in computer graphics involves algorithms that for shading surfaces in a scene to lighten or darken the colors that are rendered based on some set of attributes. Lighting in video game graphics is usually evaluated on a per-vertex or per-pixel level. In the following section we will discuss these two methods in more detail as they relate to lighting.

Pros and Cons of Per-Vertex Lighting

Per-vertex lighting essentially means executing a lighting algorithm on each vertex of a piece of geometry. The resulting colors are usually interpolated across the surface during shading. An example of per-vertex lighting is shown in Figure 1.

Figure 1. An example of an object lit by per-vertex light.


Per-vertex lighting has some good and some bad qualities. From a programming point of view, the complexity of using an algorithm per vertex rather than per pixel is not increased or decreased, thanks mostly to the current nature of shading technology and languages. If anything, per-vertex lighting could be faster than per-pixel lighting if the algorithm executes fewer times in a frame, because fewer vertices are being processed than pixels in per-pixel lighting, not to mention other issues such as fill rate that can affect performance. The downside to using per-vertex lighting includes some of the following.

  • Depending on the object’s topology, the quality of per-vertex lighting can be less than that of per-pixel lighting.

  • Increasing lighting quality using a per-vertex approach usually requires an increase in polygon count, which can lead to performance side effects such as the need for increased and polished results.

  • Per-pixel lighting has various extensions that allow for the simulation of lots of detail without the actual detail being present, while retaining a positive performance and frame rate.

Since the lighting algorithm is evaluated on the per-vertex level, the quality of the rendered surfaces depends on the polygon count of objects. Therefore, theoretically, the closer a polygon is to the size of a pixel, the better the results will be. Making many small polygons to get small details and quality is not often acceptable in video games, however. Increasing the polygon count introduces a host of issues such as increasing geometry bandwidth, increasing the possibility of over-draw many times (i.e., drawing lots of polygons on top of each other unnecessarily), and the dramatic increase of extra data, which can create all types of problems with the application’s performance.

On today’s hardware, simulating detail using a pixel approach is more efficient than using a vertex approach. A case in point can be seen with the normal mapping technique used to simulate high-polygon geometry using low polygon numbers. This is being done in many games such as Gears of War 2.


Take, for example, a wall defined by four vertices. If this wall’s surface takes up a large portion of the rendering canvas, the lack of lighting evaluations will cause the surface to have an unrealistic look, especially when the lights and cameras change orientation in relation to one another. In other words, the change in color for one or two vertices can cause a color shift across large portions of the surface that can occur faster than what looks believable. If the color of one vertex of this wall changes, a huge portion of the wall’s color will instantly change awkwardly.

With more lighting evaluations, the lighting simulation can appear more consistent and accurate (relatively speaking). And since we cannot render anything less than a pixel, what else can be better to use to evaluate lighting than to do it on the per-pixel level?

Per-vertex light is lighting that is performed in a vertex shader or manually on the vertices of objects.


Per-Pixel Lighting

Real-time per-pixel lighting is commonly performed within the pixel shader. By executing the lighting algorithm on the pixel level, the polygon count in terms of lighting quality becomes irrelevant. Of course, polygon count still matters in terms of the curvature and symmetry of the geometry. An example of an object lit by per-pixel lighting is shown in Figure 2.

Figure 2. An example of per-vertex (left) and per-pixel (right) light.

Other  
  •  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
  •  Adobe Photoshop CS5 : Managing Color from Monitor to Print - Producing Consistent Color
  •  Adobe Flash Professional CS5 : Creating Frame-by-Frame Animation - Editing Keyframes
  •  
    Top 10
    Review : Sigma 24mm f/1.4 DG HSM Art
    Review : Canon EF11-24mm f/4L USM
    Review : Creative Sound Blaster Roar 2
    Review : Philips Fidelio M2L
    Review : Alienware 17 - Dell's Alienware laptops
    Review Smartwatch : Wellograph
    Review : Xiaomi Redmi 2
    Extending LINQ to Objects : Writing a Single Element Operator (part 2) - Building the RandomElement Operator
    Extending LINQ to Objects : Writing a Single Element Operator (part 1) - Building Our Own Last Operator
    3 Tips for Maintaining Your Cell Phone Battery (part 2) - Discharge Smart, Use Smart
    REVIEW
    - First look: Apple Watch

    - 3 Tips for Maintaining Your Cell Phone Battery (part 1)

    - 3 Tips for Maintaining Your Cell Phone Battery (part 2)
    VIDEO TUTORIAL
    - 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