DOC PREVIEW
UNC-Chapel Hill COMP 770 - LECTURE NOTES

This preview shows page 1-2-3 out of 9 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Texture Mapping Texture Mapping ––Part 2Part 2Lecture 16Comp 236Spring 2005 Texture Aliasing MIPmaps Summed Area Tables Projective Textures Environment Maps Bump Maps Displacement Maps Solid Textures3/21/2005 Lecture 17 2Review of LabelTextures• Increases the apparent complexity of simple geometry • Must specify texture coordinates for each vertex • Projective correction (can’t linearly interpolate in screen space) • Specify variations in shading within a primitive3/21/2005 Lecture 17 3Sampling Texture Maps• When texture mapping it is rare that the screen-space sampling density matches the sampling density of the texture. Typically one of two things can occur: Oversampling of the texture or Undersampling of the texture• In the case of oversampling we already know what to do... interpolation. But, how do we handle undersampling? 3/21/2005 Lecture 17 4How Bad Does it Look?• Let’s take a look at what oversampling looks like: • Notice how details in the texture, in particular the mortar between the bricks, tend to pop (disappear and reappear). This popping is most noticeable around details (parts of the texture with a high-spatial frequency). This is indicative of aliasing (high-frequency details showing up in areas where we expect to see low frequencies).3/21/2005 Lecture 17 5Spatial Filtering• In order to get the sort of images the we expect, we must prefilterthe texture to remove the high frequencies that show up as artifacts in the final rendering. The prefiltering required in the undersampling case is basically a spatial integration over the extent of the sample. We could perform this filtering while texture mapping (during rasterization), by keeping track of the area enclosed by sequential samples and performing the integration as required. However, this would be expensive. The most common solution to undersampling is to perform prefiltering prior to rendering. 3/21/2005 Lecture 17 6MIP Mapping• MIP Mapping is one popular technique for precomputing and performing this prefiltering. MIP is an acronym for the Latin phrase multium in parvo, which means "many in a small place". The technique was first described by Lance Williams. The basic idea is to construct a pyramid of imagesthat are prefiltered and resampled at sampling frequencies that are a binary fractions (1/2, 1/4, 1/8, etc) of the original image’s sampling. • While rasterizing we compute theindex of the decimated image thatis sampled at a rate closest to thedensity of our desired sampling rate(rather than picking the closest one can in also interpolate between pyramid levels). Computing this series of filtered images requires only a small fraction of additional storage over theoriginal texture (How small of a fraction?). 3/21/2005 Lecture 17 7Storing MIP Maps• One convienent method of storing a MIP map is shown below (It also nicely illustrates the 1/3 overhead of maintaining the MIP map). • The rasterizer must be modified to compute the MIP map level. Remember the equations that we derived last lecture for mapping screen-space interpolants to their 3-space equivalent. 3/21/2005 Lecture 17 8Finding the MIP level• What we’d like to find is the step size that a uniform step in screen-space causes in three-space, or, in other words how a screen-space change relates to a 3-space change. This sounds like the derivatives, ( du/dt, dv/dt ). They can be computed simply using the chain rule:• Notice that the term being squared under the numerator is just the wplane equation that we are already computing. The remaining terms are constant for a given rasterization. Thus, all we need to do to compute the derivative is a square the waccumulator and multiply it by a couple of constants. • Now, we know how a step in screen-space relates to a step in 3-space. So how do we translate this to an index into our MIP table?3/21/2005 Lecture 17 9MIP Indices• Actually, you have a choice of ways to translate this gradient value into a MIP level. This also brings up one of the shortcomings of MIP mapping. MIP mapping assumes that both the uand vcomponents of the texture index undergo uniform scalings, while in fact the terms du/dtand dv/dtare relatively independent. Thus, we must make some sort of compromise. Two of the most common approaches are given below: The differences between these level selection methods isillustrated in the accompanying figure. 3/21/2005 Lecture 17 10OpenGL Code ExampleIncorporating MIPmapping into OpenGL applications is surprisingly easy.The gluBuildMipmaps() utility routine will automatically construct a mipmap from a given texture buffer. It will filter the texture using a simple box filter and then subsample it by a factor of 2 in each dimension. It repeats this process until one of the texture’s dimensions is 1. Each texture ID, can have multiple levels associated with it. GL_LINEAR_MIPMAP_LINEAR trilinearlyinterploates between texture indices and MIPmap levels. Other options include GL_NEAREST_MIPMAP_NEAREST, GL_NEAREST_MIPMAP_LINEAR, and GL_LINEAR_MIPMAP_NEAREST.// Boilerplate Texture setup codeglTexImage2D(GL_TEXTURE_2D, 0, 4, texWidth, texHeight, 0, GL_RGBA,GL_UNSIGNED_BYTE, data)glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT)glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT)glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL)OpenGL also provides a facility for specifying the MIPmap image at each level using multiple calls to the glTexImage*D() function. This approach provides more control over filtering in the MIPmap construction and enables a wide range of tricks. gluBuild2DMipmaps(GL_TEXTURE_2D, 4, texWidth, texHeight, GL_RGBA, GL_UNSIGNED_BYTE, data)GL_LINEAR_MIPMAP_LINEAR3/21/2005 Lecture 17 11Summed-Area TablesThere are other approaches to computing this prefiltering integration on the fly. One, which was introduced by Frank Crow is called a summed-area table. Basically, a summed-area table is a tabularized two-dimensional cumulative distribution function. Imagine having a 2-D table of numbers the cumulative distribution function could befound as shown below. • To find the sum of region contained in a box bounded by (x0, y0)and (x1, y1):T(x1, y1)-T(x0, y1)-T(x1, y0)+ T(x0, y0)• This approach can be used to compute the integration of pixels that lie under a pixel by dividing


View Full Document

UNC-Chapel Hill COMP 770 - LECTURE NOTES

Download LECTURE NOTES
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view LECTURE NOTES and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view LECTURE NOTES 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?