Dr. Ayman Eldeib · 2020. 3. 21. · Dr. Ayman Eldeib Systems & Biomedical Engineering Department...

16
3/21/2020 1 SBE 306B - Computer Systems III Texture Mapping Dr. Ayman Eldeib Systems & Biomedical Engineering Department Spring 2020 Computer Graphics Texture Mapping Texture Mapping geometry image x y z screen

Transcript of Dr. Ayman Eldeib · 2020. 3. 21. · Dr. Ayman Eldeib Systems & Biomedical Engineering Department...

  • 3/21/2020

    1

    SBE 306B - Computer Systems III

    Texture Mapping

    Dr. Ayman Eldeib

    Systems & Biomedical Engineering Department

    Spring 2020

    Computer Graphics Texture Mapping

    Texture Mapping

    geometry

    image

    x

    y

    z screen

  • 3/21/2020

    2

    Computer Graphics Texture Mapping

    Why Texture Mapping?

    Scenes created with diffuse lighting look convincingly three-dimensional, but are flat, chalky, and “cartoonish”

    Phong lighting lets us simulate materials like plastic and (to a lesser extent) metal, but scenes still seem very cartoonish and unreal

    Big problem: polygons are too coarse-grained to usefully model fine surface detail

    Solution: texture mapping

    Computer Graphics Texture Mapping

    Adding surface detail helps keep CG images from looking so simple

    Explicitly modeling this detail in geometry can be very expensive

    Zebra stripes, wood grain, writing on a whiteboard

    Texture mapping pastes images onto the surfaces in the scene, adding realistic fine detail without exploding the geometry

    Cont.Why Texture Mapping?

  • 3/21/2020

    3

    Computer Graphics Texture Mapping

    Texture Mapping and OpenGL Pipeline

    Images and geometry flow through separate pipelines that join at the rasterizer

    “complex” textures do not affect geometric complexity

    vertices geometry pipeline

    image pixel pipeline

    Rasterizer(screen)

    vertices

    image

    Computer Graphics Texture Mapping

    Texture Mapping

    Map variations in 2D image to 3D object

    3D object 2D image

  • 3/21/2020

    4

    Computer Graphics Texture Mapping

    Adds Visual Detail

    Texture MappingCont.

    Computer Graphics Texture Mapping

    Spring 2011 Computer GraphicsTexture Mapping

    Bump Mapping

    Texture = change in surface normal!

    Sphere w/ diffuse textureSwirly bump map

    Sphere w/ diffuse texture

    and swirly bump map

    Texture MappingCont.

  • 3/21/2020

    5

    Computer Graphics Texture Mapping

    Displacement Mapping

    Cont.

    Texture Mapping

    Computer Graphics Texture Mapping

    In short: it is impractical to explicitly model fine surface detail with geometry

    Solution: use images to capture the “texture” of surfaces

    Texture maps can modulate many factors that affect the rendering of a surface such as:

    Color or reflectance (diffuse, ambient, specular)

    Transparency (smoke effects)

    Cont.

    Texture Mapping

  • 3/21/2020

    6

    Computer Graphics Texture Mapping

    Texture Mapping Polygonal Models

    To each vertex (x,y,z in object coordinates), must associate 2D texture coordinates (u,v)

    So texture fits “nicely” over object

    Computer Graphics Texture Mapping

    geometry

    + =

    image texture map

    Texture Mapping

  • 3/21/2020

    7

    Computer Graphics Texture Mapping

    Texture Mapping Option:

    Varieties of Projections

    Computer Graphics Texture Mapping

    Map Shape

    Map shapes correspond to various projections

    Planar, Cylindrical, Spherical

    First, map (square) texture to basic map shape

    Then, map basic map shape to object

    Or vice versa: Object to map shape, map shape to

    square

    Usually, this is straightforward

    Maps from square to cylinder, plane, sphere well

    defined

    Maps from object to these are simply spherical,

    cylindrical, cartesian coordinate systems

  • 3/21/2020

    8

    Computer Graphics Texture Mapping

    Planar Mapping

    Drop z coord (u,v) = (x,y)

    Computer Graphics Texture Mapping

    Cylindrical Mapping

  • 3/21/2020

    9

    Computer Graphics Texture Mapping

    Spherical Mapping

    Computer Graphics Texture Mapping

    Cube Mapping

  • 3/21/2020

    10

    Computer Graphics Texture Mapping

    Cube Mapping Cont.

    Computer Graphics Texture Mapping

    When scan converting a polygon (triangle) must map

    each pixel to texture image

    In reality, each pixel in raster image does not map to a

    pixel in texture image

    Actually, each pixel maps to a region in texture - Scale

    |PIX| < |TEX|

    oEasy: interpolate (bilinear) between texel values

    |PIX| > |TEX|

    oHard: average the contribution from multiple texels

    |PIX| ~ |TEX|

    oStill need interpolation!

    Interpolation of Texture Coordinates

  • 3/21/2020

    11

    Computer Graphics Texture Mapping

    Interpolation

    Geometrically correct interpolation

    Nearest neighbor

    Bilinear

    Bicubic

    Scale

    interpolate

    Interpolation of Texture Coordinates Cont.

    Computer Graphics Texture Mapping

    Texture Mapping

    Interpolation methods

    Geometrically correct interpolation

    o Must interpolate in world space not screen space

    Nearest neighbor

    o Take value of nearest pixel

    Bilinear

    o Linearly average four nearest pixels based on distance

    Bicubic

    o Weighted average of surrounding pixels

  • 3/21/2020

    12

    Computer Graphics Texture Mapping

    Texture Mapping Fundamentals

    A texture is typically a 2-D image

    Image elements are called texels

    A texture is typically a 2-D array of texels

    Value stored at a texel affects surface appearance in

    some way

    The mapping of the texture to the surface determines

    the correspondence, i.e., how the texture lies on the

    surface

    o Mapping a texture to a triangle is easy.

    o Mapping a texture to an arbitrary 3-D shape is more

    complicated.

    Computer Graphics Texture Mapping

    Texture Mapping Rendering

    Rendering uses the mapping:

    Find the visible surface at a pixel

    Find the point on that surface corresponding to that

    pixel

    Find the point in the texture corresponding to that

    point on the surface

    Use the parameters associated with that point on the

    texture to shade the pixel

    Using triangulated meshes reduces the problem to

    mapping a portion of the image to each triangle

  • 3/21/2020

    13

    Computer Graphics Texture Mapping

    We typically parameterize the texture as a function in (u, v)

    For simplicity, normalize u & v

    Associate each triangle with a texture

    Give each vertex of the triangle a texture coordinate (u, v)

    For other points on the triangle, interpolate texture

    coordinate from the vertices

    Much like interpolating color or depth

    Cont.Texture Mapping Rendering

    Computer Graphics Texture Mapping

    MIP-maps

    For a texture of 2n x 2n pixels, compute n-1 textures,

    each at ½ the resolution of previous

    This multiresolution texture is called a MIP-map

    Original Texture Lower Resolution Versions

  • 3/21/2020

    14

    Computer Graphics Texture Mapping

    Keep textures pre-filtered at multiple resolutions

    For each pixel, linearly interpolate between

    two closest levels

    Fast, easy for hardware

    MIP-maps

    Computer Graphics Texture Mapping

    User Generated Mappings

    For complex 3-D objects, mapping textures is still something of an art…so we often let the user do it

  • 3/21/2020

    15

    Computer Graphics Texture Mapping

    Applying Texture using OpenGL

    specify texture

    read or generate image

    assign to texture

    assign texture coordinates to vertices

    specify texture parameters

    wrapping, filtering

    Three Steps

    Computer Graphics Texture Mapping

    Specify Texture Image

    Define a texture image from an array of texels in CPU memory

    dimensions of image must be powers of 2

    glTexImage2D( target, level, components, w, h, border, format, type, *texels );

    glTexCoord*() specified at each vertex

    Texel colors are processed by pixel pipeline

  • 3/21/2020

    16

    Computer Graphics Texture Mapping

    Texture Application Methods Filter Modes

    minification or magnification

    special mipmap minification filters

    Wrap Modes

    clamping or repeating

    e.g. glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT )

    Texture Functions

    how to mix primitive’s color with texture’s color

    blend, modulate or replace texelsglTexEnv{fi}[v]( GL_TEXTURE_ENV, prop, param )GL_TEXTURE_ENV_MODE modes: GL_MODULATE, GL_BLEND, GL_REPLACE

    g{tÇ~ lÉâ g{tÇ~ lÉâ g{tÇ~ lÉâ g{tÇ~ lÉâ