Download presentation
Presentation is loading. Please wait.
1
Introduction to Texture Mapping
CSE 470/598 Introduction to Computer Graphics Arizona State University
2
Texture Mapping Concepts
A method to create complexity in an image without the overhead of building large geometric models.
3
Basic Idea Application of an image onto a model
An image is mapped onto the 2D domain of a 3D model Correspondence between domain of surface and texture gives method to apply image
4
Texture Form Textures are almost always rectangular m x n array of pixels called texels (texture elements) Textures are frequently square and of sizes that are powers of two to support downsize filtering (mipmapping) It is not necessary to always use the entire texture
5
Texture Coordinates [0, 1] t [1, 0] [0,0] s
A texture is usually addressed by values between zero and one The “addresses” of points on the texture consist of two numbers (s, t) A vertex can be associated with a point on the texture by giving it one of these texture coordinates glTexCoord*(s,t); glVertex*(x,y,z); Texture coords part of state like colors and normals. …although it is really just an array of pixels [0, 1] t [1, 0] [0,0] s [s,t]-space [u,v]-space of surface [x,y,z]-space of surface
6
Pixels & Texture Coordinates
[0, 1] s, t = .33, .33 t For example: a 32 x 32 pixel image Glubyte mychecker[32][32][3]; glEnable(GL_TEXTURE_2D); [1, 0] [0,0] s glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 32, 32, 0, GL_RGB, GL_UNSIGNED_BYTE, mychecker);
7
Texture Coordinates to Polygons
1,0 1,1 Texture Coordinates s, t = .33, .33 0,0 1,0 Each vertex of each polygon in assigned a texture coordinate. OGL finds the appropriate texture coordinate for points “between” vertices during rasterization. – same idea as smooth shading!
8
Example domains of the 3D model
Parametric surfaces come with a 2D domain. Meshes: flatten parts to create a 2D domain
9
Textured
10
Modes of Operation Decal: only the texture color determines the color we see in the frame buffer: GL_DECAL Modulation: texture color multiplies the color computed for each face (default) Blend: Similar to modulation but add alpha-blending glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE)
11
Programming with Texture Maps
Create texture and load with glTexImage() by either a. read a jpeg, bmp, …. file b. define texture within application c. copy image from color buffer Define parameters as to how texture is applied glTexParameter*() Next slides describe the options here…. See Table 9.6 in OGL Red Book Enable texture maps glEnable(GL_TEXTURE_2D) Define texture coordinates for vertices glTexCoord*(s,t); glVertex*(x,y,z);
12
Texture Memory Texels go into texture memory; depends on implementation – special memory or frame buffer Transfer of texels from application program to texture memory can be significant if texture large Texture memory is limited resource –proxy commands to query availability New graphics cards have MBs of texture memory Texture objects help to optimize access to textures In recent years, texturing has moved from software to high performance graphics hardware
13
Texture Objects When using more than one texture …
Stores texture data and makes it available Fastest way to apply/bind/reuse textures Set-up similar to display lists 1. Name the texture object 2. Bind (create) texture object to texture data/properties 3. Prioritize texture object (if maxing out texture memory) 4. Bind texture object making data currently available
14
Texture Mapping Issues
What should happen when we zoom in close or zoom out far away? How do we generate texture coordinates ? What happens if we use texture coordinates less than zero or greater than one? Are texture maps only for putting color on objects?
15
Texture to Surface Mapping
Texture map to surface takes place during rendering Similar to smooth shading method: Triangle rasterized Each pixel mapped back to the texture Use known values at vertices to interpolation over the texture Each pixel is associated with small region of surface and to a small area of texture. 3 possibilites for association: 1) one texel to one pixel (rare) 2) magnification 3) minification Filtering Magnification one texel to many pixels Minification many texels to one pixel
16
Zoom In many pixels correspond to one texel “blockiness” / jaggies / aliasing solution: apply averaging (magnification filter)
17
Zoom-In: Magnification Filter
Pixel cooresponds to a small portion of one texel Results in many pixels getting same texel Without a filtering method, aliasing is common Magnification filter: smooths transition between pixels pixel Texture space
18
Zoom-In: Magnification Filter
Options for smoothing: Simplest: GL_NEAREST Just use the closest texel’s color (default – jaggies common) Also called point sampling Better: GL_LINEAR Weighted average of the four nearest texels Also called bilinear sampling (interpolation) glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); Bilinear interpolation b1 = (s – s0)/(s2 – s0) b2 = (t – t0)/(t2 – t0) c = (1-b2)*( (1-b1)*c0 + b1*c1) + b2*( (1-b1)*c2 + b1*c3) c3 c0 c1 (s0, t0) (s2, t0)
19
Zoom Out: Minification Filter
One pixel corresponds to many texels Common with perspective foreshortening (see example on next slide) Options: GL_NEAREST GL_LINEAR GL_*_MIPMAP_*_ where * = NEAREST OR LINEAR mipmapping glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
20
Mipmap Improvements Perspective foreshortening and poor texture mapping causes checkerboard to deform Mipmaps improve the mapping, returning more form to the checkerboard
21
Better Min Filter: Mipmaps
“mip” stands for multum in parvo, or “many things in a small place” Basic idea: Create many textures of decreasing size and use one of these subtextures when appropriate
22
Mipmap Representation I
Create several copies Filter down in size Pre-filter textures = mipmaps Appropriate sized texture selected based on number of pixels occupied by geometry
23
Mipmap Representation II
See plate 20 in ogl for an interesting illustration in the change between mipmaps Optimize storage (Schematic of method)
24
Mipmap Generation Must provide all sizes of texture from input to 1x1 in powers of 2 gluBuild*DMipmaps() will help with that!
25
Filtering in Summary Zoom-in calls for mag filter
Zoom-out calls for min filter More advanced filters require more time/computation but produce better results Mipmapping is an advanced min filter Caution: requesting mipmapping without pre-defining mipmaps will turn off texturing; (see Filtering in OGL)
26
Wrapping Modes: Repeat or Clamp
Can assign texture coords outside of [0,1] and have them either clamp or repeat the texture map Repeat Issue: Making the texture borders match-up 2 1 2 1 clamped repeat
27
Assigning Texture Coordinates
Parametric surfaces make assignment easy However, distortion of texture will occur Can minimize distortions by preserving aspect ratio of texture and geometry Two solutions: 1) repeat texture 2) use just a portion of the texture (to match the aspect ratio) geometry texture
28
1D Textures Similar to 2D texture but height = 1
Can create pattern of colors for line segments or curves Contouring Can use for Cel shading from intel
29
3D Textures 3D texture elements are called voxels (volume elements)
Embed an object in the voxels to determine color at vertices Commonly used in medical or geoscience applications Medical: CT or MRI layered 3D data Geoscience: rock strata or gas measurements Caution: Texture memory can run out fast! Example: Uni Hamburg’s Virtual Mummy
30
Resources From the SIGGRAPH tutorial pages: Texture Mapping - Advanced OpenGL Texture Mapping - Texture Mapping as a Fundamental Drawing Primitive
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.