Texture Mapping - Introduction to Computer Graphics - Lecture Slides, Slides of Computer Graphics

In Introduction to Computer Graphics course we study the basic concept of the principle of computer architecture. In these lecture slides the key points are:Texture Mapping, Implementation Details, Surface Mapping, Bump Mapping, Displacement Mapping, Bi-Cubic Interpolation, Geometric Coordinates, Pixel and Texel Relations, Controlling Filtering, Texture Sampling

Typology: Slides

2012/2013

Uploaded on 04/23/2013

sarasvan
sarasvan 🇮🇳

4.4

(20)

118 documents

1 / 42

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Texture Mapping
OpenGl and Implementation Details
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a

Partial preview of the text

Download Texture Mapping - Introduction to Computer Graphics - Lecture Slides and more Slides Computer Graphics in PDF only on Docsity!

Texture Mapping

OpenGl and Implementation Details

Surface mapping

• Texture mapping

• Bump Mapping

• Displacement mapping

– Actually moving geometry

– ie Create screw from cylinder, Terrain, etc

An Overview

  • Steps in Texture Mapping
    1. Specify the texture. (R, G, B, A, mipmapping)
    2. Indicate how the texture is to be applied to each pixel. (decal, modulate, blend)
    3. Enable texture mapping via glEnable(..) GL_TEXTURE_1D or GL_TEXTURE_2D
    4. Draw the scene, supplying both texture and geometric coordinates.

What does a pixel see?

Controlling Filtering

Texture Sampling

• Sinc(x) is not feasible in real time

• Box filter

(nearest-neighbor)

is poor quality

Interpolation

• Texture coordinate (pu, pv) in [0,1]

• Texture images size n*m texels

• Nearest neighbor would access:

(floor(nu), floor(mv))

• Interpolate 1D in x and y

Bilinear Interpolation

• Let t(u,v) access texture map

b(u,v) = filtered texel

(u’, v’) = (pu - floor(pu), pv - floor(pv))

b(pu, pv) = (1 - u’) (1-v’) t(xl,yb) +

u’ (1-v’) t(xr, yb) + (1-u’) v’ t(xl, yt) +

u’ v’ t(xr,yt)

Repeat, Mirror, Clamp, Border

Repeating and Clamping Textures

  • You can assign texture coordinates outside the range [0,1] and have them either clamp or repeat.
  • With repeating textures, if you have a large plane with texture coordinates running from 0.0 to 10.0 in both directions, for example, you’ll get 100 copies of the texture tiled together on the screen.
  • For most applications where the texture is to be repeated, the texels at the top of the texture should match those at the bottom, and similarly for the left and right edges.
  • To clamp the texture coordinates: Any values greater than 1.0 are set to 1.0, and any values less than 0.0 are set to 0.0. Clamping is useful for applications where you want a single copy of the texture to appear on a large surface.
  • If the surface-texture coordinates range from 0.0 to 10.0 in both directions, one copy of the texture appears in the lower corner of the surface. The rest of the surface is painted with the texture’s border colors as needed.

glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_S_WRAP GL_REPEAT);

glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_T_WRAP GL_REPEAT);

or

glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_S_WRAP GL_CLAMP);

glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_T_WRAP GL_CLAMP);

You can also clamp in one direction and repeat in the other.

How to apply texturing

• Modulate

– Multiply texture with lighting

• Replace

– Just use texture color

• Add, sub, etc

– On newer hardware

Assigning Texture Coordinates

  • Texture coordinates can comprise one, two, three, or four coordinates. They’re usually referred to as the s, t, r, and q coordinates.
  • For one-dimensional textures, you use the s coordinate; for two-dimensional textures, you use s and t.
  • The q, like w, is typically given the value 1 and can be used to create homogeneous coordinates
  • The command to specify texture coordinates, glTexCoord(), is similar to glVertex(), glColor(), and glNormal(). Usually, texture-coordinate values range between 0 and 1; values can be assigned outside this range, however, with the results described in “ Repeating and Clamping Textures .”

void glTexCoord{1234}{sifd}{v}(TYPEcoords);

Computing Approximate Texture Coordinates

  • Polygon aspect ratio 3/2 (w/h); texture aspect ration 1. To avoid distorting the texture: use texture coordinates of (0,0), (1,0), (1,2/3), (0,2/3)
  • A can with label 4 units tall and 12 units around (aspect ratio 3/1). Textures must have aspect ratio of 2n^ to 1. We can copy and paste it twice to make an aspect ration of 1. Let’s approximate the can by 30 (412/30) polygons. We* can use the following texture coordinates: - (0,0), (1/30,0), (1/30,1/3),(0,1/3) - (1/30,0), (2/30,0), (2/30,1/3),(1/30,1/3) - - (29/30,0), (1,0), (1,1/3),(29/30,1/3)
  • Only a few curved surfaces (cone and cylinders) can be mapped to a flat surface without geodesic distortion. For example, a sphere (cos q cos f ,cos q sin f ,sin q ). The q - f rectangle can be mapped directly to a rectangular texture map, but the closer you get to the poles, the more distorted the texture.