1 / 19

CS 3388: Texture Mapping

CS 3388: Texture Mapping. [Hill § 8.5]. Enemy Territory: Quake Wars . Per-vertex colour not enough. In real objects, large changes to shape less frequent than large changes in colour. colour change: red vs white. shape change: almost flat!.

tacy
Download Presentation

CS 3388: Texture Mapping

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS 3388: Texture Mapping [Hill §8.5] Enemy Territory: Quake Wars

  2. Per-vertex colour not enough... • In real objects, large changes to shape less frequent than large changes in colour colour change: red vs white shape change: almost flat! Do we build this wall out of 1,000 vertices of different colours? Or ... only 4 vertices + “brick texture”!

  3. Texture Mapping • Instead of interpolating solid colour... • Interpolate (x,y) location in bitmap and then sample current(x,y)to get colour! thousands of vertices dozens of vertices + texture vs.

  4. Bitmap + Mapping = Texture Mapping! texture (bitmap) texture coordinates (per-vertex) + = texture mapped mesh very few vertices very complex colour!

  5. Re-use Vertices with New Texture! texture 1 texture 2 mesh 1 mesh 2

  6. Texture Coordinates (texcoords) 3D positions 2D texcoords • Each vertex has position (x,y,z) in space and position (u,v) in texture • Colour at (x,y,z)is texture[u,v] (u0,v0) (x0,y0,z0) (x2,y2,z2) (x1,y1,z1) (u1,v1) (u2,v2) sample the texture at (u,v)

  7. Texture Coordinates (texcoords) 3D positions 2D texcoords • Texture coordinates t= (u,v)2 [0,1]2 • note textbook/opengl call them (s,t), but in general this is called “u-v mapping” in 3D modeling software, so we call them (u,v) t0 = (0,0) p0 p2 t1= (0,1) p1 t2= (1,1)

  8. Texture Coordinates (texcoords) 3D positions 2D texcoords • Given p on triangle what’s corresponding t? • If (®,¯,°)is barycentriccoord of p, coord then (®,¯,°) is alsobarycentriccoord of t! t0 = (0,0) p0 p t p2 t1= (0,1) p1 t2= (1,1)

  9. [Hill §8.5.2] Perspective Correction • The (®,¯,°)must be barycentriccoord of the 3D point, not 2D screen coordinate! • All modern hardware supports perspective correct texture mapping interpolate (u,v) based on 2Dscreen coords interpolate (u,v)based on 3D eye coords halfway mark in ... screen coords 3D coords linear non-linear

  10. OpenGL Texture Mapping (pre-3.0) • See texture_demo.cpp documentation

  11. Texture Sampling (“Filtering”) Texture pixel = “texel” Q: what should colour of this pixel be? ... and what about this pixel? avg = 1 avg¼ 0.6 A: integrated colour (average colour) over corresponding area in texture But how do we integrate texture for each pixel?? (slow? complex? or is there a fast hacky trick?)

  12. Hack Solution: Mip Mapping • Pre-compute low-frequency versions of the texture (a “mipmap”) 128£128 64£64 get avg of 64 samples here by taking just 1 sample here! glGenerateMipmap(GL_TEXTURE_2D); 16£16 32£32

  13. How to Visualize Mip-Map Sampling • Manually load solid colour texture at each mipmap level! sampling of fake colour-coded mipmaps (yellow=128£128 white = 1£1) sampling of actual texture mipmaps minification magnification

  14. OpenGL Texture Filtering • Two cases to configure • magnification: what should OpenGL do when a screen pixel maps to region smaller than a texel? • minification: what if screen pixel maps to region much larger than a texel? • Configure mode of bound texture glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,mag_mode); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,min_mode); // where mag_mode = GL_NEAREST or GL_LINEAR // where min_mode= GL_NEAREST or GL_LINEAR or GL_LINEAR_MIPMAP_LINEAR

  15. OpenGL Texture Wrapping • Some textures repeat over and over... 2004 George Bush campaign ad

  16. OpenGL Texture Wrapping • Some textures repeat over and over... • If interpolated (u,v)is outside texmap range [0,1]2, where should we sample? • GL_CLAMP_TO_EDGE: clamp u and v to range [0,1] • GL_REPEAT: take fractional part of u and v glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,wrap_mode); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,wrap_mode); // where wrap_mode = GL_CLAMP_TO_EDGE or GL_REPEAT clamped repeated once repeated four times 6£6 texture

  17. Anisotropic Sampling/Filtering • Normal mip-maps are isotropic: they blur same amount in each direction. • Pixel may project onto highly stretched region in texture • Anisotropic filtering uses “rip-maps” to sample more in u than in v etc.

  18. Anisotropic Sampling/Filtering • Avoids oblique textures looking blurred

  19. Anisotropic Sampling/Filtering • Higher-detail samples in one dimension

More Related