1. Field of the Invention
The present invention relates generally to shading computer-generated images.
2. Related Art
A. Light Equation Calculations in Shading
In computer graphics, shading is an important component that contributes to the realism of a geometric scene to be rendered. The calculations associated with shading can be split into two parts: finding surface reflectance properties at each point being shaded, and computing the incident illumination at the point being shaded. Surface reflectance properties are used by computer graphics application programming interfaces (graphics APIs) to define how a surface dissipates light. For example, one graphics API, OpenGL(copyright) by Silicon Graphics, Inc., supports five surface reflectance properties: diffuse and ambient properties, specular and shininess properties, and an emissive property. See, e.g. R. Fosner, OpenGL(copyright) Programming for Windows 95 and Windows NT (Addison-Wesley Pub.: Reading, Mass. 1997), Chapter 9, xe2x80x9cColors, Materials, and Lights,xe2x80x9d pp. 181-201. Computing the incident illumination takes into account the angle of an illumination source relative to an object surface. Lighting, half angle, and/or viewing vectors (L, H, V) are used to compute incident illumination.
These shading calculations are combined in a lighting equation to determine a color value for a respective pixel. The lighting equation can vary depending upon the particular illumination model or graphics effect that is desired. One example lighting equation used by the OpenGL(copyright) API determines a color value Cs as follows:       C    S    =            E      m        +                  A        m            *              A        s              +          (                        ∑                      i            =            0                                k            -            1                          ⁢                              A            tt                    *                      SpotL            ⁡                          (                                                                    A                    m                                    *                                      A                    l                                                  +                                                      D                    m                                    *                                      D                    l                                    *                                      (                                          L                      ·                      N                                        )                                                  +                                                      S                    m                                    *                                      S                    l                                    *                                                            (                                              H                        ·                        N                                            )                                        n                                                              )                                          )        +                  S        m            *      Env      
wherein, Em represents emissivity, Am is a material ambient coefficient, As is a scene ambient coefficient, Al is an ambient light color, Att is an attenuation factor, SpotL is a spotlight attenuation factor, Dm is a diffuse material coefficient, Dl is diffuse light color, Sm is a specular material coefficient, Sl is specular light color, n is the specular power (e.g., shininess), and Env is an environment mapping coefficient. The summation sign sums overall lights k, and like other terms in the lighting equation can be omitted depending upon a particular illumination model. L and H are the lighting and half angle vectors, respectively. See, Beider et al., OpenGL(copyright) Programming Guide, Silicon Graphics, Inc. (Addison-Wesley Publishing Co., 1993), pp. 182-194 (incorporated herein by reference).
B. Phong Shading
Shading quality is increased dramatically with Phong shading, which interpolates and normalizes vertex normal vectors at each pixel. See, Phong, B.-T., xe2x80x9cIllumination For Computer Generated Picturesxe2x80x9d, Communications of the ACM 18 6:311-317 (June 1975). In Phong shaders, light and halfangle vectors are computed directly in world space or interpolated, either of which requires their normalization relative to a local viewer and light. FIG. 1A shows a lighting vector L, half-angle vector H, normal vector N, and viewing vector V relative to an example object surface, such as, a sphere. These vectors are passed to a Phong shader. FIG. 1B shows rasterization hardware 100 for one example implementation of Phong shading. This hardware includes three sets of interpolator and normalizer units 110, 120, 130 coupled in parallel to an illumination module 150. The sets of interpolator and normalizer units interpolate and normalize respective normal, lighting, and half-angle vectors (N, L, and H). Interpolated and normalized normal, lighting, and half-angle vectors are then passed to illumination module 150 to be used in further lighting and shading calculations.
Phong shading adds cost to rasterization hardware. However, higher quality lighting is almost universally desired in three-dimensional graphics applications, and advancing semiconductor technology is making Phong shading hardware more practical to many users and vendors.
C. Bump Mapping
Bump mapping is a technique used in advanced shading applications for simulating the effect of light reflecting from small perturbations across a surface. See, Blinn, J. F., xe2x80x9cSimulation of Wrinkled Surfacesxe2x80x9d, Computer Graphics (SIGGRAPH ""78 Proceedings) vol. 12, (Aug. 1978), pp. 286-292. A single component texture map, f(u,v), is interpreted as a height field that perturbs the surface along its normal vector, N=(Puxc3x97Pv)/|(Puxc3x97Pv)|, at each point. Rather than actually changing the surface geometry, however, only the normal vector is modified. FIG. 2 shows an example of a normal vector N, a perturbation xcex94N, and the resultant vector Nxe2x80x2.
From the partial derivatives of the surface position in the u and v parametric directions (Pu and Pv), and the partial derivatives of the image height field in u and v (fu and fv), a perturbed normal vector Nxe2x80x2 is given by:
xe2x80x83Nxe2x80x2=((Puxc3x97Pv)+D)/|(Puxc3x97Pv)+D|xe2x80x83xe2x80x83(1)
where, a displacement vector D becomes:
D=xe2x88x92fu(Pvxc3x97N)xe2x88x92fv(Nxc3x97Pu)xe2x80x83xe2x80x83(2)
In these equations, Pu and Pv are not normalized. This causes the bump heights to be a function of the surface scale because Puxc3x97Pv changes at a different rate than D. If the surface scale is doubled, the bump heights are halved. This dependence on the surface often is an undesirable feature and a constant bump height is forced instead. See, Blinn, J. F., xe2x80x9cSimulation of Wrinkled Surfacesxe2x80x9d, Computer Graphics (SIGGRAPH ""78 Proceedings), vol. 12, (Aug. 1978), pp. 286-292.
A full implementation of these equations in a rasterizer can be impractical, so the computation is divided among a preprocessing step, per-vertex, and per-pixel calculations. An expensive method to implement bump mapping in hardware, and one that is planned for a high-end graphics workstation, is to compute Puxc3x97Pv, Pvxc3x97N, and Nxc3x97Pu at polygon vertices and interpolate them to polygon interiors. See, Cosman, M. A. and Grange, R. L., xe2x80x9cCIG Scene Realism: The World Tomorrowxe2x80x9d, Proceedings of I/ITSEC 1996 on CD-ROM, (1996), p. 628. The perturbed normal vector is computed and normalized as in Equation 1, with fu and fv read from a texture map. The resulting normal vector is used in an illumination model. One approximation to this expensive implementation has been proposed, where Pvxc3x97N and Nxc3x97Pu are held constant across a polygon. See, Ernst, I., et al., xe2x80x9cHardware Supported Bump Mapping: A Step Towards Higher Quality Real-Time Renderingxe2x80x9d, 10th Eurographics Workshop on Graphics Hardware (1995), pp. 63-70. This approximation is known to have artifacts.
A further technique provides high-quality, accelerated shading by bump mapping in a coordinate space, such as, atangent space or object space. See, U.S. Pat. No. 5,880,736, issued to Peercy et al., on Mar. 9, 1999 (incorporated in its entirety herein by reference). Among other things, this technique implements bump mapping by leveraging Phong shading hardware at full speed, eliminating either a large investment in special purpose hardware or a slowdown during bump mapping.
In general, as described below, the present invention is not limited to a particular bump-mapping algorithm and can be used in any graphics system that supports bump-mapping.
D. Environment Mapping
An environment map is a 360 degree image of an environment as viewed from a single reference point. Environment maps are used to model a scene at an infinite distance from a reference point. They are an arbitrary function of direction alone, and ignore parallax. Examples of environment maps include spheric or circular environment maps and cubic environment maps.
A reflection vector R is used to index an environment map. FIG. 3 shows an object surface with respective normal, lighting and reflection vectors N, V, R. One common calculation for R is:
R=2*{circumflex over (N)}*({circumflex over (N)}xe2x80xa2{circumflex over (V)})xe2x88x92{circumflex over (V)},
where {circumflex over (N)} denotes a normalized normal vector N and {circumflex over (V)} denotes a normalized viewing vector V. Texture mapping hardware is used to map texels in an environment map to an object. See, e.g., the software and hardware renderers using cubic and circular environment maps described by Voorhies and Foran, xe2x80x9cReflection Vector Shading Hardware,xe2x80x9d SIGGRAPH ""94, Computer Graphics Proceedings, Annual Conference Series, 1994, pp. 163-66 (incorporated in its entirety herein by reference).
E. Problem of Combining Bump Mapping and Environment Mapping Efficiently
A problem arises when an object is rendered with both bump mapping and environment mapping. This problem results from different geometric representations that underpin bump-mapping and environment mapping. Different types of texture maps are used to carry-out bump-mapping. A xe2x80x9cbump-mapxe2x80x9d is a texture representing a pattern of perturbations. This bump-map is used to perturb a surface normal using a fragment""s interpolated tangent and binormal vectors. A xe2x80x9cnormal mapxe2x80x9d is a texture representing a pattern of perturbed normals. Entries from the normal map are substituted entirely for the surface normals of fragments.
Since bump-mapping using a bump-map affects a Phong lighting equation or calculation by perturbing surface normals across polygons of an object, applying an environment map to a bump-mapped object is incorrect geometrically. For a normal or bump map to be used in a geometrically correct manner with an environment map, it must perturb a reflected ray used to look-up an environment map. This requires a reflector vector calculation in between bump-mapping and environment mapping. Such a reflection vector calculation is expensive in hardware. Two separate texture fetch units to carry out the bump-mapping and environment mapping would also be required.
What is needed is an inexpensive method, system, and computer program product that combines bump-mapping and environment mapping. A separate reflection vector calculation needs to be avoided. The requirement of two separate texture fetch units to carry out the bump-mapping and environment mapping also needs to be overcome.
The present invention provides a method, system, and computer program product for bump-mapping into an environment map in multiple passes. A single hardware rasterizer can be used. A separate reflection vector calculation is avoided. One hardware rasterizer can be used to perform processing in each pass. Two separate texture fetch units to support a reflection vector calculation are not necessarily needed.
In one embodiment, at least two passes are made through a hardware rasterizer to bump map into an environment map. In the first pass, a lighting equation is overloaded. The overloaded lighting equation represents a reflection vector of a perturbed normal at a pixel position. The reflection vector at a pixel position is then generated according to the overloaded lighting equation. In a second pass, at least one texel in an environment map is accessed based on the generated reflection vector. For example, the generated reflection vector can be used as a look-up into the environment map to access one or more texel samples. In this way, bump mapping and environment mapping effects can be applied in shading on a per-pixel basis in multiple passes through a rasterizer.
According to the present invention, terms in a lighting equation are overloaded to equal a reflection vector R calculated as follows:
R=2Nxe2x80x2(Nxe2x80x2xe2x80xa2V)xe2x88x92V,
where Nxe2x80x2 is a perturbed normal, and V is a viewing vector at the pixel position.
In one example implementation, a lighting equation includes a specular material vector Sm, a lighting vector L, and an ambient material vector Am. Such a lighting equation is overloaded according to the present invention by setting the specular material vector Sm to equal a perturbed normal vector Nxe2x80x2, setting the lighting vector L to equal a viewing vector V at the pixel position, and setting an ambient material vector Am to equal the viewing vector V. Other terms in the lighting equation include a specular exponent n and two vectors scli and acli. To overload the lighting equation, the specular component n is set to equal one, the vector scli is set to equal to {2,2,2}; and the vector acli is set to equal to {xe2x88x921,xe2x88x921,xe2x88x921}.
In one preferred example, hardware is used to calculate the overloaded lighting equation and thereby, generate a reflection vector. This hardware can include Phong shading hardware.
In one embodiment, the first and second passes are made through the same graphics pipeline that includes a single hardware rasterizer. The first pass carries out the steps of overloading the lighting equation and generating a reflection vector from the overloaded lighting equation. In the second pass, at least one texel is accessed from an environment map based on the reflection vector generated during the first pass. The environment map can include, but is not limited to, a spheric or cubic environment map.
In another embodiment, an additional pass is used to compute an even more geometrically correct reflection vector by passing the reflection vector through a normal subsystem to be interpolated and normalized prior to the texel accessing pass. In this additional pass, the geometry is re-drawn with a normal pointing away. In the first pass, a normal component is set to zero by setting coefficient acli equal to zero.
Further features and advantages of the present invention, as well as the structure and operation of various embodiments of the present invention, are described in detail below with reference to the accompanying drawings.