Game Development Reference
In-Depth Information
Understanding shading/interpolation
models
We discussed earlier that information about the surface of a model, such as the
positions of points on the surface and the normal vectors at those points, are
stored only for each vertex of a triangle mesh. When a single triangle is rendered,
information known at each vertex is interpolated across the face of the triangle.
Sometimes we calculate the diffuse and specular illumination only at the vertices
of a mesh, and at other times we apply the entire illumination formula at every
individual pixel drawn in the display. A shading model defines whether we will
apply the illumination model only for the vertex or apply the illumination model for
every pixel of the face. If calculated at the vertex level, then the values of the pixels
between vertices are linearly interpolated. Remember that if we want to apply the
illumination model per vertex, then we will have to compute it in the vertex shader.
The vertex shader is executed for each vertex. Hence, it is computationally expensive.
Therefore, we would prefer to apply it per pixel in the fragment shader.
The three most common shading models are as follows:
Flat shading
Gouraud shading
Phong shading
Flat shading
Flat shading shades each polygon of an object based on the angle between the face
surface normal and the direction of the light source, its respective colors, and the
intensity of the light source. It is usually used for high-speed rendering where more
advanced shading techniques are too computationally expensive.
Flat shading gives low-polygon models a faceted look. We do not use flat shading for
gaming applications.
Gouraud shading
In this shading algorithm, we calculate the surface normal of each vertex in a
polygonal 3D model or average the surface normals of the polygons that meet
at each vertex. We apply lighting computations based on a reflection model, for
example, the Blinn-Phong reflection model, and then they are performed to produce
color intensities at the vertices. For each screen pixel that is covered by the polygonal
mesh, color intensities can then be interpolated from the color values calculated at
the vertices.
 
Search WWH ::




Custom Search