• Aucun résultat trouvé

Blinn-Phong Illumination

Dans le document Real-Time Volume Graphics (Page 132-138)

Local vs. Global Volume Illumination

5.4 Local Illumination Models

5.4.1 Blinn-Phong Illumination

The local illumination model most frequently used in computer graphics is the Blinn-Phong model. Although it does not fulfill the physical require-ments of energy conservation or Helmholtz reciprocity, it is definitely the most popular phenomenological illumination model in practice.1

1There is also a less popular version of the original Phong model, called themodified Phong model, which is physically plausible. See [202] for details.

5.4 Local Illumination Models 115 Like many popular illumination models, the Blinn-Phong model com-putes the light reflected by an object as a combination of three different terms, anambient, adiffuse, and aspecularterm:

IPhong = Iambient + Idiffuse + Ispecular. (5.17) Note that illumination terms are denoted as RGB triplets. The frequency dependency of the illumination equations are omitted by considering color components separately. The product between two RGB triplets, such as the multiplication of an illumination term by a material color, is always performed component-wise.

Theambient term Iambient is modeled as a constant global light mul-tiplied by the ambient color and the ambient coefficient of the material:

Iambient = ka MaIa. (5.18)

The color and intensity of the global ambient light is specified by theRGB triplet Ia. It is multiplied component-wise by the ambient material color Ma. The scalar ambient coefficientka is a constant between 0 and 1 that controls how much of the ambient light that arrives at the surface is actually reflected by it. Often the ambient coefficient ka and the ambient material color Ma are combined into a single RGB triplet. Ambient light is the easiest way to compensate for missing indirect illumination and to lighten up shadow regions. In the real world, such illumination effects are caused by light that arrives indirectly at the surface via multiple scattering.

Without ambient lighting, every surface not directly facing a light source would be completely black, which is often found unrealistic. Am-bient light will alleviate this by adding constant light. The amAm-bient term, however, has only been introduced for practical reasons. It does not have any physically based justification. It is important to understand that am-bient light will always reduce the contrast and the dynamic range of the

Figure 5.3. Different types of reflections. Left: Lambertiansurfaces reflect light equally in all directions. Middle:perfect mirrorsreflect incident light in exactly one direction. Right: shiny surfaces reflect light in aspecular lobearound the direction of perfect reflection (specular reflection).

i

image. For good reasons, many artists prefer setting the ambient light to zero and using additional light sources calledfill lightsto lighten up dark regions.

The diffuse and specular parts of the Blinn-Phong model are illus-trated in Figure 5.3. The diffuse term (Figure 5.3 (left)) models the view-independent part of reflected light. A perfect mirror (Figure 5.3(middle)) reflects incident light in exactly one direction. The specular term (Fig-ure 5.3 (right)) is a generalization of a mirror, where light is scattered around the direction of perfect reflection. The shape of the specular term in Figure 5.3 is calledspecular lobeand depends on the material coefficients.

The diffuse term Idiffuse corresponds to Lambertian reflection, which means that light is reflected equally in all directions. Diffuse reflection is exhibited by a dull, matte surface. Its brightness is independent of the viewing angle and depends only on the angle of incidence ϕ between the direction l of the incoming light and the surface normal n (see Fig-ure 5.4 (left)). All vectors used in local illumination computations are assumed to have unit length, so that the cosine of the angle between two vectors can be computed by the dot product. Diffuse illumination term can be written as:

Idiffuse = kdMdIdcosϕ ifϕ≤π

2 (5.19)

= kdMdIdmax((r·v),0). (5.20) The diffuse material colorMdis multiplied component-wise by the colorId

emitted by the light source. The scalar diffuse coefficientkd is a constant between 0 and 1 that specifies the amount of diffuse reflection of the mate-rial. Again, the diffuse coefficientkdand the diffuse material colorMdcan

n

Figure 5.4.Left: the diffuse illumination term depends on the angle of incidenceϕ between the normalnand the light directionl. Middle: in the original Phong model, the specular term is based on the angleρbetween the reflected light vectorrand the viewing directionv. Right: the specular term depends on the angle between the normal and a vectorh, which is halfway between the viewing and the light direction.

5.4 Local Illumination Models 117 be combined into a single RGB triplet. In order to avoid surfaces being lit from behind,Idiffuseshould be zero when the angleϕbecomes larger than π/2, which is ensured by the maximum operator. In order to simplify the notation, we are going to omit these maximum operators in the following equations.

The specular lighting term Ispecular models the reflection behavior of shiny surfaces, which cause so-called specular highlights. It depends on the viewing vector v, which points from the surface point to be shaded to the eye position. The specular term of the original Phong model (see Figure 5.4 (middle)) uses the direction of perfect reflection r, which is calculated by mirroring the light vectorlabout the surface normal n. The amount of specular reflection is determined by the cosine of the angle ρ betweenrand the viewing vectorv,

cosρ = (r·v), with (5.21)

r = 2 (l·n)n l, (5.22)

resulting in a specular term according to

Ispecular = ksMsIscosnρ , if ρ≤π

2 (5.23)

= ksMsIs(r·v)n. (5.24) In the Blinn-Phong model, the specular term is computed more efficiently by introducing the vectorh, which is halfway betweenv andl,

Ispecular ksMsIs(h·n)n, with (5.25) h = v+l

v+l. (5.26)

The dot product (h·n) is also clamped to a positive range to account for an-glesρ≤ π2 only. The specular material colorMsis multiplied component-wise by the radiance Is of the light source. The scalar specular coefficient ksdetermines the amount of specular reflection of the material. The spec-ular exponentnis called theshininessof the surface and is used to control the width of the specular lobe and thus the size of the resulting highlights.

Both the original Phong model and Blinn-Phong model are phenomeno-logicalillumination models. This means that they might produce believable illumination effects, although certain aspects are not physically plausible.

The degree of realism greatly depends on the choice of the material coeffi-cients. The law of energy conservation requires that the amount of reflected light never exceeds the incident radiant energy. As a rule of thumb, the sum of the scalar coefficientska,kd, andksshould not exceed 1 in practice and the ambient coefficientka should be as small as possible. Straightfor-ward implementations of the Blinn-Phong model for per-fragment surface

i

shading with different types of light sources can be found inThe Cg Tuto-rial [71].

In order to use a local illumination model in volume graphics, we uti-lize the fact that light is additive. In fact, we can render a scene several times, each time with a different light source and add up all the resulting images afterwards to obtain a final image that will correctly contain the contribution of all the light sources. For incorporating local illumination into the emission-absorption model, we can simply add the scattered light to the volume emission termIemission at each sample.

Ivolume = Iemission+IBlinnPhong (5.27)

= Iemission+Iambient+Idiffuse+Ispecular

= keIe+kaMaIa+kdMdIdln+ksMsIshnn. The maximum operators are again omitted in the equation. For volume illumination in practice, there are different possibilities for specifying the material coefficients. The scalar coefficients ke, ka, kd, and ks are usually specified as global constants. Note that in order to avoid clamping of illumination values when their sum exceeds 1, floating-point render targets and high dynamic range rendering must be used. In this case, ke can be allowed to be arbitrarily big, e.g., ke > 1. Section 5.8 contains more information on high dynamic range volume rendering.

The emitted radianceIeis defined as a function of the underlying scalar field s(x). It is specified by a transfer function,

Ie(x) =TIe(s(x)). (5.28) The material colorsMa,Md,Ms, the shininessn, and the emitted radiance can either be defined as a global parameter or as a function of the scalar field. The ambient term is often omitted. The diffuse material coefficient Mdis usually set to the same color as the emitted lightIe. The coefficients of the specular termMsandnare often specified as global parameters.

In general, however, nothing prevents us from specifying all material coefficients as function of the scalar field. A separate transfer function can be used for each optical property. In practice, there are two factors that limit this approach. The first factor is a technical limit. Every transfer function must be implemented as a dependent texture look-up in the frag-ment program, as explained in Chapter 4. There might be an upper limit for the possible number of texture look-ups, and every texture look-up will also decrease the rendering performance noticeably. The second factor is the practical aspect. Setting up a transfer function is often a tedious and time-consuming task of manual parameter tweaking. If every parameter is specified separately, the expenditure for user interaction will significantly

5.4 Local Illumination Models 119

// Blinn-Phong illumination

half4 shading(float3 N, float3 V, float3 L) { // material properties

float3 Ka = float3(0.1, 0.1, 0.1); // ambient float3 Kd = float3(0.6, 0.6, 0.6); // diffuse float3 Ks = float3(0.2, 0.2, 0.2); // specular float n = 100.0; // shininess

// light properties

float3 lightColor = float3(1.0, 1.0, 1.0);

float3 ambientLight = float3(0.3, 0.3, 0.3);

// Calculate halfway vector float3 H = normalize(L + V);

// Compute ambient term

float3 ambient = Ka * ambientLight;

// Compute the diffuse term

float diffuseLight = max(dot(L, N), 0);

float3 diffuse = Kd * lightColor * diffuseLight;

// Compute the specular term

float specularLight = pow(max(dot(H, N), 0), shininess);

if (diffuseLight <= 0) specularLight = 0;

float3 specular = Ks * lightColor * specularLight;

return ambient + diffuse + specular;

}

Listing 5.1. Cg function implementing the Blinn-Phong local illumination model.

increase. With these two aspects in mind, however, we encourage the reader to experiment with whatever concept for parameter specification will turn out to be appropriate for your application.

A sample implementation of the Blinn-Phong illumination model can be found in Listing 5.1. The model is implemented as a separate function, which will be called from different main programs later in this chapter. The material coefficientskandMhave again been combined into one coefficient K for the diffuse and the specular term, respectively. To keep the code as simple as possible, the light and material properties have been hard-coded. In practical applications, these parameters will be passed as uniform

i i

i i

i i

i i

120 Local Volume Illumination

Figure 5.5.Examples of gradient-based volume illumination using the local illumi-nation models by Blinn-Phong (left) and Cook-Torrance (right)

variables to the main function and handed over to the shading function as additional arguments. An example rendition demonstrating gradient-based volume illumination using the Blinn-Phong model is displayed in Figure 5.5 (left).

Dans le document Real-Time Volume Graphics (Page 132-138)