• 沒有找到結果。

Chapter 2 Background

2.2 Rendering Process

2.2.2 Lighting

Shading Pixels

The first quality shading in computer graphics was developed by H. Gouraud in 1971 (Gouraud 1971). In 1975 Phong Bui-Tuong (Phong 1975) improved on Gouraud’s model and Phong shading, as it is universally known, became the defacto standard in mainstream 3D graphics. Despite the subsequent development of ‘global’ techniques, such as ray tracing and radiosity, Phong shading has remained ubiquitous. This is because it enables reality to be mimicked to an acceptable level at reasonable cost.

There are two separate considerations to shading the pixels onto which a polygon projects. First we consider how to calculate the light reflected at any point

on the surface of an object. Given a theoretical framework that enables us to do this, we can then calculate the light intensity at the pixels onto which the polygon projects. The first consideration we call ‘local reflection models’ and the second

‘shading algorithms’. The difference is illustrated conceptually in Figure 2.5. For example, one of the easiest approaches to shading – Gouraud shading – applies a local reflection models at each of the vertices to calculate vertex intensity, then derives a pixel intensity using the interpolation equations.

Figure 2-5 The difference between local reflection models and shading algorithms [1]

Basically there is a conflict here. We only want to calculate the shade for each pixel onto which the polygon projects. But the reflected light intensity at every point on the surface of a polygon is by definition a world space calculation. We are basing the calculation on the orientation of the surface with respect to a light source both of which are defined in world space. Thus we use a 2D projection of the polygon as the basis of an interpolation scheme that controls the world space calculations of intensity and this is incorrect. Linear interpolation, using equal

Illustrating the difference between local reflection models and shading algorithms.

(a) Local reflection models calculate light intensity as any point P on the surface of an object.

(b) Shading algorithms interpolate pixel values from calculated light intensities at the polygon vertices.

increments, in screen space does not correspond to how the reflected intensity should vary across the face of the polygon in world space. One of the reasons for this is that we have already performed a (non-linear) perspective transformation to get into screen space. Like many algorithms in 3D computer graphics it produces an acceptable visual result, even using incorrect mathematics. However, this approach does lead to visible artifacts in certain contexts.

Local reflection models

A local reflection model enables the calculation of the reflected light intensity from a point on the surface of an object. Here we will confine ourselves to considering, from a practical view point, the most common model and see how it fits into a renderer.

This model, introduced in 1975, evaluates the intensity of the reflected light as a function of the orientation of the surface at the point of interest with respect to the position of a point light source and surface properties. We refer to such a model as a local reflection model because it only considers direct illumination. It is as if the object under consideration was an isolated object floating in free space. Interaction with other objects that result in shadows and inter-reflection are not taken into account by local reflection models. This point is emphasized in Figure 2.6.

Figure 2-6 The concept of local reflection model [1]

(a) A local reflection model calculates intensity at Pb and Pa considering direct illumination only.

(b) Any indirect reflected light from A to B or from B to A is not taken into account.

The physical reflection phenomena that the model simulates are:

z Perfect specular reflection z Imperfect specular reflection z Perfect diffuse reflection

Figure 2-7 The reflection phenomena [1]

Figure 2-8 The computer graphics surface [1]

These are illustrated in Figure 2.7 for a point light source that is sending an infinitely thin beam of light to a point on a surface. Perfect specular reflection occurs when incident light is reflected, without diverging, in the ‘mirror’ direction.

The three reflection phenomena used in computer graphics.

(a) Perfect specular reflection.

(b) Imperfect specular reflection.

(c) Perfect diffuse reflection.

Imperfect specular reflection is that which occurs when a thin beam of light strikes an imperfect mirror, that is a surface whose reflecting properties are that of a perfect mirror but only at a microscopic level – because the surface is physical rough. Any area element of such a surface can be considered to be made up of thousands of tiny perfect mirrors all at slightly different orientations.

Perfect specular reflection does not occur in practical but we use it in ray tracing models simply because calculating interaction due to imperfect specular reflection is too expensive. A perfect diffuse surface reflects the light equally in all directions and such a surface is usually called matte.

The Phong reflection model considers the reflection from a surface to consist of three components linearly combined:

Reflected light = ambient light + diffuse component + specular component The ambient term is a constant and simulates global or indirect illumination. This term is necessary because parts of a surface that cannot ‘see’ the light source, but which can be seen by the viewer, need to be lit. Otherwise they would be rendered as black. In reality such lighting comes from global or indirect illumination and simply adding a constant side-step the complexity of indirect or global illumination calculation.

It is useful to consider what types of surface such a model simulates. Linear combination of a diffuse and specular component occurs in polished surfaces such as varnished wood. Specular reflection results from the transparent layer and diffuse reflection from the underlying surface (Figure 2.8). Many different physical types, although not physical the same as a varnished wood, can be approximately simulated by the same model. The veracity of this can be demonstrated by considering looking at a sample of real varnished wood, shiny plastic and gloss paint. If all contextual clues are removed and the reflected light from each sample exhibited the same spectral distribution, an observer would find it difficult to distinguish between the samples.

As well as possessing the limitation of being a local model, the Phong reflection model is completely empirical or imitative. One of its major defects is that the value of reflected intensity calculated but the model is a function only of the viewing direction and the orientation of the surface with respect to the light source.

In practical, reflected light intensity exhibits bi-directional behavior. It depends also on the direction of the incident light. This defect has led to much research into

physically based reflection models, where an attempt is made to model reflected light by simulating real surface properties. However, the subtle improvements possible by using such models – such as the ability to make surface look metallic – have not resulted in the demise of the Phong reflection model and the main thrust of current research into rendering methods deals with the limitation of ‘localness’.

Global methods, such as radiosity, result in much more significant improvements to the apparent reality of a scene.

Leaving aside, for a moment, the issue of color, the physical nature of a surface is simulated by controlling the proportion of the diffuse to specular reflection and we have the reflected light:

a a d d s s (7)

I =k I +k I +k I

Where the proportions of the three components, ambient, diffuse and specular are controlled by three constant, where:

1 ( direction of the light source

In vector notation:

Id =I L Ni( i ) (10)

The geometry is shown in Figure 2.9

Figure 2-9 The Phong diffuse component [1]

Now physically the specular reflection consists of an image of the light source

‘smeared’ across an area of the surface resulting in what is commonly known as a highlight. A highlight is only seen by a viewer if the viewing direction is near to the mirror direction. We therefore simulate specular reflection by:

Is =IicosnΩ (11)

where:

Ω is the angle between the viewing direction and the mirror direction R n is an index that simulate the degree of imperfection of a surface

When = ∞ the surface is a perfect mirror – all reflected light emerges along the mirror direction. For other values of an imperfect specular reflector is simulated (Figure 2.7 b). The geometry of this is shown in Figure 2.10. In vector notation we have:

n

n

Is =I R Vi( i )n (12)

Bringing these terms together gives:

( ( ) ( ) )n (13)

a a d s

I =k I +I k L Ni +k R Vi

The behavior of this equation is illustrated in Figure 2.11. Figure 2.11 shows the light intensity at a single point P as a function of the orientation of the viewing vector V . The semicircle is the sum of the constant ambient term and the diffuse

term – which is constant for a particular value of N . Addition of the specular term gives the profile shown in the figure. As the value of is increased the specular bump is narrowed.

n

Figure 2-10 The Phong specular component [1]

Figure 2-11 The light intensity [1]

Local reflection model – practical points

A number of practical matters that deal with color and the simplification of the geometry now need to be explained.

The expense of the above shading equation, which is applied a number of times at every pixel, can be considerably reduced by making geometric simplifications that

The light intensity at point P as a function of the orientation of the viewing vector V.

reduce the calculation time, but which do not affect the quality of the shading.

First if the light source is considered as a point source located at infinity the L is constant over the domain of the scene. Second we can also place the view point at infinity making V constant. Of course, for the view and perspective transformation, the view point needs to be firmly located in world space so we end up using a finite view point for the geometric transformation and an infinite one for the shading equation.

Next the vector R is expensive to calculate and it is easier to define a vector H (Halfway) which is the unit normal to a hypothetical surface that is oriented in a direction halfway between the light direction vector L and the viewing vector

(Figure 2.12). It is easily seen that:

V

Figure 2-12 the vector H [1]

( ) / 2 (14)

H = L V+

This is the orientation that a surface would require if it was to reflect light maximally along the V direction. Our shading equation now becomes:

( ( ) ( ) )n (15)

a a i d s

I =I k +I k L Ni +k N Hi

because the term (N H )i varies in the same manner as (R Vi ) . These simplifications mean that I is now a function only of N .

For colored objects we generate three components of the intensity Ir, Ig and Ib controlling the color of the objects by appropriate setting of the diffuse

H is the normal to a surface orientation that would reflect all the light along V.

reflection coefficients kr, kb and kg. In effect the specular highlight is just the reflection of the light source in the surface of the object and we set the proportions of the ks to match the color of the light. For a white light, ks is equal in all three equations. Thus we have:

(( ( ) ( ) )

Local reflection model – light source considerations

One of the most limiting approximations in the above model is reducing the light source to a point at infinity. A simple directional light (non-point) is easily modeled and the following was suggested by Warn (1983). In this method a directional light source is modeled in the same way as a specularly reflecting surface, where the light emitted from the source is given by a cosine function raised to a power. Here we assume that for a directional source, the light intensity in a particular direction, given by the angle φ is :

Iscosmφ (17)

Now φ is the angle between −L, the direction of the point on the surface that we are considering, and L , the orientation of the light source (Figure 2.13). The s value of Ii that we use in the shading equation is then given by:

Ii =Is(− iL Ls)m (18)

Note that we can no longer consider the vector L constant over the scene.

Figure 2-13 The orientation of the light source [1]

Light source represented as a specularly reflecting surface.

相關文件