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.
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.