Docsity

Texture Mapping - Lecture Slides | CSE 167, Study notes of Computer Graphics

Partial preview of the text

Download Texture Mapping - Lecture Slides | CSE 167 and more Study notes Computer Graphics in PDF only on Docsity!

Texture Mapping

CSE167: Computer Graphics

Instructor: Steve Rotenberg

UCSD, Fall 2006

Texture Mapping^ „

Texture mapping is the process of mapping animage onto a triangle in order to increase thedetail of the rendering

This allows us to get fine scale details withoutresorting to rendering tons of tiny triangles

The image that gets mapped onto the triangle iscalled a

texture map

or

texture

and is usually a

regular color image

Texture Coordinates^ „

To render a textured triangle, we muststart by assigning a texture coordinate toeach vertex

„

A texture coordinate is a 2D point [

tx

t

] in y

texture space that is the coordinate of theimage that will get mapped to a particularvertex

Texture Mapping

v

v

v

t^2

t t^0

x

y

Texture Space

Triangle (in any space)

Texture Interpolation^ „

The actual texture mapping computations take place atthe scan conversion and pixel rendering stages of thegraphics pipeline „^

During scan conversion, as we are looping through thepixels of a triangle, we must interpolate the

tx

t y

texture

coordinates in a similar way to how we interpolate the rgb

color and

z

depth values

„^

As with all other interpolated values, we mustprecompute the slopes of each coordinate as they varyacross the image pixels in

x

and

y

„^

Once we have the interpolated texture coordinate, welook up that pixel in the texture map and use it to colorthe pixel

Perspective Correction^ „^

The scan conversion process usually uses linear interpolation to interpolatevalues across the triangle (colors, z, etc.) „^

If we use linear interpolation to interpolate the texture coordinates, we mayrun into inaccuracies „^

This is because a straight line of

regularly

spaced points in 3D space maps

to a straight line of

irregularly

spaced points in device space (if we are using

a perspective transformation) „^

The result is that the texture maps exactly onto the triangle at the vertices,but may warp and stretch within the triangle as the viewing angle changes „^

This is known as

texture swimming

and can be quite distracting on large

triangles „^

To fix the problem, we must perform a perspective correct interpolation, or hyperbolic

interpolation

„^

This requires interpolating the w coordinate across the triangle andperforming a perspective division for each pixel „^

See page 121 & 128 in the book for more info

Pixel Rendering^ „^

Let’s consider the scan conversion process once again and look at how thepixel rendering process fits in „^

Remember that in scan conversion of a triangle, we loop from the top rowdown to the bottom row in y, and then loop from left to right in x for eachrow „^

As we are looping over these pixels, we are incrementing variousinterpolated values (such as

z

,^ r

,^ g

,^ b

,^ t

, and x

ty

„^

Each of these increments requires only 1 addition per pixel, but perspectivecorrection requires 1 an additional divide per pixel and 1 additional multiplyper pixel for each perspective corrected value „^

Before actually writing the pixel, we compare the interpolated

z

value with

the value written into the zbuffer, stored per pixel. If it is further than theexisting z value, we don’t render the pixel and proceed to the next one. If itis closer, we finish rendering the pixel by writing the final color into theframebuffer and the new z value into the zbuffer „^

If we are doing expensive per-pixel operations (such as Phong interpolation& per-pixel lighting), we can postpone them until after we are sure that thepixel passes the zbuffer comparison. If we are doing a lot of expensive per-pixel rendering, it is therefore faster if we can render closer objects first

Tiling^ „

The image exists from (0,0) to (1,1) intexture space, but that doesn’t mean thattexture coordinates have to be limited tothat range

„

We can define various

tiling

or

wrapping

rules to determine what happens when wego outside of the 0…1 range

Clamping

x

y

(0,0)^ Texture Space

Mirroring

x

y

(0,0)^ Texture Space

Texture Space^ „

Let’s take a closer look at texture space „^

It’s not quite like the normalized image space or devicespaces we’ve seen so far „^

The image itself ranges from 0.0 to 1.0, independent ofthe actual pixel resolution „^

It allows tiling of values <0 and > „^

The individual pixels of the texture are called

texels

„^

Each texel maps to a uniform sized box in texture space.For example, a 4x4 texture would have pixel centers at1/8, 3/8, 5/8, and 7/

Magnification^ „

What happens when we get too close to thetextured surface, so that we can see theindividual texels up close?

This is called

magnification

We can define various magnification behaviorssuch as:

„^

Point sampling „^

Bilinear sampling „^

Bicubic sampling

Minification^ „^

Minification

is the opposite of magnification and refers to how we handle the

texture when we view it from far away „^

Ideally, we would see textures from such a distance as to cause each texelto map to roughly one pixel „^

If this were the case, we would never have to worry about magnification andminification „^

However, this is not a realistic case, as we usually have cameras movingthroughout an environment constantly getting nearer and farther fromdifferent objects „^

When we view a texture from too close, a single texel maps to many pixels.There are several popular magnification rules to address this „^

When we are far away, a many texels may map to a single pixel.Minification addresses this issue „^

Also, when we view flat surfaces from a more edge on point of view, we getsituations where texels map to pixels in a very stretched way. This case isoften handled in a similar way to minification, but there are otheralternatives

Minification^ „^

Why is it necessary to have special handling for minification?

„^

What happens if we just take our per-pixel texture coordinate anduse it to look up the texture at a single texel?

„^

Just like magnification, we can use a simple

point sampling

rule for

minification

„^

However, this can lead to a common texture problem known as shimmering

or

buzzing

which is a form of

aliasing

„^

Consider a detailed texture map with lots of different colors that isonly being sampled at a single point per pixel

„^

If some region of this maps to single pixel, the sample point couldend up anywhere in that region. If the region has large colorvariations, this may cause the pixel to change color significantlyeven if the triangle only moves a minute amount. The result of this isa flickering/shimmering/buzzing effect

„^

To fix this problem, we must use some sort of minification technique