introduction to texture mapping cse 470/598 introduction to computer graphics arizona state...
TRANSCRIPT
![Page 1: Introduction to Texture Mapping CSE 470/598 Introduction to Computer Graphics Arizona State University Dianne Hansford](https://reader031.vdocuments.site/reader031/viewer/2022020718/56649e7a5503460f94b7b68c/html5/thumbnails/1.jpg)
Introduction toTexture Mapping
CSE 470/598
Introduction to Computer GraphicsArizona State University
Dianne Hansford
![Page 2: Introduction to Texture Mapping CSE 470/598 Introduction to Computer Graphics Arizona State University Dianne Hansford](https://reader031.vdocuments.site/reader031/viewer/2022020718/56649e7a5503460f94b7b68c/html5/thumbnails/2.jpg)
Texture Mapping Concepts
A method to create complexity in an image without the overhead of building large geometric models.
![Page 3: Introduction to Texture Mapping CSE 470/598 Introduction to Computer Graphics Arizona State University Dianne Hansford](https://reader031.vdocuments.site/reader031/viewer/2022020718/56649e7a5503460f94b7b68c/html5/thumbnails/3.jpg)
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
![Page 4: Introduction to Texture Mapping CSE 470/598 Introduction to Computer Graphics Arizona State University Dianne Hansford](https://reader031.vdocuments.site/reader031/viewer/2022020718/56649e7a5503460f94b7b68c/html5/thumbnails/4.jpg)
Texture Form
• Textures are almost always rectangularm 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
![Page 5: Introduction to Texture Mapping CSE 470/598 Introduction to Computer Graphics Arizona State University Dianne Hansford](https://reader031.vdocuments.site/reader031/viewer/2022020718/56649e7a5503460f94b7b68c/html5/thumbnails/5.jpg)
Texture Coordinates
• 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 statelike colors and normals.
s
t
[0,0]
[1, 0]
[0, 1]
[s,t]-space [u,v]-space of surface [x,y,z]-space of surface
…although it is really just an array of pixels
![Page 6: Introduction to Texture Mapping CSE 470/598 Introduction to Computer Graphics Arizona State University Dianne Hansford](https://reader031.vdocuments.site/reader031/viewer/2022020718/56649e7a5503460f94b7b68c/html5/thumbnails/6.jpg)
Pixels & Texture Coordinates
s
t
[0,0]
[1, 0]
[0, 1]
s, t = .33, .33s, t = .33, .33
For example: a 32 x 32 pixel image
Glubyte mychecker[32][32][3];
glEnable(GL_TEXTURE_2D);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 32, 32, 0, GL_RGB, GL_UNSIGNED_BYTE, mychecker);
![Page 7: Introduction to Texture Mapping CSE 470/598 Introduction to Computer Graphics Arizona State University Dianne Hansford](https://reader031.vdocuments.site/reader031/viewer/2022020718/56649e7a5503460f94b7b68c/html5/thumbnails/7.jpg)
Texture Coordinates to Polygons
1,0
1,1
0,0
1,0
Texture Coordinat
es
Texture Coordinat
es
s, t = .33, .33s, t = .33, .33
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!
![Page 8: Introduction to Texture Mapping CSE 470/598 Introduction to Computer Graphics Arizona State University Dianne Hansford](https://reader031.vdocuments.site/reader031/viewer/2022020718/56649e7a5503460f94b7b68c/html5/thumbnails/8.jpg)
Example
domains of the 3D model
Parametric surfaces come with a 2D domain.
Meshes: flatten parts to create a 2D domain
![Page 9: Introduction to Texture Mapping CSE 470/598 Introduction to Computer Graphics Arizona State University Dianne Hansford](https://reader031.vdocuments.site/reader031/viewer/2022020718/56649e7a5503460f94b7b68c/html5/thumbnails/9.jpg)
Textured
![Page 10: Introduction to Texture Mapping CSE 470/598 Introduction to Computer Graphics Arizona State University Dianne Hansford](https://reader031.vdocuments.site/reader031/viewer/2022020718/56649e7a5503460f94b7b68c/html5/thumbnails/10.jpg)
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)
![Page 11: Introduction to Texture Mapping CSE 470/598 Introduction to Computer Graphics Arizona State University Dianne Hansford](https://reader031.vdocuments.site/reader031/viewer/2022020718/56649e7a5503460f94b7b68c/html5/thumbnails/11.jpg)
Programming with Texture Maps
1. Create texture and load with glTexImage() by eithera. read a jpeg, bmp, …. fileb. define texture within applicationc. copy image from color buffer
2. Define parameters as to how texture is appliedglTexParameter*()
Next slides describe the options here….See Table 9.6 in OGL Red Book
3. Enable texture mapsglEnable(GL_TEXTURE_2D)
4. Define texture coordinates for vertices glTexCoord*(s,t); glVertex*(x,y,z);
![Page 12: Introduction to Texture Mapping CSE 470/598 Introduction to Computer Graphics Arizona State University Dianne Hansford](https://reader031.vdocuments.site/reader031/viewer/2022020718/56649e7a5503460f94b7b68c/html5/thumbnails/12.jpg)
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
![Page 13: Introduction to Texture Mapping CSE 470/598 Introduction to Computer Graphics Arizona State University Dianne Hansford](https://reader031.vdocuments.site/reader031/viewer/2022020718/56649e7a5503460f94b7b68c/html5/thumbnails/13.jpg)
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 lists1. Name the texture object2. Bind (create) texture object to texture data/properties3. Prioritize texture object (if maxing out texture memory)4. Bind texture object making data currently available
![Page 14: Introduction to Texture Mapping CSE 470/598 Introduction to Computer Graphics Arizona State University Dianne Hansford](https://reader031.vdocuments.site/reader031/viewer/2022020718/56649e7a5503460f94b7b68c/html5/thumbnails/14.jpg)
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?
![Page 15: Introduction to Texture Mapping CSE 470/598 Introduction to Computer Graphics Arizona State University Dianne Hansford](https://reader031.vdocuments.site/reader031/viewer/2022020718/56649e7a5503460f94b7b68c/html5/thumbnails/15.jpg)
Texture to Surface Mapping• Texture map to surface takes place during rendering
Similar to smooth shading method:Triangle rasterizedEach pixel mapped back to the textureUse 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) magnification3) minification
Magnificationone texel to many pixels
Minificationmany texels to one pixel
Filtering
![Page 16: Introduction to Texture Mapping CSE 470/598 Introduction to Computer Graphics Arizona State University Dianne Hansford](https://reader031.vdocuments.site/reader031/viewer/2022020718/56649e7a5503460f94b7b68c/html5/thumbnails/16.jpg)
Zoom In
many pixels correspond to one texel “blockiness” / jaggies / aliasing
solution: apply averaging (magnification filter)
![Page 17: Introduction to Texture Mapping CSE 470/598 Introduction to Computer Graphics Arizona State University Dianne Hansford](https://reader031.vdocuments.site/reader031/viewer/2022020718/56649e7a5503460f94b7b68c/html5/thumbnails/17.jpg)
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
![Page 18: Introduction to Texture Mapping CSE 470/598 Introduction to Computer Graphics Arizona State University Dianne Hansford](https://reader031.vdocuments.site/reader031/viewer/2022020718/56649e7a5503460f94b7b68c/html5/thumbnails/18.jpg)
Zoom-In: Magnification FilterOptions for smoothing:
Simplest: GL_NEARESTJust use the closest texel’s color (default – jaggies common)Also called point sampling
Better: GL_LINEARWeighted average of the four nearest texelsAlso called bilinear sampling (interpolation)
glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
(s0, t0)
c0 c1
c3
(s2, t0)
Bilinear interpolationb1 = (s – s0)/(s2 – s0)b2 = (t – t0)/(t2 – t0)
c = (1-b2)*( (1-b1)*c0 + b1*c1) + b2*( (1-b1)*c2 + b1*c3)
![Page 19: Introduction to Texture Mapping CSE 470/598 Introduction to Computer Graphics Arizona State University Dianne Hansford](https://reader031.vdocuments.site/reader031/viewer/2022020718/56649e7a5503460f94b7b68c/html5/thumbnails/19.jpg)
Zoom Out: Minification Filter
• One pixel corresponds to many texels• Common with perspective foreshortening
(see example on next slide)
glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
Options:GL_NEARESTGL_LINEARGL_*_MIPMAP_*_ where * = NEAREST OR LINEAR mipmapping
![Page 20: Introduction to Texture Mapping CSE 470/598 Introduction to Computer Graphics Arizona State University Dianne Hansford](https://reader031.vdocuments.site/reader031/viewer/2022020718/56649e7a5503460f94b7b68c/html5/thumbnails/20.jpg)
Mipmap Improvements
Images from the flipCode tutorial in the Resources
Perspective foreshorteningand poor texture mappingcauses checkerboard to deform
Mipmaps improve the mapping, returning moreform to the checkerboard
![Page 21: Introduction to Texture Mapping CSE 470/598 Introduction to Computer Graphics Arizona State University Dianne Hansford](https://reader031.vdocuments.site/reader031/viewer/2022020718/56649e7a5503460f94b7b68c/html5/thumbnails/21.jpg)
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
![Page 22: Introduction to Texture Mapping CSE 470/598 Introduction to Computer Graphics Arizona State University Dianne Hansford](https://reader031.vdocuments.site/reader031/viewer/2022020718/56649e7a5503460f94b7b68c/html5/thumbnails/22.jpg)
Mipmap Representation I
Create several copiesFilter down in sizePre-filter textures = mipmaps
Appropriate sized texture selected based on number of pixels occupied by geometry
![Page 23: Introduction to Texture Mapping CSE 470/598 Introduction to Computer Graphics Arizona State University Dianne Hansford](https://reader031.vdocuments.site/reader031/viewer/2022020718/56649e7a5503460f94b7b68c/html5/thumbnails/23.jpg)
Mipmap Representation II
Optimize storage(Schematic of method)
![Page 24: Introduction to Texture Mapping CSE 470/598 Introduction to Computer Graphics Arizona State University Dianne Hansford](https://reader031.vdocuments.site/reader031/viewer/2022020718/56649e7a5503460f94b7b68c/html5/thumbnails/24.jpg)
Mipmap Generation
Must provide all sizes of texture from input to 1x1 in powers of 2
gluBuild*DMipmaps() will help with that!
![Page 25: Introduction to Texture Mapping CSE 470/598 Introduction to Computer Graphics Arizona State University Dianne Hansford](https://reader031.vdocuments.site/reader031/viewer/2022020718/56649e7a5503460f94b7b68c/html5/thumbnails/25.jpg)
Mipmap Filters
• In order of increasing complexity:– GL_NEAREST_MIPMAP_NEAREST– GL_LINEAR_MIPMAP_NEAREST– GL_NEAREST_MIPMAP_LINEAR– GL_LINEAR_MIPMAP_LINEAR
Intermipmap
Intramipmap
Remember: more complexity = slower rendering
![Page 26: Introduction to Texture Mapping CSE 470/598 Introduction to Computer Graphics Arizona State University Dianne Hansford](https://reader031.vdocuments.site/reader031/viewer/2022020718/56649e7a5503460f94b7b68c/html5/thumbnails/26.jpg)
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)
![Page 27: Introduction to Texture Mapping CSE 470/598 Introduction to Computer Graphics Arizona State University Dianne Hansford](https://reader031.vdocuments.site/reader031/viewer/2022020718/56649e7a5503460f94b7b68c/html5/thumbnails/27.jpg)
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
clamped repeat
0 1 2 10 2
![Page 28: Introduction to Texture Mapping CSE 470/598 Introduction to Computer Graphics Arizona State University Dianne Hansford](https://reader031.vdocuments.site/reader031/viewer/2022020718/56649e7a5503460f94b7b68c/html5/thumbnails/28.jpg)
Borders and Sizing
• Linear filtering needs an extra row/column of texels at the border
• Solution: Add a border to your textureglTexParamter3fv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, color)
• Some help copying texel values from original texture: glTexSubImage2D()
• Size of texture: must be 2^n in width and heightgluScaleImage() can be used to convert image to acceptable dimension
![Page 29: Introduction to Texture Mapping CSE 470/598 Introduction to Computer Graphics Arizona State University Dianne Hansford](https://reader031.vdocuments.site/reader031/viewer/2022020718/56649e7a5503460f94b7b68c/html5/thumbnails/29.jpg)
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
texture geometry
Two solutions:1) repeat texture2) use just a portion of the texture(to match the aspect ratio)
![Page 30: Introduction to Texture Mapping CSE 470/598 Introduction to Computer Graphics Arizona State University Dianne Hansford](https://reader031.vdocuments.site/reader031/viewer/2022020718/56649e7a5503460f94b7b68c/html5/thumbnails/30.jpg)
Auto Texture Coordinate Generation
• GLU Quadrics: use gluQuadricTexture() to enable auto generation of textures
• OGL determines texture coordinates based on the distance of a vertex from a plane
Plane can be defined in object or eye coordinatesobject: texture remains fixed wrt objecteye: texture is dynamic, for example contour lines
• OGL determines texture coordinates based on surface normal direction – environment mapping (see “More Texture Mapping” slides) glEnable(GL_TEXTURE_GEN_S)glTexGen*(…)
![Page 31: Introduction to Texture Mapping CSE 470/598 Introduction to Computer Graphics Arizona State University Dianne Hansford](https://reader031.vdocuments.site/reader031/viewer/2022020718/56649e7a5503460f94b7b68c/html5/thumbnails/31.jpg)
Problem with Perspective
• Shape distortions caused by perspective maps not handled by simple interpolation of textures
• More advanced methodglHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
• Also: GL_FASTEST• (Other Hints for antialiasing of lines and polygons.)
• More advanced method - slower
![Page 32: Introduction to Texture Mapping CSE 470/598 Introduction to Computer Graphics Arizona State University Dianne Hansford](https://reader031.vdocuments.site/reader031/viewer/2022020718/56649e7a5503460f94b7b68c/html5/thumbnails/32.jpg)
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
![Page 33: Introduction to Texture Mapping CSE 470/598 Introduction to Computer Graphics Arizona State University Dianne Hansford](https://reader031.vdocuments.site/reader031/viewer/2022020718/56649e7a5503460f94b7b68c/html5/thumbnails/33.jpg)
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 dataGeoscience: rock strata or gas measurements
• Caution: Texture memory can run out fast!
• Example: Uni Hamburg’s Virtual Mummy http://www.uke.uni-hamburg.de/zentren/experimentelle_medizin/informatik/forschung/mumie/index.en.html
![Page 34: Introduction to Texture Mapping CSE 470/598 Introduction to Computer Graphics Arizona State University Dianne Hansford](https://reader031.vdocuments.site/reader031/viewer/2022020718/56649e7a5503460f94b7b68c/html5/thumbnails/34.jpg)
More Mapping Methods
• Height maps• Normal maps / Bump maps• Shadow maps • Environment maps • ….
We’ll discuss these another day!
![Page 35: Introduction to Texture Mapping CSE 470/598 Introduction to Computer Graphics Arizona State University Dianne Hansford](https://reader031.vdocuments.site/reader031/viewer/2022020718/56649e7a5503460f94b7b68c/html5/thumbnails/35.jpg)
Resources I
• Chapter 9 of the text– Overview, pp 360-369– Assigning Texture Coords, pp 414-417– As much of the rest of the chapter as you can
handle
![Page 36: Introduction to Texture Mapping CSE 470/598 Introduction to Computer Graphics Arizona State University Dianne Hansford](https://reader031.vdocuments.site/reader031/viewer/2022020718/56649e7a5503460f94b7b68c/html5/thumbnails/36.jpg)
Resources II
• Fun Reading– From the SIGGRAPH tutorial pages:
http://www.siggraph.org/education/materials/HyperGraph/mapping/r_wolfe/r_wolfe_mapping_1.htm
• Texture Mapping - http://www.geocities.com/SiliconValley/2151/tmap.html
• Advanced OpenGL Texture Mapping - http://www.flipcode.com/tutorials/tut_atmap.shtml
• Texture Mapping as a Fundamental Drawing Primativehttp://www.sgi.com/misc/grafica/texmap/