computer graphics texture mapping co2409 computer graphics week 13

16
Computer Graphics Texture Mapping CO2409 Computer Graphics Week 13

Upload: cori-lester

Post on 29-Dec-2015

237 views

Category:

Documents


5 download

TRANSCRIPT

Page 1: Computer Graphics Texture Mapping CO2409 Computer Graphics Week 13

Computer GraphicsTexture Mapping

CO2409 Computer Graphics

Week 13

Page 2: Computer Graphics Texture Mapping CO2409 Computer Graphics Week 13

Lecture ContentsLecture Contents

1. Textures

2. Texture Coordinates

3. Texture Addressing Modes

4. Texture Filtering

5. Mip-Mapping

Page 3: Computer Graphics Texture Mapping CO2409 Computer Graphics Week 13

TexturesTextures

• We can vastly improve on simple coloured and lit models by using textures– Sometimes called texture maps or more simply maps

• Textures are rather like a wallpaper, shrink-wrapped around the model geometry

• A texture is simply a bitmap held off-screen– Typically loaded from standard

bitmap file formats

• Each pixel in the bitmap appears as a square on the geometry called a texel– Texture resolution usually high

enough so that we don’t notice the texels

Page 4: Computer Graphics Texture Mapping CO2409 Computer Graphics Week 13

Texture Coordinates (UVs)Texture Coordinates (UVs)

• So each vertex in the geometry is assigned a texture coordinate:– A texture coordinate is a pair of (float)

values usually from 0.0 to 1.0– Measured on U & V axes– Written (U,V) and hence very often

referred to as UVs

• The vertex UVs define exactly how the texture maps onto the geometry– This is Texture Mapping

• Need to define exactly how a texture is wrapped around the geometry– Which part of the texture is attached to each vertex

Page 5: Computer Graphics Texture Mapping CO2409 Computer Graphics Week 13

Defining Texture MappingDefining Texture Mapping

– So (1, 0) defines the top-right– (0, 1) the bottom-left– (0.5, 0.5) the centre– See diagram on last slide

• The UV for each vertex specifies which part of the texture is on that vertex– Choosing a texture pixel for a

given UV is sampling the texture

• UVs are interpolated across the polygon surface to define how the texture is applied

• The UV coordinate (0, 0) specifies the top-left of the texture bitmap, (1,1) specifies the bottom-right

This polygon is mapped with the yellow square on the last slide

Page 6: Computer Graphics Texture Mapping CO2409 Computer Graphics Week 13

Artist UV Mapping ToolArtist UV Mapping Tool

Page 7: Computer Graphics Texture Mapping CO2409 Computer Graphics Week 13

Texture Addressing ModesTexture Addressing Modes

• UVs do not have to be in the range 0.0 to 1.0• The texture position represented by UVs outside this range

depends on the texture addressing mode:

– (Note this is DirectX terminology)

– Wrap: Use only the fractional part of the UVs (e.g. U=2.7 means U=0.7). This is the usual mode.

– Mirror: Similar to wrap mode, but the texture is mirrored for odd U and V

– Clamp: UVs are clamped to the nearest valid value (U=2.7 means U=1, V=–2.3 means V=0)

– Border: UVs out of range return a fixed colour regardless of the texture colours

– Diagrams on next slide…

Page 8: Computer Graphics Texture Mapping CO2409 Computer Graphics Week 13

Addressing Modes ExamplesAddressing Modes Examples

• Wrap addressing mode repeats the texture over for large UV ranges– Useful for mapping a large polygon with a

repeated texture (e.g. a tiled wall)

• Mirror addressing looks similar but the texture alternately mirrors

• Clamp addressing ensures we see only one texture– Can be used to reduce bleeding problems

at the edges of geometry

• Border addressing is similar

Wrap

Mirror

Clamp Border

Page 9: Computer Graphics Texture Mapping CO2409 Computer Graphics Week 13

Texture FilteringTexture Filtering

• If we zoom in on a textured polygon each texel will cover a small, but noticeable area– If all pixels in a texel the same colour we see small small quads:

• If we zoom out, will be a choice of several texels within a single pixel– Could cause aliasing shown

in a later slide

• So when sampling, we blend texels to smooth out these effects

• Called Texture Filtering– Magnification: zoom in– Minification: zoom out

Texels Visible as Squares

Page 10: Computer Graphics Texture Mapping CO2409 Computer Graphics Week 13

Texture Filtering ModesTexture Filtering Modes

• Choose a filtering mode for both texture minification & magnification:– Can be different

• Point Sampling– No filtering, sample nearest texel

• Bilinear Filtering– Sampled colour is a linear blend of the

nearest four texels– Called bilinear because it blends neighbour

texels in X & Y direction

• Anisotropic Filtering– An advanced blending mode– Considers polygon angle to the camera– Improves the clarity of polygons going into

the distance especially

Point Sampled Bilinear

Bilinear Sampling

Page 11: Computer Graphics Texture Mapping CO2409 Computer Graphics Week 13

Mip-MappingMip-Mapping

• When a texture is drawn far away, it will use the minification filter– However, the available runtime filters are poor when

considerable scaling down is required

• Certain textures will likely exhibit unpleasant aliasing effects– Aliasing is when the resolution is not

sufficient to display fine detail– E.g. “strobing” on regular patterns– or noise effects on naturalistic detail

• Reduce problem by pre-creating smaller versions of the texture to use when it is far away

• This is called mip-mapping

NoMip-Maps

WithMip-Maps

Page 12: Computer Graphics Texture Mapping CO2409 Computer Graphics Week 13

Mip-Map CreationMip-Map Creation

• A mip-map is a smaller version of a texture created using a high-quality resizing algorithm– Done in advance, not during scene rendering

• A sequence of mip-maps is created, each 50% smaller than the one before– Making mip-map chain from original texture

potentially down to a 1x1 pixel version

• When rendering a texture, the mip-map closest to the polygon size is used– This minimises aliasing effects– [It is also faster: more likely to sequentially

sample neighbouring texels with correct sized texture, which is more cache-efficient]

Page 13: Computer Graphics Texture Mapping CO2409 Computer Graphics Week 13

Tri-linear FilteringTri-linear Filtering

• When a polygon moves toward or away from the viewer, the change in mip-map choice can be seen– A clear visual dividing line between mip-maps

(hard to show on static diagram – see lab)

• To remove this we can linearly blend the nearest two mip-maps– Instead of just choosing the nearest one

• Combined with bilinear filtering within each texture, this gives trilinear filtering

• Blends the mip-map dividing line• There is an anisotropic equivalent too

Bilinear

Trilinear

Page 14: Computer Graphics Texture Mapping CO2409 Computer Graphics Week 13

ComparisonComparison

Page 15: Computer Graphics Texture Mapping CO2409 Computer Graphics Week 13

High Resolution ComparisonHigh Resolution Comparison

Page 16: Computer Graphics Texture Mapping CO2409 Computer Graphics Week 13

Texture BlendingTexture Blending

• Use blending modes– Like the earlier sprite lab

• We may need to provide multiple sets of UVs, one for each texture

• A polygon can have more than one texture applied • Can blend several textures on top of each other to create a

composite texture

• Possible uses:– Reflections on a texture– Shadows on a texture– Merging textures (above)– Normal mapping - upcoming lab