IRIX 6.5 » Books » Developer »
OpenGL Optimizer Programmer's Guide: An Open API for Large-Model Visualization
(document number: 007-2852-002 / published: 1998-06-09)
table of contents | additional info | download find in page
Chapter 8. Efficient High-Quality Lighting Effects: Reflection Mapping
OpenGL Optimizer supplements Cosmo3D lighting effects with reflection mapping, an efficient technique for simulating a complex lighting environment. With reflection mapping, also known as environment mapping, you treat a surface as a reflector and follow one ray (from your eye and reflecting off the surface) to select a point on a texture image that defines the visual environment. As an object rotates in the environment, the image appears to move over the surface. This approach contrasts with texture-mapping techniques that fix an image on a surface.
The reflection mappings available from OpenGL Optimizer form two groups:
One group uses simple reflection maps, which have approximate lighting geometry with credible sources and can be computed quickly. This group includes the sphere and Gaussian map styles.
The second group uses exact lighting geometry with relatively simple but useful lighting sources that allow accurate visualization of curvature; they are useful when visualizing smoothly curved surfaces, such as car bodies. This second group includes the cylinder, floor, and ceiling mapping types.
OpenGL Optimizer adds a shininess threshold to the basic reflection mapping algorithm so that selected objects do not reflect the environment image. This is appropriate for certain materials such as rubber, brick, and many fabrics.
This chapter discusses the principles underlying the different mapping methods, the basic control parameters for each method, and the class opReflMap, which is the API for using reflection maps. It contains the following sections:
For a more detailed discussion of reflection mapping, consult Advanced Animation and Rendering Techniques: Theory and Practice and the section on “Interobject Reflections” in Chapter 16 of Computer Graphics: Principles and Practice. Both of these books are listed in “Recommended Background Reading”.
Simple Mapping: Remote View of a Remote Environment
Two opReflMap map types—sphere and Gaussian—use simple reflection mapping. These map types are discussed in the following sections:
Simple reflection maps determine coordinates for the texture image by assuming the following:
An image that lies on a sphere surrounding the scene.
A remote environment: The reflection geometry is simplified, so that only the direction of the reflection vector determines texture coordinates. Effectively, the texture map is infinitely far away.
A remote viewer: The reflection geometry is further simplified by assuming that all rays are parallel between the viewpoint and object's surface. Effectively the viewpoint is infinitely far away. The direction of the rays is from the viewpoint to the center of the scene.
These three assumptions imply that the texture coordinates for any point on a surface are determined by the viewing angle to the center of the scene and the vector normal to the surface. For a tessellated surface, which includes correct surface-normal vectors only at vertices, the rendering algorithm calculates the texture coordinates for a point inside a triangular surface tile by interpolating the coordinates of the triangle's three vertices. As an object rotates, the directions of the normal vectors completely determine texture coordinates; you do not have to calculate a new mapping from the surface to the texture image.
You can simulate complex lighting environments at low computational cost with a simple reflection map. However, reflection angles are not exact. For example, the algorithm yields the same image point for every point on a large, flat surface. This effect is illustrated in Figure 8-1, where collimating “lenses” indicate the effects of the remote viewer and remote source approximations. Notice that the shading for all points on each face of the cube is determined by one point on the texture image, which is determined by the normal to each surface. Furthermore, the texture image is usually blurred to avoid problems that occur when the curvature of a surface can cause two points that are close together to reflect widely separated points on the texture map, an effect called aliasing. Thus you cannot closely examine reflection-map images to make accurate inferences about a surface or its reflected environment.
For sphere maps, you import a texture image, and opReflMap creates a lighting environment for your scene by projecting the texture on a sphere that surrounds the scene. The texture map first locates a point on the sphere using a remote viewer and remote environment, and then projects the point onto the texture coordinate plane (a plane through the equator) to determine the image point in the texture.
Thus, for a realistic image to appear on the surface, the texture image is a fish-eye image. Mathematical details of the projection operation are in the discussion of the glTexGen() functions in the OpenGL Reference Manual. Sphere mapping is discussed more intuitively in the section “Environment Mapping” in Chapter 9, “Texture Mapping,” of the OpenGL Programming Guide.
Gaussian mapping creates an environment map on a sphere that simulates the effect of a light source directed along the viewing direction at an imperfectly reflecting surface. It provides efficient lighting effects for models with inconsistent normals; it is a faster alternative to using two lights.
The mapping is a Phong-like illumination model characterized by a specularity parameter that controls the amount of light that is imperfectly reflected. As the specularity increases, reflections become less diffuse and more mirror-like. For more details on the Phong illumination model, see the book by van Dam and others listed in the “Recommended Background Reading”.
A special form is an infinite viewer/infinite sphere environment map where the environment is two lights with a fixed gaussian distribution. The texture map is only generated if the user does not specify an image file name or a csImage, in case Gaussian mapping act just like sphere environment mapping.
 | Note: Gaussian map mode only supports two lights fixed in the environment map.
|
Accurate Mapping: Local View of a Local Environment
Reflection mapping assumes:
A lighting geometry made of a spherical or cylindrical room
A local environment: The radius of the room is finite; reflections do not depend solely on the direction of the reflection angle. Reflections from a large flat surface vary; they show the alternating lights in the room.
A local viewer: The distance between the viewpoint and the surface is finite.
The texture coordinates depend on the complete ray-path geometry: the location of the viewpoint and the location of the reflecting surface point and its normal. These quantities, and the dimensions of the cylinder, define the point where a ray intersects the cylinder and determine the point in the texture image (see Figure 8-2).
Unlike the remote viewer and environment configuration, a ray between the viewpoint and the texture image changes as you bring the viewpoint closer to the surface or translate the surface; the complete ray geometry determines the texture coordinates associated with a point on a surface. For example, as you “walk” by a car, translating the viewpoint of the scene, lines of lights slide over the car's surface.
Figure 8-2 illustrates the general effects of a local viewer and local environment. To simplify the comparison with the remote-viewer-remote-environment approximation, the spherical texture image is the same as in Figure 8-1; the difference is that the collimating lenses have been removed. Note how each point on the cube maps to a different point on the texture map; the entire ray geometry determines the texture image point and the size of the image on the cube.
Any change in the scene or viewpoint requires a recomputation of the reflected ray, and a new mapping of the surface to the texture image. The member function updateViewInfo() calculates cylinder texture map coordinates for each frame. Clearly, this is a greater processing burden than using a remote viewer in a remote environment.
Cylinder reflection maps simulate tube lighting. The mapping assumes a local viewer and a local environment; the x axis is the axis of a cylinder with lights that run down the wall, parallel to the axis. As you move the viewpoint, the simulated lighting tubes slide over the surface.Tube lighting is the default when opReflMap has no image file; that is, you can attach an image to the cylinder.
In cylinder mapping (a.k.a. reality mapping) the environment map is placed on a finite radius sphere, at a user-defined origin. If no image file or csImage is given to opReflMap, then a default black and white striped texture map is automatically generated. The user can control the width, spacing, and coloration of the stripes. Stripes reflected off the body of an automobile can be an useful aid to visualizing surface curvature and anomolies.
The sample application zebraFly can be used to illustrate this (see “Reflection Mapping”).
Figure 8-3 illustrates the viewing configuration used for the cylinder map.
opReflMap has accessor methods to control parameters of the cylinder map.
Reflection-Mapping Class: opReflMap
The opReflMap class provides the tools for the different reflection-mapping types discussed in this section.
Use any of the three simple reflection maps to rotate objects in the scene to observe changing reflections.
Use the more computationally expensive cylindrical environment map to more realistically shift the lighting as you “walk” around a surface. The function updateViewInfo() updates the texture coordinates as you walk around.
In addition to the constructor, opReflMap's methods fall into three groups: those that are independent of the type of reflection map set by the constructor, those that apply only to the Gaussian map type, and those that apply only to the cylinder, floor, and ceiling maps. No special function is needed to control the sphere map.
Class Declaration for opReflMap
This class has the following main methods:
class opReflMap
{
public:
opReflMap( csGroup *root, char *fileName, unsigned int mt );
opReflMap( csGroup *root, csImage *inputImage, unsigned int mt );
opReflMap( csGroup *root, opReal spec, unsigned int mt );
~opReflMap( void );
// Sets and gets
void setScene( csGroup *root ) ;
csGroup *getScene( ) ;
void setSpecularity( opReal spec );
opReal getSpecularity( );
void setScale( opReal _scale );
opReal getScale( );
void setXoffset( opReal offset );
opReal getXoffset( );
void setYoffset( opReal offset );
opReal getYoffset( );
void setZoffset( opReal offset );
opReal getZoffset( );
void setStartAngle( opReal angle );
opReal getStartAngle( );
void setEndAngle( opReal angle );
opReal getEndAngle( );
void setMapType( uint mt );
unsigned int getMapType( );
void setShinyThres( float t );
float getShinyThres( );
void setXRes(int res);
int getXRes();
void setYRes(int res);
int getYRes();
csTexture *getTex()
csTexGen *getTexGen()
void setCBias(float bias)
float getCBias()
void setLightTint(float r, float g, float b)
void setSpaceTint(float r, float g, float b)
// Compute the new texture coordinates for a given geoset
void computeTexCoords( csTriStripSet *gs );
void computeTexCoords( csTriFanSet *gs );
// Run over the scene graph updating the texture coord
void computeAllTexCoords( );
// Tell the reflection map to update it's viewing information
void updateViewInfo(
csCamera &camera, csTransform &transform, csVec3f ¢er );
// Enables the texture appearance on the scene graph's shape nodes'
// apearances
void setTextureApp( bool enable );
};
|
The following opReflMap methods are independent of mapping type:
| opReflMap(root, fileName, mt), opReflMap(root, spec, mt), and | |
opReflMap(root, inputImage, mt)
Construct a reflection map of type mt, where mt is an element of an enumerated type: SPHERE, GAUSSIAN, CYLINDER, FLOOR, or CEILING. If mt is GAUSSIAN, spec is the specularity parameter; the default value is 2.0.
| | setMapType() and getMapType() | |
Set and get the map type, which is SPHERE, GAUSSIAN, LSPHERE, CYLINDER, FLOOR, or CEILING.
| | setScene() and getScene() | |
Set and get the scene graph for which opReflMap builds a reflection mapping.
| | setShinyThres() and getShinyThres() | |
Get and set the threshold value for mapping a reflection from a surface. The threshold is compared with the value of an object's csMaterial shininess parameter, which can vary from 0.0, for no reflections, to 1.0 for a perfect reflector. The default value is 0.0.
|
For GAUSSIAN reflection maps, you have the following specific methods:
| setSpecularity() and getSpecularity() | |
Get and set the specularity parameter for the GAUSSIAN mapping, a Phong-like illumination model. As the specularity parameter increases, the surface appears more mirror like. The default value is 2.0.
|
For CYLINDER reflection maps, you have the following specific methods:
| setScale() and getScale() | |
Get and set the radius for the CYLINDER mapping.
| | setStartAngle() and getStartAngle() | |
Set and get the angular elevation, in radians, of the right edge of the light cylinder as you look in the negative x direction. The angle is measured from the y axis in the z-y plane.
| | setEndAngle() and getEndAngle() | |
Set and get the angular elevation, in radians, of the left edge of the light cylinder as you look down the center of the cylinder in the negative x direction. The angle is measured from the y axis in the z-y plane.
| | computeTexCoords() | |
Computes texture coordinates for a particular csGeoSet, so you can update the reflection map for a local viewer and environment when you change the relative position of the viewpoint and the object.
| | updateViewInfo(camera, transform, center) | |
Translates the center of the scene to center, changes the viewing angle according to the matrix transform, and computes new texture coordinates for the entire scene graph. A simple rotation matrix gives the best results. Use the center parameter to set the distance from the center of the scene.
|
OpenGL Optimizer Programmer's Guide: An Open API for Large-Model Visualization
(document number: 007-2852-002 / published: 1998-06-09)
table of contents | additional info | download
Front Matter
About This Guide
Part I. Getting Started
Part II. High-Level Strategic Tools for Fast Rendering
Part III. Specific Tools for Fast Rendering
Part IV. Managing and Rendering Higher-Order Geometric Primitives
Part V. Traversers, Low-Level Geometry Processing, and Multiprocessing
Part VI. Utilities and Troubleshooting
Part VII. Appendices
Glossary
Index
home/search |
what's new |
help
|