Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
HP PEX Implementation and Programming Supplement: HP9000 Series 700 Color Workstations > Chapter 10 Texture Mapping Tutorial

Detailed Discussions

» 

Technical documentation

Complete book in PDF
» Feedback
Content starts here

 » Table of Contents

 » Glossary

 » Index

This section contains more detailed discussions of some selected texture mapping-related topics below:

Discussion: MIP Map

"MIP" stands for multum in parvo; literally, "many things in a small place."

  • Why use MIP maps?

    MIP maps are generally used to reduce the aliasing effects that naturally take place with texture mapping. Because the cost and repetition of anti-aliasing calculations are high, pre-computing their values in the form of a MIP map can dramatically reduce the overall performance cost of anti-aliasing.

    When a texture map is accessed for a single screen pixel, one of three things can happen:

    • The pixel maps to less than one texel (this means that several screen pixels map to a single texel of the texture map.) The texel information must be "magnified" (by interpolating information from neighboring texels) to cover the pixel.

    • One pixel maps to a single texel (the ideal case)

    • One pixel maps to several texels. The texel information must be "minified" to represent the average color of all the covered texels.

    In cases 1 and 3, a MIP map allows a color to be easily approximated for the screen pixels in near-constant time. This averaging mechanism minimizes the effects of aliasing as much as possible in a cost-effective manner.

  • How is a MIP map created?

    A MIP map is a pyramid of images with the base of the pyramid equal to the original source texture map. Each successive level of the texture map is created using a box filter for each texel in the next level. In other words, four texels in one level of the map (in a 2×2 square) are averaged to create one texel in the next, smaller level. Thus, each successive level in a MIP map is a quarter of area of the previous level. The number of levels in a MIP map is also referred to as the depth of the map. The highest, and smallest, level of the MIP map is referred to as the "pinnacle."

    PEXlib provides the utilities PEXExtCreateFilteredTM and PEXExtCreateFilteredTMFromWindow to create a MIP map from a source map provided by the application. One of the parameters passed to the PEXExtCreateFilteredTM* utilities is the number of levels to create. If zero is specified, the optimum number of levels will be created to produce a full MIP map.

  • How is a MIP map used?

    The values specified in the Sampling LUT determine how the MIP map is actually sampled to find the appropriate color for a single pixel. The minification method specifies how the map should be sampled when one screen pixel maps to several texels and the magnification method determines what to do in the case of multiple pixels mapping to a single texel. The possible methods are detailed in the table below and vary depending on how many pixels per level are sampled and how many levels are sampled to determine the final color. Note that for magnification, only the first two, PEXExtTMTexelSampleSingleBase and PEXExtTMTexelSampleLinearBase are recommended. In the table, where "2n" is specified, n refers to the texture map dimension: 1, 2, or 3.

    Table 10-1 MIP Map Usage

    Method (minification or magnification)

    Texels sampled per level

    Level(s) sampled

    PEXExtTMTexelSampleSingleBase

    1

    Base level only

    PEXExtTMTexelSampleLinearBase

    2n

    Base level only

    PEXExtTMTexelSampleSingleInMipmap

    1

    One level closest to sample depth

    PEXExtTMTexelSampleLinearInMipmap

    2n

    One level closest to sample depth

    PEXExtTMTexelSampleBetweenMipmaps

    1

    Two levels closest to sample depth

    PEXExtTMTexelSampleLinearBetweenMipmaps

    2n

    Two levels closest to sample depth

     

    Given these methods, the MIP map is sampled according to the following formula:

    • The number of texels in the base map that are covered by a single pixel determines if the minification method or magnification method should be used. The number of texels also determines which level should be sampled if the minification method specifies a level other than the base level. The depth_sampling_bias_hint value in the Sampling LUT can shift this sampled level up or down to make the texture appear more detailed or more blurred.

    • The minification method or magnification method, as appropriate, is used to determine how many pixels should be sampled.

    • If more than one texel is sampled as specified by the minification method or magnification method, the texels are averaged to derive the final color value.

User Interface Considerations for Creating Filtered Texture Maps

Some PEXlib implementations require texture map dimensions to be a power of two and/or require square maps (your implementation's requirements can be determined by PEXGetImpDepConstants). The utilities PEXExtCreateFilteredTM and PEXExtCreateFilteredTMFromWindow will resize the maps if demanded by the implementation. In some rare instances, the user may want total control over how the images are resized to meet the implementation requirements. The user may want to specify whether the map be cropped to meet the requirements or shrunk or enlarged using a filter. In these cases, the application will need to perform the shrinking or enlargement itself, before calling PEXExtCreateFilteredTM (or PEXExtCreateFilteredTMFromWindow). The utilities PEXExtCreateFilteredTM and PEXExtCreateFilteredTMFromWindow filter according to these rules:

  • If a power of two is required, each dimension is resized to the closest power of two. If the closest power of two is smaller than the original dimension of the map, the map is down-sampled using a box filter. If the closest power of two is greater than the original dimension, the map is up-sampled using linear interpolation.

  • If texture maps are required to be square, the texture map will be enlarged using linear interpolation to have dimensions equal to the largest of the two original dimensions.

  • If both power-of-two and square texture maps are required, the dimensions will first be resized to a power of two and then the largest dimension will be used as the dimension of the final map.

Troubleshooting

This troubleshooting section is separated into several sections; choose the desired texture-mapping subject matter.

Frequently-Asked Questions

Q.

What areas should be checked if textures fail to render?

A.

Texture mapping may fail when some of the following conditions occur:

  • Neither the extended primitives (PEXExtFillAreaSetWithData, PEXExtSetOfFillAreaSets, PEXExtTriangleStrip, PEXExtQuadrilateralMesh) were called; nor were the OCC alternatives PEXOCCFillArea, PEXOCCFillAreaSet, PEXOCCIndexedFillAreaSets, PEXOCCTriangleStrip, and PEXOCCQuadrilateralMesh called. These are the only primitives for which texture mapping is supported.

  • The interior style PEXExtInteriorStyleTexture was not specified for either front and/or back faces.

  • The PEX server does not support the 5.1 texture mapping extended renderer, determined by inquiring its support with PEXGetEnumTypeInfo.

  • No texture maps or coordinates were supplied. In this case, the default map (a black-and-white checkerboard) is used, but since no texture coordinates existed, the default specifies a coordinate of (0,0) per vertex, which translates into a single point of a white square (or black square on some implementations non-HP implementations).

  • Texture coordinates were out of range when the active texture coordinate clamp condition was PEXExtTMBoundaryCondBoundary. Scaling coordinates to be between [0,1) or attempting the clamp condition PEXExtTMBoundaryCondWrap (if it is supported) may resolve this.

  • Texture coordinates were out of range when the active texture coordinate clamp condition was PEXExtTMBoundaryCondClampColor. If the clamp color specified was black (the default), then the surface should appear black as well. Try specifying a color of red (1,0,0) in the Sampling LUT entry to determine if the clamp condition is being used.

  • The texture map input may be invalid. If so, try another map type and be certain it abides by any implementation-dependent constraints such as PEXExtIDPowerOfTwoTMSizesRequired and PEXExtIDSquareTMRequired. Note that the utilities PEXExtCreateFilteredTM and PEXExtCreateFilteredTMFromWindow can be used to ensure the implementation constants are met.

  • Data from the utilities for texture coordinates or filtered texture maps was invalid. Be certain to check the return status of these functions to determine the correctness of their data.

Q.

Under what conditions might one see the default texture (a checkerboard) appear?

A.

The default texture appears when:

  • When the active [backface] texture list is empty (zero in length).

  • When the active [backface] texture list specifies a nonexistent Binding LUT entry.

  • When a user Binding LUT table is unspecified.

  • When an invalid TMDescription or texture map ID is detected.

Q.

What types of image file formats does PEXlib support?

A.

None. The library supports utilities to perform xwd-like window grabs (PEXExtCreateFilteredTMFromWindow) once an image is displayed, however it cannot read or use a file format directly.

Q.

Does PEXlib limit the number or size of textures which can be used?

A.

PEXlib does not limit the number of textures which can be predefined by PEXExtCreateTM or PEXExtCreateTMDescription, however, implementations may limit the actual number of textures which can be applied to any one extended surface primitive at a time. This limit is specified by the constant PEXExtIDMaxTextureMaps on a per-primitive basis. The size of a texture may also be limited by the value specified in PEXExtIDMaxFastTMSize if texture mapping acceleration is available to a user. Both values can be inquired by PEXGetEnumTypeInfo.

Q.

Why do the scaling matrices in the TMCoordSrc LUT behave inversely to their expected effect on a texture; for example, scaling values greater than 1 create multiple copies of a map on my surface?

A.

Texture coordinate space is ideally defined between zero and one [0.0,1.0). When a texture coordinate is scaled by a value greater than one in the orientation matrix of a TMCoordSrc LUT entry, its value spans a texture coordinate space distance greater than or equal to one. In this case, the texture coordinates will, if the correct wrap or mirror boundary conditions are set, sample more than one texture "space" in a periodic fashion.

For example, the orientation matrix:

|3 0 0 0|
|0 2 0 0|
|0 0 1 0|
|0 0 0 1|

transforms the texture coordinates (0,0) and (1,1) to be the new forms (0,0) and (3,2). As the texture coordinates are interpolated across texture space, the boundary conditions for zero and one are examined and the appropriate wrap or clamp actions taken. (To wrap, compute the value t'0=t0-[t0] and t'1=t1-[t1].) In the above example, boundary conditions of PEXExtTMBoundaryCondWrap for t0 and t1 would result in three copies of the texture in the t0 direction and two copies in the t1 direction. This stems from the fact that the texture space range of zero to one [0,1) fits into the above ranges three and two times, respectively.

A matrix of the type:

|0.25 0 0 0|
| 0 0.25 0 0|
| 0 0 1 0|
| 0 0 0 1|

would map the texture coordinates (0,0) and (1,1) to the new forms (0,0) and (0.25, 0.25) in texture space, thus sampling only a fraction of the total map.

Texture Maps

Q.

How does one avoid or fix the unpleasant texture seams which may occur on an object?

A.

Texture seams can become visible when:

  • The boundary condition PEXExtTMBoundaryCondWrap is active in a given direction and opposing edges of a texture map do not match in color. To correct this, ensure the opposing edges of a map (top=bottom, left=right) share the same color. This can be performed in many interactive image processing and paint packages. Alternatively, the boundary condition PEXExtTMBoundaryCondMirror, if supported, may help in certain situations.

  • Texture coordinates on a primitive do not quite stretch between [0,1), thus the underlying color of a primitive (such as white) reveals the edge of the map. In this situation, explicit texture coordinates can either be scaled and restored in the vertex to account for this condition (scale operation occurs once) or the orientation matrix in the TMCoordSrc LUT can hold a scale matrix (less efficient due to per image cost to rescale texture coordinates).

  • Two textures in proximity to each other (by nature of their texture coordinates) do not overlap at their edges cleanly due to precision problems or because of contrasting colors. Under these situations, corrections may be possible by either editing textures to share edge colors explicitly or forcing one texture to overlap the other via its orientation matrix.

  • The texture coordinate utility functions (PEXExtTMCoord*) are susceptible to producing parameterizations with obvious "seams." Seams created here occur when a projection method wraps over a boundary condition (both cylindrical or spherical projections have seams at their positive (+X) axes). Using the orientation matrix contained in the param_data argument of these utility functions can reorient this seam condition to other parts of an object's geometry (in many desirable cases, the side opposite the observer).

Q.

Why does my input texture map appear to be inverted (upside down) on the textured surface?

A.

The problem may be caused by the ordering of your texture map scanlines. PEXlib texture maps assume to have their origins (0,0) at the lower left edge of the quadrant. Many formats (such as X) assume the upper left. Maps should be inverted in scanline order if their origins are in conflict with PEXlib. Alternatively, an appropriate orientation matrix can flip these coordinates as well, although this method may cause more calculation and precision costs later in the pipeline. (The utility PEXExtCreateFilteredTMFromWindow already performs this inversion.)

Surface Parameterization

Q.

When parameterizing certain objects (such as a sphere composed of polygons), why do texture maps appear to sometimes "swirl" around the natural poles of the object?

A.

The poles of a sphere correspond to the "top" and "bottom" edges of a 2D texture as they collapse down to one point. Since the texture coordinate utilities PEXExtTMCoord* compute projections on a per-vertex basis, it is not possible to represent all points along these edges as one point. Instead, the projection utility will usually choose one or more points (depending upon the coordinate source selected), which will then be interpolated during rendering. When this occurs, a swirling effect appears which is often emphasized by having large primitives at the top (or bottom) of the sphere. This visual effect can be minimized by reducing the sizes of any "polar" primitives of the sphere, but it cannot be totally eliminated from this parameterization approach. (Ray tracers escape this problem by evaluating the projection equation at each pixel, not each vertex, thus minimizing the effect of the polar singularity.)

Q.

Why do certain primitives (the extended primitives PEXExtFillAreaSetWithData, PEXExtSetOfFillAreaSets, PEXExtTriangleStrip, and PEXExtQuadrilateralMesh; or the OCC alternatives PEXOCCFillArea, PEXOCCFillAreaSet, PEXOCCIndexedFillAreaSets, PEXOCCTriangleStrip, and PEXOCCQuadrilateralMesh) sometimes appear to have discontinuous textures applied across their surfaces, even though the texture coordinate utilities worked on the primitive all at once?

A.

The primitives described above are shared-vertex types of surface primitives. Although facets of these primitives may share geometric vertices, they may not actually share the shading normals associated at these points. Thus, if the texture coordinate source is PEXExtTMCoordSourceVertexNormal and a facet normal must be substituted, the coordinates stored in the vertex will be those of the last shared facet to that vertex point (which may be incorrect for all other primitives). The only solutions to this problem are to ensure that facets sharing vertices also share vertex shading normals when using PEXExtTMCoordSourceVertexNormal or to use PEXExtTMCoordSourceVertexCoord when possible.

Q.

What causes textures to become "squeezed" at unnatural locations on my object geometry?

A.

Spherical projections computed by the texture coordinate utilities PEXExtTMCoord* create known artifacts around the poles of their projection object. These poles lie along the +Y axis in world space (WC). If the natural axis of symmetry for an object (such as a vase) uses a different axis (such as the Z axis), then the orientation matrix in the parameterization data record should incorporate a rotation of 90 degrees to bring this axis in conjunction with the +Y axis of the projection object. This will reduce the apparent distortion by keeping the lines of symmetry aligned.

Standard Mapping

Q.

What operations affect the apparent position of a texture on the surface of a primitive?

A.

The apparent position of a texture on a surface occurs due to the location of texture coordinates within the 2D space of a standard texture map. Texture coordinates select regions of the texture to "pin" to the vertices of a facet. To alter the selected regions, several measures can be taken:

  • Texture coordinates can be "moved" during their creation by controlling the method of a surface parameterization. Both PEXExtTMProjectionSphereWC and PEXExtTMProjectionCylinderWC use orientation matrices in their parameterization, effectively transforming a texture coordinate before it is stored.

  • A TMCoordSrc LUT entry contains a unique transformation matrix which can scale, translate, or rotate texture coordinates within 2D texture space. Use of this feature can aid in exactly positioning texture coordinates over the interesting areas of a texture map.

  • Editing the contents of the target texture map to relocate, rescale, or otherwise alter the locations of interest with respect to the object's texture coordinates.

Environment Mapping

Q.

Under certain conditions, why do some of the facets of a surface fail to texture map when using PEXExtTMParamReflectSphereWC?

A.

The implementation of PEXExtTMParamReflectSphereWC under HP PEXlib detects a condition where a parameterized primitive may cross the natural seam of the texture (the seam of the WC sphere is at the +X axis). To correct this condition, try using the boundary clamp conditions PEXExtTMBoundaryCondWrap for both t0 and t1 to ensure correct continuity of the map across a seam.

Q.

What advantage does PEXExtTMParamReflectSphereWC offer over PEXExtTMParamReflectSphereVRC?

A.

If PEXExtTMParamReflectSphereWC is supported in your implementation, then reflections on a surface will change with respect to location of the view in world coordinates (WC). As an object or viewpoint changes position, so does the apparent reflection along its surface. This differs from PEXExtTMParamReflectSphereVRC, which computes reflections in eye coordinates (VRCs), a coordinate system which always keeps the reflected environment fixed behind the viewer. From a natural perspective, PEXExtTMParamReflectSphereWC behaves more like an enclosing environment as the eye position moves relative to the reflective surface. (HP PEXlib supports the functionality of PEXExtTMParamReflectSphereWC.)

Q.

How are chrome or metallic effects best simulated?

A.

Chrome and other highly reflective surfaces are only as interesting as the environments they are found in. In real-world situations, chrome objects are often photographed in special enclosures which include both light and dark regions. Texture maps to simulate this effect should include both light and dark regions of a map such as those found in sparsely lit rooms. Photographs or other image data can be converted specifically for this purpose. The quality of rendered reflection is also dependent upon the clarity of detail in a texture map. The sharper the detail contained in a map, the greater the impression of fine chrome there will be on a rendered model.

Performance

Q.

Under what conditions will my texture mapping performance be the best?

A.

Several steps can be taken to improve texture mapping throughput in the system:

  • Attempt to render all extended surface primitives using the same set of textures at the same time. Activating different textures on a per-primitive basis can be costly.

  • Minimize the mixture of surface primitives going to PEX. When the supported extended primitives for texture mapping (PEXExtFillAreaSetWithData, PEXExtSetOfFillAreaSets, PEXExtTriangleStrip, PEXExtQuadrilateralMesh), or the OCC versions of these primitives (PEXOCCFillArea, PEXOCCFillAreaSet, PEXOCCIndexedFillAreaSets, PEXOCCTriangleStrip, and PEXOCCQuadrilateralMesh) are mixed with other types of primitives, the overall cost to switch modes — texturing versus non-texturing — will increase.

  • A single active texture map will generally perform better than multiple active texture maps. The performance cost, however, varies with general size of the map, type of map, number of maps, and the complexity of the texture operations associated with each map.

  • Texture maps which use the "Int8" (byte) level organization save considerable memory resource on a given system. Larger maps, because of their dimension or the fact that they are comprised of "Float" data, will impact the operating system by increasing the application's use of swap space.

  • Pre-transforming texture coordinate data stored at a vertex and using identity orientation matrices for all TMCoordSrc LUT entries will reduce the amount of computation spent during texture mapping. Although these matrices help position a texture on the surface of an object, it is often possible to fix these texture coordinate values by pre-transforming them one time since they are not likely to change after their location can be tied down.

Visual Quality

Q.

My texture map has many fine details in it, some only one texel wide (such as lines). When I rotate the surface it is applied to, these lines tend to break up or flash. What can I do to correct this?

A.

Texture mapping is all about sampling theory. Essentially, the more discrete samples taken, the better the reconstruction of the original, continuous signal. The artifact you are experiencing is sampling "aliasing," the loss of reconstruction information. To reduce or eliminate visual artifacts, try the following:

  • Increase the size of your texture map. Since aliasing is based on a factor of screen pixel size to its coverage on the texture map, a greater size map with more information can often improve color sampling.

  • Use a MIP map with more than one level. MIP maps are precomputed sampling filters which try to account for aliasing during sampling. Use of a MIP map can often improve image quality during animation due to problems with sampling.

  • Use better sampling methods for your MIP map. PEXExtTMTexelSampleSingleBase uses only one sample and is prone to aliasing. PEXExtTMTexelSampleLinearBetweenMipmaps uses many samples and an neighbor interpolation filter to approximate colors, thus reducing the inaccuracy of single point sampling. (The only drawback to using more interpolation is a softening of sharp detail due to the blending used in the computation.)

Q.

Portions of my textured surface appear to be blotched with regions of blurred detail. What are they and how can I correct this?

A.

The artifact witnessed here occurs due to the design of the Mip Map anti-aliasing filter. As a renderer attempts to approximate an area of texels to sample in texture space, it selects different map levels to sample. The regions of blurred detail are visible transitions which are occurring due to the current sampling method. To reduce the visual impacts of these artifacts, several steps should be attempted:

  • Create your own MIP maps using better filters than those offered by PEXExtCreateFilteredTM and PEXExtCreateFilteredTMFromWindow. These utilities employ box- and linear filters to minify and scale incoming image data. Other image processing filters such as Gaussian can lead to improved images.

  • Increase the level of filtering. PEXExtTMTexelSampleLinearBetweenMipmaps provides the highest quality of visual control, however, it also requires the greatest amount of computation; this can reduce pipeline throughput.

  • Increase the size of the depth_sampling_bias_hint in the TMSampling LUT to greater than one to force sampling to occur in deeper maps away from the base map. The overall blurring of detail will increase, however it will appear more uniform. Decrease the size to improve sharpness.

  • Decrease the t*_frequency_hint in any of the t0 or t1 directions. Depending upon the level of detail in a map and its frequency, this bias will reduce the contribution of t0 or t1 gradient calculations such that the levels of Mip Map will change more rapidly based upon the contributing factor of the other's (t1 or t0) gradient. This hint, however, may not be implemented under all implementations or devices.

  • Reduce the level of high frequency detail in the original texture map. Areas of high change (gradient) reveal greater levels of visual artifacts when viewed on a textured surface.

  • Decrease the size of the primitives to which the texture will be applied. Sometimes the interaction between light shade interpolation and texture surface causes mach-bands or other artifacts to become more pronounced. Increasing the level of detail can sometimes improve the final visual outcome.

Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© 1996 Hewlett-Packard Development Company, L.P.