CSE 167: Introduction to Computer Graphics Lecture 11: Textures 2
CSE 167: Introduction to Computer Graphics Lecture 11: Textures 2
CSE 167: Introduction to Computer Graphics Lecture 11: Textures 2
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
<strong>CSE</strong> <strong>167</strong>:<strong>Introduction</strong> <strong>to</strong> <strong>Computer</strong> <strong>Graphics</strong><strong>Lecture</strong> <strong>11</strong>: <strong>Textures</strong> 2Jürgen P. Schulze, Ph.D.University of California, San DiegoFall Quarter 20<strong>11</strong>
Announcements Homework assignment #5 due Friday, Nov 4, grading inlab 260 starts as usual at 1:30pm StarCAVE demonstration Nov 15 after class Instruc<strong>to</strong>r’s office hour moves from Nov 15 <strong>to</strong> Nov 17 (sametime) Next lecture: Midterm review Midterm exams distributed2
<strong>Lecture</strong> Overview Texturing Wrapping Texture coordinates Anti-aliasing3
Wrap Modes Texture image extends from [0,0] <strong>to</strong> [1,1] in texturespace What if (s,t) texture coordinates are beyond that range? Wrap modes4
Repeat Repeat the texture Creates discontinuities at edges unless texture designed <strong>to</strong> line up(1,1)t(0,0)sSeamless brick wall texture(by Chris<strong>to</strong>pher Revoir)5Texture Space
Clamp Use edge value everywhere outside data range [0..1] Or, ignore the texture outside [0..1](1,1)t(0,0)s6Texture Space
Wrap Mode Specification in OpenGL Default: glTexParameterf( GL_TEXTURE_2D,GL_TEXTURE_WRAP_S, GL_REPEAT ); glTexParameterf( GL_TEXTURE_2D,GL_TEXTURE_WRAP_T, GL_REPEAT ); Options for wrap mode: GL_CLAMP (requires border <strong>to</strong> be set)GL_CLAMP_TO_EDGE (repeats last pixel in texture),GL_REPEAT7
<strong>Lecture</strong> Overview Texturing Wrapping Texture coordinates Anti-aliasing8
Texture CoordinatesWhat if texture extends across multiple polygons? Surface parameterization Mapping between 3D positions on surface and 2D texturecoordinatesIn practice, defined by texture coordinates of triangle vertices Options for mapping:ParametricOrthographicProjectiveSphericalCylindricalSkin9
Parametric Mapping Surface given by parametric functions Very common in CAD Clamp (u,v) parameters <strong>to</strong> [0..1] and use as texturecoordinates (s,t)10
Orthographic Mapping Use linear transformation of object’s xyz coordinates For example:⎡s⎢⎣t⎤⎥⎦⎡1= ⎢⎣00100⎡ x⎤0⎢ ⎥⎤⎢y⎥0⎥⎦⎢z ⎥⎢ ⎥⎣w⎦<strong>11</strong>
Projective Mapping Use perspective projection of xyz coordinates OpenGL provides GL_TEXTURE matrix <strong>to</strong> applyperspective projection on texture coordinates Can be used for “fake” lighting effects12
Spherical Mapping Use spherical coordinates for sphere Place object in sphere “shrink-wrap” sphere <strong>to</strong> object13
Cylindrical Mapping Similar as spherical mapping, but using cylinder Useful for faces14
Skin Mapping Complex technique <strong>to</strong> unfold surface on<strong>to</strong> plane Preserve area and angle Sophisticated mathematics15
<strong>Lecture</strong> Overview Texturing Wrapping Texture coordinates Anti-aliasing16
Example for Aliasing What could cause this effect?17
AliasingSufficientlysampled,no aliasingInsufficientlysampled,aliasingImage: Robert L. CookHigh frequencies in the input data can appear aslower frequencies in the sampled signal18
Antialiasing: Intuition Pixel may cover large area on triangle in camera space Corresponds <strong>to</strong> many texels in texture space Need <strong>to</strong> compute averageImage planeCamera spaceTexture spaceTexelsPixel area19
Antialiasing: Mathematics Pixels are sample points, not little squares! See article by Dr. Alvy Ray Smith, Microsoft:http://alvyray.com/Memos/CG/Microsoft/6_pixel.pdf Antialiasing is achieved through low-pass filtering For more information: Master’s Thesis: Fundamentals of Texture Mapping and ImageWarping, Paul Heckbert, UC Berkeley:http://www.cs.cmu.edu/~ph/texfund/texfund.pdf20
Antialiasing Using Mip-Maps Averaging over texels is expensive Many texels as objects get smaller Large memory access and compuation cost Precompute filtered (averaged) textures Mip-maps Practical solution <strong>to</strong> aliasing problem Fast and simple Available in OpenGL, implemented in GPUs Reasonable quality21
Mipmaps MIP stands for multum in parvo = “much in little” (Williams1983)Before rendering Pre-compute and s<strong>to</strong>re down scaled versions of texturesReduce resolution by fac<strong>to</strong>rs of two successivelyUse high quality filtering (averaging) scheme Increases memory cost by 1/31/3 = ¼+1/16+1/64+… Width and height of texture should be powers of two (nonpowerof two supported since OpenGL 2.0)22
Mipmaps Example: resolutions 512x512, 256x256, 128x128, 64x64,32x32 pixelsLevel 123Level 0234“multum in parvo”
Mipmaps One texel in level 4 is the average of 4 4 =256 texels inlevel 0Level 124Level 0234“multum in parvo”
MipmapsLevel 0 Level 1 Level 225Level 3 Level 4
Rendering With Mipmaps “Mipmapping” Interpolate texture coordinates of each pixel as withoutmipmapping Compute approximate size of pixel in texture space Look up color in nearest mipmap E.g., if pixel corresponds <strong>to</strong> 10x10 texels use mipmap level 3 Use nearest neighbor or bilinear interpolation as before26
MipmappingImage planeCamera spaceTexture spaceTexelsPixel area27Mip-map level 0Mip-map level 1Mip-map level 2Mip-map level 3
Nearest Mipmap, Nearest Neighbor Visible transition between mipmap levels28
Nearest Mipmap, Bilinear Visible transition between mipmap levels29
Trilinear Mipmapping Use two nearest mipmap levels E.g., if pixel corresponds <strong>to</strong> 10x10 texels, use mipmap levels 3(8x8) and 4 (16x16) Perform bilinear interpolation in both mip-maps Linearly interpolate between the results Requires access <strong>to</strong> 8 texels for each pixel Standard method, supported by hardware with noperformance penalty30
Nearest Mipmap, Bilinear Visible transition between mipmap levels31
Trilinear Mipmapping Smooth transition between mipmap levels32
Next <strong>Lecture</strong> Midterm review Curves33