3D CG (continued)

Rendering — rendering algorithms

Rendering is the process to generate a realistic image based on model data (shape, attributes). The following rendering algorithms exists, but 3D software often uses z-buffering, scanline method, and ray tracing.

Painter's algorithm

This is a simple method of removing hidden surfaces by painting polygons in order from the far side to the near side. Sometimes used for rendering in CAD software. Shadows and transparent objects cannot be handled. Anti-aliasing is not possible.


A simple method of painting each polygon one by one. The z value (depth) of each pixel of the painted polygon is stored in a buffer (temporary memory), and when another polygon comes to the same pixel, the z values are compared and the pixel is repainted only if the new point it is nearer. Because this method is simple and fast, it is often used for CAD and game rendering. Many graphic chips also support the z-buffer method at the hardware level. Though z-buffer method is simple, it has disadvantages such as inability to represent translucent objects.
* Shadows can be simulated by using a method called shadow mapping (or shadow buffering).
* Anti-aliasing is possible if oversampling technique is used.

Scanline method

For each scanline on the screen, polygons that lie on the scanline are detected, and the distance of each point on the scanline from the viewpoint is calculated to determine the pixel color. This method is widely used because it is relatively fast. Anti-aliasing is possible. A translucent object can be rendered with this method. Refraction cannot be described.
* Shadows can be simulated by using shadow mapping.

Ray tracing

A method of generating an image by emitting rays from the viewpoint toward each pixel on the screen, and by tracing the rays back to a light source while simulating physical phenomena, such as refraction and reflection. Since shadows, refractions, reflections, and other effects can be expressed, photorealistic images can be obtained. Effects of a spread light source and depth of field can also be represented. Anti-aliasing is performed by averaging the colors of many points in one pixel (oversampling). The disadvantage of ray tracing is that it takes a long time to calculate, but it is not much of a problem because of the improvement in processing speed.

ray tracing 1   ray tracing 2
Examples of ray tracing

Rendering — shading models and attributes

To render and create an image, we must specify attributes for shading as well as color.

1. Shading or reflection model

Adding light and shade to an object according to the orientation of the surface is called shading. The shading attribute is often specified by the following three components, because it can provide a realistic expression despite of simply. This shading model is called the Phong reflection model (Phong is from Vietnam).

(1) Ambient component
Brightness due to the indirect light from the surrounding objects. This component alone determines the brightness of the shaded area where no direct light from the light source comes. It is usually around a few percent depending on the environment where the object is placed.

(2) Diffuse component
The brightness of the surface due to the diffused reflection of the direct light. The brightness changes according to the angle with the light beam. Usually, for simplicity, it is assumed that the incident light is reflected in all directions, and the brightness of the surface is proportional to the cosine of the incident angle (Lambert's law, Lambertian). Adjust this brightness according to the material.

(3) Specular light
Intensity of reflected light (so-called highlight) when the surface is glossy. The size can also be changed. Metals and non-metals have different light reflection mechanisms, so colors of the specular lights are different. Each metal has its peculiar color, e.g. gold is yellowish. On the other hand, for nonmetals, the color of specular light is the same as that of the light source. The calculation of the specular intensity distribution uses the Phong formula and the improved Blinn formula, but the GGX formula is getting popular after 2010s.

reflection model

The combination of these three components can express a wide variety of materials, for example:

• For plastic, make specular weak and dull.
• For glass, weaken ambient and diffuse, and sharpen specular.
• For shiny metal, weaken ambient and diffuse, and strengthen specular. The color of the specular should be the color of the metal.

[Note. Flat shading and smooth shading]

When shading a model consisting of polygons, flat shading refers to determining the brightness of the surface according to the orientation of each polygon, and smooth shading refers to shading the surface so that it appears smooth.

flat Phong
Flat shading Smooth shading

in the Gouraud shading method (Gouraud is from France), interpolation of the color of each polygon is used to make the surface look smoother. On the other hand, in the Phong shading, interpolation of the normal vector is used to make the surface look smooth, and it gives better results. The Gouraud shading is seldom used because it cannot express specular correctly.

2. Texture

As well as shading an object with a single color, a technique to attach various types of maps on the surface of an object is widely used. Texture mapping pastes a texture or a pattern onto the surface. Reflection mapping (or environment mapping ) places the scenery around the object to make the surface look like a reflection. Bump mapping adds information on irregularities of the surface (or irregularities in the direction of normal vector) to makes it look like real irregularities. Though it is not a mapping, a solid texture that gives a pattern as a function of 3D space can be used to shows a pattern such as wood or marble on the cut surface.

texture mapping reflection mapping bump mapping
Texture mapping
Reflection mapping
(environment mapping)
Bump mapping (rough skin)

bump mapping solid texture solid texture
Bump mapping (wave) Solid texture Solid texture

3. Global illumination model

In classical ray tracing, rendering is performed using the above three components (ambient, diffuse, specular), with refraction and reflection taken into account. This simple illumination model is called a local illumination model. On the other hand, a lighting model that comprehensively calculates the light path including the indirect lighting by diffuse reflection (called radiosity), instead of artificially giving ambient light, is called global illumination model (see figure). In addition to radiosity, advanced ray tracing software can simulate the effects of fog and haze, bunching of refracted rays (called caustics), depth of field (defocus), and so on. Although it might take time for computation, high-quality expressions are possible nowadays even with a personal computer.

Local illumination Global illumination
Ray tracing with a
local illumination model
Ray tracing with a
global illumination model