Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Advanced_Renderman_Book[torrents.ru]

.pdf
Скачиваний:
1714
Добавлен:
30.05.2015
Размер:
38.84 Mб
Скачать

2.2 Geometry

29

Figure 2.5 Tangent lines and normal vectors to a curve at two points.

In three dimensions, the tangent to a surface is a plane and is also unique. Any vector that lies in the tangent plane is tangent to the surface, so there are infinitely many tangent vectors, radiating from the point at all angles. Generally, it is quite easy to find two of the tangent vectors that lie on the tangent plane: take the partial derivatives of the surface equations with respect to a couple of the variables. For example, consider a parametric equation of two variables, u and v. The partial derivative of the equation with respect to will give us one such tangent vector, as will the partial derivative with respect to

Another important concept (that is probably obvious if we think about it for just a moment) is that there is a unique direction that is perpendicular, or "normal," to a plane. This unique vector is called the plane's normal vector. Of particular interest to us is the vector that is normal to the tangent plane at the particular point on the surface. For obvious reasons, we call it the point's normal vector and usually denote it N (see Figure 2.5). Conversely, if you have a normal vector at a point, you immediately know the tangent plane at that point.

This relationship between planes and normals means that you can derive one from the other. Any vector that is perpendicular to the normal must be in the tangent plane, and the normal is perpendicular to all vectors in the tangent plane. Because it takes two vectors to define a plane (for example, the partial derivatives defining the tangent plane), the unique vector that is perpendicular to both vectors must be the plane normal. Recall from Section 2.1.2 that the main tool for computing perpendicular vectors is the cross product, so we can immediately say that

We mentioned earlier that points and direction vectors transform differently. Normal vectors transform in yet a third way-they use a different matrix! Normal vectors transform through the inverse transpose matrix, that is, the transpose of the inverse of the matrix, which is denoted For many matrices, including most of the matrices that we see in common cases in computer graphics, the inverse of a matrix and the transpose of it are

identical, so they cancel and = M. For

2 Review of Mathematics and Computer Graphics Concepts

this reason, a common mistake is to transform normal vectors just like direction vectors. In fact, you should always use the inverse transpose.

Just to be complete in our confusion, tangent vectors do transform just like direction vectors. Sigh!

2.2.3Curvature

The next, more abstract concept beyond the tangent at a point is the curvature. Just as the tangent measures the slope of a line that touches the object without crossing it (at least, locally), the curvature measures the radius of a circle that hugs the object without crossing it. If the circle is very small, the surface has high curvature; and if the circle is very large, the surface has low curvature. As you might expect by now, the curvature is computed by taking the second derivative of the surface equations. Note that curvature is a signed quantity. Positive curvature means the surface curves up, cupping the surface normal. Negative curvature means the surface curves down, drooping away from the surface normal. Zero curvature means the surface is flat.

Just as there are infinitely many tangent vectors at a point on a surface, all radiating at different angles, so too there are infinitely many curvatures, corresponding to all the circles oriented at different angles around the point. Of these, a few in particular are interesting. On a parametric surface, the curvatures in the two parametric directions are interesting because they are easy to compute. However, these values are not necessarily the "most curved" directions on the surface. If we are interested in those, we need values known as the principal curvatures, Kmax and Kmin• The equations for computing K are somewhat complex and scary, so persons wearing Math-Sensitive SunglassesTM will see a large blank space next:

The curvature in the a and v directions are Ku and Kv, respectively. The curvature along the two principal axes are Kmin and Kmax. The angle between one principal axis and a is 4> (as is the angle between the other principal axis and v), but without

2.3

Physics and Optics

 

 

evaluating K, you can't really know which is the axis of minimum curvature and which is the

 

axis of maximum curvature.

 

For most surfaces, K,min and Kmax are both the same sign, implying a bump or dent, or one

 

of them is 0.0, implying it is flat in some direction, like a cylinder. Surfaces for which Kmin is

 

negative and Kmax is positive are known as saddles, because in one direction they bend up and

 

in the perpendicular direction they bend down, like a horse's saddle.

2.2.4

Continuity

 

 

 

When two primitives with different surface equations are set adjacent to each other,

 

conceptually joined to become parts of the same object, we are often concerned about the

 

continuity at the seam. The type of continuity that exists at the seam determines whether we

 

consider the seam to be "smooth." There are four types of continuity that are typically of

 

interest to us:

 

 

 

the surface is connected but could have sharp corners

 

the first derivative has no abrupt changes-no corners-but could have abrupt curvature

 

changes

 

 

 

the second derivative, curvature, has no abrupt changes-surface feels smooth

 

no derivatives at any level have abrupt changes-mathematically smooth

 

For example, when two polygons share an edge but there is an angle between them, the seam

 

has a cusp, a corner, and therefore the surface is

edge. Two semicircles that connect to

 

form an S-shaped curve are

the joint but are

discontinuous there.

2.3Physics and Optics

Many computer graphics algorithms, particularly shading algorithms, rely on the simulation of various aspects of the physics of materials and light to provide their realism. Sometimes the physical properties are duplicated exactly, sometimes they are approximated, sometimes ignored entirely and replaced by ad hoc rules. However, a little bit of physical intuition and a few simple equations will help you program RenderMan much more effectively.

2.3.1Light Spectra

As everyone remembers from elementary physics, visible light is a wave of electromagnetic energy within a certain range of wavelengths (roughly 380 nanometers to 750 nanometers, or 790 to 400 teraHertz). In fact, most forms of visible light contain a continuum of frequencies, each at a different intensity. This function of intensities at various frequencies is called the light's spectrum. Each wavelength of

2 Review of Mathematics and Computer Graphics Concepts

light corresponds to a color in the rainbow, and light beams that are dominated by a particular color appear to our eyes to have that color. Light beams that have a spectrum like that of sunlight, roughly equal intensity over a broad range of colors but somewhat dominated by colors near 530 nn (green), appear "white" to us, and are called white light.

Most interactions between light and materials are wavelength dependent, meaning that they have different effects upon light of different wavelengths. For example, refraction of light through a prism separates the light into a rainbow of colors because light's refraction direction is dependent on wavelength. Blue wavelengths refract more than red, which spreads a white light beam apart into the visible spectrum.

When we look at an object, we see the spectrum of the light that is reflected from that object. The surface color of the object is due to the fact that each material absorbs more light at certain wavelengths and reflects more light at other wavelengths. This process, where the color is determined by the remaining light after certain portions of the spectrum have been removed, is called subtractive color. The filtering of transmitted light is another example of a subtractive process. The color of a filter, such as a piece of stained glass, is primarily based on the spectrum that remains after the light that is passing through has mostly been absorbed by the filter. A "red" filter is one that absorbs most of everything except red.

The complementary process, where the color is determined by adding together light emitted from various colored light sources, is called additive color. Television monitors are an example of an additive process. The color on a monitor is determined by the sum of the spectra that the phosphors emit (actually, this is a somewhat complex situation, due to a subtle interaction with our visual system described in Section 2.4.7).

2.3.2Reflection and Refraction

When light reflects off of a mirrored surface, the direction of the reflected ray is easily computed due to the well-known maxim that "the angle of reflection equals the angle of incidence." This relationship is shown in Figure 2.6. In distilling this relationship into an equation, we take advantage of the fact that the normal vector describes the mirror plane. By looking at relationships of the vectors in the figure, it is pretty easy to tell just by looking that the reflection vector can be computed by for some constant a. Invoking a little trigonometry (and assuming that the vectors N and 1 are normalized), With a little algebra,we can see that But remembering the dot product rule, we can say

we conclude that It turns out the equation is the same even if 1 isn't normalized, but it's a little messier if N isn't normalized. And if you prefer the vectors to point in different directions, you might negate one term or other.

2.3Physics and Optics

Figure 2.6 Computing reflection vectors.

When light refracts through a transparent surface, the direction of the refracted vector is computed using a well-known equation called Snell's law. This law specifies how light is bent by using the indices of refraction for the material that the light is leaving and for the

material that the light is entering. The index of refraction of a material, usually denoted n (eta), is a physical constant of the material and can be looked up in physics reference books such as the CRC Handbook. For most common materials, such as the ones listed in Table 2.1, the index of refraction is in the range of 1.0 to around 2.3. Vaguely speaking, as light enters a material that is more dense, it is bent towards the surface normal; and as it enters a material that is less dense, it is bent away from the surface normal (as illustrated on the top of Figure 2.7). The precise equation is:

where is the angle between surface normal and the light ray on that side.

There are several important subtleties about refraction that every good computer graphics artist should know. First, the index of refraction of material is actually

2 Review of Mathematics and Computer Graphics Concepts

34

Figure 2.7 Computing refraction vectors and total internal reflection.

wavelength dependent. This means that as light travels through it, different colors get bent more than other colors. For some materials, this effect is minor, for other materials, this effect is usefully large. This is, of course, how prisms work.

Second, when light strikes an object, no matter how clear it is, not all the light enters the object and is refracted. Some light is absorbed, of course, but also some light is reflected. The Fresnel equation tells us the intensity of the light that will pass through (be transmitted and refracted) and the intensity of the light that will be reflected off the surface. The Fresnel equation is very dependent on incoming light angle because light that strikes perpendicular to the surface will transmit strongly, while light that strikes at a glancing angle reflects very strongly.

Third, it is interesting to consider the following situation. Light is inside the dense material, and it approaches the boundary at a glancing angle, quite a bit away from the surface normal. The bottom of Figure 2.7 shows the situation. Because refraction bends it even farther away from the surface normal, Snell's equation implies that the refraction angle should be more than 90 degrees. But that would put the refraction direction T inside the object! That would not be refraction, of course, so the light refuses to go in that direction. The refraction simply doesn't

bidirectional reflection

2.3

Physics and Optics

35

occur, and all of the light is reflected off the boundary instead. This situation is known as total internal reflection.

It is also useful to note that if light is passing through a flat solid with parallel walls (for example, a pane of glass), the final light direction on the far side will be the same as the original direction. The light gets bent to the side and then gets bent exactly back again, the difference being that it was simply shifted to the side a little.

2.3.3 Light Interacting with Surfaces

When light strikes the surface of an object, some portion of the light is absorbed by the object and some portion of the light reflects off the object in various directions. The spectrum that it reflects strongly is seen as the object's "color." The exact directions and colors of the reflections depend on many factors, such as the direction of the incoming light, the chemical makeup and electrical properties of the material, the macroscopic and microscopic geometry of the surface, and even physical effects, such as diffraction and interference. Materials that appear smooth tend to reflect light primarily in the direction of the reflection vector, with some light reflected in directions near the reflection vector and almost no light reflected in other directions far frorn the reflection vector. Materials that appear rough tend to reflect light strongly in a wide range of directions. Transparent materials, such as plastic and glass, refract some light based on angle-dependent Fresnel equations, so they reflect more strongly at glancing angles and therefore appear glossy. Iridescent materials reflect different colors at different angles due to destructive interference in the reflection.

In fact, these light reflection properties are actually components of a more comprehensive characteristic of the material known as the

distribution function or BRDF. The BRDF determines the intensity of reflection in every direction and at every wavelength, based on the incoming light direction. There are no good general-purpose techniques for predicting the exact BRDF of a material based on its chemical composition and manufacturing process, so tables of the BRDF for various materials are almost always created by careful examination of a sample of the material.

It is often the case that at the microscopic level, the surface of a material is actually a complex composite of different types of materials mixed together or layered on top of each other, each of which has a different BRDF. For example, common plastic is a mixture of a pure-white transparent base material with tiny flecks of opaque paint particles suspended in it. Human skin, on the other hand, is a complex layering of translucent cells, some dead, some living, some brown, some red, covered with thin layers of oil and moisture, which together have a very complicated composite interaction with light that strikes it.

2 Review of Mathematics and Computer Graphics Concepts

36

Figure 2.8 Diagram of a typical camera.

2.3.4Cameras and Depth of Field

Physical cameras have three important parts, a lens system, a lens diaphragm with an adjustable aperture, and film to record the image. The lens system in modern cameras is usually relatively complicated-it magnifies, is typically adjustable in several ways, compensates for certain types of optical distortion, and so on. However, at any given zoom and focus setting, the multielement lens system is effectively equivalent to a single perfect converging lens at some position in the lens barrel. The lens system focuses light onto the film, which lies flat on a plane in the back of the camera, behind the shutter (see Figure 2.8). Because of the way the lenses work, the image on the film plane is upside down. Narrowing the lens aperture blocks some light from reaching the film, and therefore dims the image.

The primary characteristic of a lens is its focal length, which is the distance from the center of the lens to the point where light from an infinitely distant object will focus. The focal length of a simple lens is determined solely by how it is manufactured, the material, and the curvature of the lens, and so it is a constant. However, light that does not come from an infinitely distant object will focus at a different distance, as determined by the thin lens equation:

Notice from this equation that as an object comes closer to the camera, the image focuses farther back. A camera focuses on those closer objects by moving the lens back and forth so that the distance to the film plane matches the for that object.

2.3 Physics and Optics

37

Figure 2.9 An object whose image distance does not match the film plane appears out of focus. C1 and C2 are the circles of confusion before and after the aperture has been used to shrink the effective lens diameter.

When the film plane is not adjusted correctly for a given object, it will be out of focus. As we can see from Figure 2.9, the light streaming toward the focus has the shape of a cone, and the misaligned film plane cuts the cone in a large diskshaped region. We call this region the circle of confusion, and its size depends on two things: the amount of the misalignment of the focus and the diameter of the lens. Notice that a smaller lens would have a narrower light cone, and all circles of confusion would be smaller.

The interesting feature of the circle of confusion is that if it is smaller than a certain size-say, smaller than the resolving power of the film or of our eyes-we can't really notice it, and the object appears to still be in focus. For this reason, even though there is only one unique distance that the lens focuses exactly, there is a range of distances for which objects are only so slightly out of focus that the circle of confusion is not objectionable. This range of distances is known as the depth of the camera's field or simply depth of field.

The final piece of this puzzle is to see that the aperture in the lens diaphragm has the effect of shrinking lens diameter without changing the other physical characteristics of the lens. By making the aperture smaller, it cuts off the sides of the focusing cones, which has the dual effect of making the image dimmer and shrinking the circles of confusion. Smaller circles mean more objects are in focus, there is more depth in the field. The measure of the size of the aperture is known in physics literature as the f-number and in camera literature as the f-stop. Because fnumber is defined as focal length divided by aperature diameter, smaller apertures have bigger f-numbers. If the aperture shrank down to nearly zero (an f-number approaching infinity), nothing would have a noticeable circle of confusion, and all

38

2 Review of Mathematics and Computer Graphics Concepts

objects would appear to be in focus. This is why the pinhole camera has infinite depth of field.

2.4Computer Graphics

In the 30 years that computer graphics has been studied, many algorithms, techniques, and tricks of the trade have been invented. Over the years, many have been refined, put onto a firm theoretical basis, and studied extensively. Others are hacks that are used because they look good. Often, it is not easy to tell (or remember) which is which. But having a good working vocabulary of these techniques is vital to doing good work with RenderMan, a system that was specifically designed to promote the development of new techniques.

2.4.1Antialiasing

Aliasing is perhaps the most reviled artifact to plague computer graphics images. Also known as "stair-stepping" or "jaggies," aliasing is a term we borrow from signal processing theory to describe artifacts that come from inadequate sampling of the underlying scene.

A scene is continuous, meaning that the scene description provides sufficient information for there to be a color at every infinitesimal point on the image plane. The pixels of an image are regularly spaced discrete samples of the colors of the scene. The few discrete pixels we decide to put into the frame buffer are therefore only representative of the continuously varying colors underneath. If you were to graph the continuous colors (in one dimension along a scanline, or in two dimensions over the whole image), you would have an oscilloscope-like signal. Such signals, be they heartbeats or audio waveforms or scene colors, all have various frequencies in them; signals that move up and down fast have higher frequencies than those that change slowly. One of the most important theories of signal processing (known as the Nyquist theorem) says that representing a signal accurately takes twice as many regularly spaced discrete samples as the highest frequency in the signal. Rarely do computer graphics images have such high spatial resolution. Without enough samples, we get abasing. The interesting high-frequency data is lost and is replaced by inconsistent and visually upsetting low-frequency aliases that were not really part of the scene (see Figure 2.10).

There are two ways around this conundrum. First, our samples can be nondiscrete. That is, they can represent not the specific colors at particular points in the scene, but instead some average color over a region of the scene. Supersampling, where each pixel is a weighted average of many samples that are close together, and area sampling, where each pixel is the weighted average of the regions of color in some area covered by that pixel, are both techniques that can be used to reduce aliasing. When these techniques are used well, the high-frequency data is still

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]