Computer Graphics Texture Mapping CO2409 Computer Graphics Week 13.

Click here to load reader

  • date post

    29-Dec-2015
  • Category

    Documents

  • view

    222
  • download

    5

Embed Size (px)

Transcript of Computer Graphics Texture Mapping CO2409 Computer Graphics Week 13.

  • Computer GraphicsTexture MappingCO2409 Computer GraphicsWeek 13

  • Lecture ContentsTexturesTexture CoordinatesTexture Addressing ModesTexture FilteringMip-Mapping

  • TexturesWe can vastly improve on simple coloured and lit models by using texturesSometimes called texture maps or more simply mapsTextures are rather like a wallpaper, shrink-wrapped around the model geometryA texture is simply a bitmap held off-screenTypically loaded from standard bitmap file formatsEach pixel in the bitmap appears as a square on the geometry called a texelTexture resolution usually high enough so that we dont notice the texels

  • 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.0Measured on U & V axesWritten (U,V) and hence very often referred to as UVsThe vertex UVs define exactly how the texture maps onto the geometryThis is Texture MappingNeed to define exactly how a texture is wrapped around the geometryWhich part of the texture is attached to each vertex

  • Defining Texture MappingSo (1, 0) defines the top-right(0, 1) the bottom-left(0.5, 0.5) the centreSee diagram on last slide

    The UV for each vertex specifies which part of the texture is on that vertexChoosing a texture pixel for a given UV is sampling the textureUVs are interpolated across the polygon surface to define how the texture is appliedThe UV coordinate (0, 0) specifies the top-left of the texture bitmap, (1,1) specifies the bottom-rightThis polygon is mapped with the yellow square on the last slide

  • Artist UV Mapping Tool

  • Texture Addressing ModesUVs do not have to be in the range 0.0 to 1.0The 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 VClamp: 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 coloursDiagrams on next slide

  • Addressing Modes ExamplesWrap addressing mode repeats the texture over for large UV rangesUseful 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 textureCan be used to reduce bleeding problems at the edges of geometryBorder addressing is similarWrapMirrorClampBorder

  • Texture FilteringIf we zoom in on a textured polygon each texel will cover a small, but noticeable areaIf 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 pixelCould cause aliasing shown in a later slideSo when sampling, we blend texels to smooth out these effects

    Called Texture FilteringMagnification: zoom inMinification: zoom outTexels Visible as Squares

  • Texture Filtering ModesChoose a filtering mode for both texture minification & magnification:Can be different

    Point SamplingNo filtering, sample nearest texelBilinear FilteringSampled colour is a linear blend of the nearest four texelsCalled bilinear because it blends neighbour texels in X & Y directionAnisotropic FilteringAn advanced blending modeConsiders polygon angle to the cameraImproves the clarity of polygons going into the distance especiallyPoint SampledBilinearBilinear Sampling

  • Mip-MappingWhen a texture is drawn far away, it will use the minification filterHowever, the available runtime filters are poor when considerable scaling down is requiredCertain textures will likely exhibit unpleasant aliasing effectsAliasing is when the resolution is not sufficient to display fine detailE.g. strobing on regular patternsor noise effects on naturalistic detail

    Reduce problem by pre-creating smaller versions of the texture to use when it is far awayThis is called mip-mappingNoMip-MapsWithMip-Maps

  • Mip-Map CreationA mip-map is a smaller version of a texture created using a high-quality resizing algorithmDone in advance, not during scene rendering

    A sequence of mip-maps is created, each 50% smaller than the one beforeMaking 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 usedThis minimises aliasing effects[It is also faster: more likely to sequentially sample neighbouring texels with correct sized texture, which is more cache-efficient]

  • Tri-linear FilteringWhen a polygon moves toward or away from the viewer, the change in mip-map choice can be seenA 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-mapsInstead of just choosing the nearest oneCombined with bilinear filtering within each texture, this gives trilinear filtering

    Blends the mip-map dividing lineThere is an anisotropic equivalent tooBilinearTrilinear

  • Comparison

  • High Resolution Comparison

  • Texture BlendingUse blending modesLike the earlier sprite labWe may need to provide multiple sets of UVs, one for each textureA 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 textureShadows on a textureMerging textures (above)Normal mapping - upcoming lab