Docsity

Texture Mapping: Pixel-Texel Relations, Filtering, Interpolation, and Texturing, Slides of Advanced Computer Programming

Partial preview of the text

Download Texture Mapping: Pixel-Texel Relations, Filtering, Interpolation, and Texturing and more Slides Advanced Computer Programming in PDF only on Docsity!

Texture Mapping

OpenGl and Implementation Details

Docsity.com

Surface mapping

• Texture mapping

• Bump Mapping

• Displacement mapping

– Actually moving geometry

– ie Create screw from cylinder, Terrain, etc

Docsity.com

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.

From Jim X. Chen, [email protected] Docsity.com

What does a pixel see?

From Tomas Akenine-Moller Docsity.com

Controlling Filtering

Docsity.com

Texture Sampling

• Sinc(x) is not feasible in real time

• Box filter

(nearest-neighbor)

is poor quality

From Tomas Akenine-Moller Docsity.com

Interpolation

• Texture coordinate (p u, p v) in [0,1]

• Texture images size n*m texels

• Nearest neighbor would access:

(floor(nu), floor(mv))

• Interpolate 1D in x and y

From Tomas Akenine-Moller Docsity.com

Bilinear Interpolation

• Let t(u,v) access texture map

b(u,v) = filtered texel

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

b(p u , p v) = (1 - u’) (1-v’) t(x l,y b) +

u’ (1-v’) t(x r , y b) + (1-u’) v’ t(x l, y t) +

u’ v’ t(x r ,y t)

From Tomas Akenine-Moller Docsity.com

From Tomas Akenine-Moller

Repeat, Mirror, Clamp, Border

Docsity.com

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.

From Jim X. Chen, [email protected] Docsity.com

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.

From Jim X. Chen, [email protected] Docsity.com

How to apply texturing

• Modulate

– Multiply texture with lighting

• Replace

– Just use texture color

• Add, sub, etc

– On newer hardware

Docsity.com

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);

From Jim X. Chen, [email protected] Docsity.com

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 θ cos φ ,cos θ sin φ ,sin θ ). The θ - φ rectangle can be mapped directly to a rectangular texture map, but the closer you get to the poles, the more distorted the texture.

From Jim X. Chen, [email protected] Docsity.com