CS 551 / CS 645
Texture Maps
• Let’s talk about ‘working together’
– No sharing code unless specifically allowed (and documented in README)
– Talking about provided start-up code allowed
– Talking about generic programming allowed. How does fscanf work?
– No helping one another with the graphics-specific programming.
• Obvious violations in Assignment 2
– Email me today or tomorrow
• Assignment 2 returned
• Midterm returned
• Assignment 3 part 2 handed out
• Shade pixels according to the area covered by thickened line
• This is unweighted area sampling
• A rough approximation formulated by dividing each pixel into a finer grid of pixels
• Weighting function, W(x,y)
– specifies the contribution of primitive passing through the point (x, y) from pixel center
Intensity
W(x,y) x
• Multiply sample grid by image intensity to obtain a discrete set of points, or samples.
Sampling Geometry
• To lower Nyquist rate, remove high frequencies from image: low-pass filter
– Only low frequencies remain
• Sinc function is common filter:
– sinc(x) = sin ( p x)/ p x
Spatial Domain Frequency Domain
• Sometimes called a tent filter
• Easy to compute
– just linearly interpolate between samples
• Finite extent and no negative values
• Still has artifacts
• Adaptive supersampling
– store more points when necesssary
• Stochastic supersampling
– Place sample points at stochastically determined points
• Eye has harder time detecting aliasing when combined with the noise generated by stochastics
• Chapter 9 of Open GL Programming
Guide (Red Book)
• Images applied to polygons to enhance the visual effect of a scene
– Rectangular arrays of data
• Color, luminance, alpha
• Components of array called texels
• Color mode must be RGBA
– A stands for Alpha, or opacity
• Texture applied to pixels of polygon
– Replace mode: texture is painted on top of polygon
– Modulate polygon color
– Blend a constant color with polygon
• GLenum target
– GL_TEXTURE_2D
– GL_PROXY_TEXTURE_2D
• Provides queries for texture resources
• Proceed with hypothetical texture use (GL won’t apply the texture)
• After query, call GLGetTexLevelParamter to verify presence of required system components
• Doesn’t check possibility of multiple texture interference
• GLint level
– Used for Level of Detail (LOD)
– LOD stores multiple versions of texture that can be used at runtime (set of sizes)
– Runtime algorithms select appropriate version of texture
• Pixel size of polygon used to select best texture
• Eliminates need for error-prone filtering algorithms
• GLint internalFormat
– Describes which of R, G, B, and A are used in internal representation of texels
– Provides control over things texture can do
• High bit depth alpha blending
• High bit depth intensity mapping
• General purpose RGB
– GL doesn’t guarantee all options are available on given hardware
• GLsizei width
• GLsizei height
– Dimensions of texture image
• Must be 2 m + 2b (b=0 or 1 depending on border)
• min, 64 x 64
• GLint border
– Width of border (1 or 0)
• Border allows linear blending between overlapping textures
• Useful when manually tiling textures
• GLenum format
– Describe how texture data is stored in input array
• GL_RGB, GL_RGBA, GL_BLUE…
• GLenum type
– Data size of array components
• GL_SHORT, GL_BYTE, GL_INT…
• Const GLvoid *texels
– Pointer to data describing texture map
• Be aware of tradeoffs between memory usage, color depth, and speed
• gluScaleImage will alter the size of an image to meet the 2 m size requirement of OpenGL
– Scaling performed by linear and box filtering
• glCopyTexImage2D
– Use current frame buffer contents as texture
– Copy frame buffer to named texture location
• Replace a region of current working texture with a smaller texture
• SubImage need not adhere to 2 m size limitation
• This is how you add data from your system’s camera to GL environment
• glCopyTexSubImage2D
– Frame buffer cut and paste possible too
• A texture LOD technique
• Prespecify a series of prefiltered texture maps of decreasing resolutions
• Requires more texture storage
• Eliminates shimmering and flashing as objects move
• Automatically constructs a family of textures from original texture size down to 1x1
• Runtime mipmap level determination
– r
= max texture size / max polygon size
– l
= log
2 r
– If l < 0.0, texture smaller than polygon and magnification filter is used
– If l > 0.0, texture is larger than polygon and minification is used (mipmapping)
• l specifies mipmap level
• You can specify additional mipmap levels on the fly
– MIN_LOD may reduce popping
– MAX_LOD may reduce over compression
• You can specify min mipmap level
– Useful for mosaicing
• OpenGL tries to pick best mipmap level
• Question: Which texel corresponds to a particular pixel?
• GL_NEAREST (Point Sampling)
– Pick the texel with center nearest pixel
• GL_LINEAR (Bilinear Sampling)
– Weighted average of 2x2 closest texels
• GL_LINEAR_MIPMAP_LINEAR
– Average texels from two mipmap levels
• GL_LINEAR_MIPMAP_LINEAR (Trilinear)
– Average two averaged texels from two mipmaps
• glGenTextures
– A way to obtain a reference to a texture object
• glBindTexture
– A way to bind a texture to a texture object
• Desirable to have all the textures stored as memory resident objects
• Many GL management functions
• Coloring – like a decal
• Alpha – average polygon color with texture
• Lighting – change intensity
• Specular lighting effects
– Lighting mode exists which separates polygon base color from specular color
– Texturing can be applied to base color only with specular effects added later
• Every polygon has object coordinates and texture coordinates
– Object coordinates describe where polygon vertices are on the screen
– Texture coordinates describe texel coordinates of each vertex (usually 0 -> 1)
– Texture coordinates are interpolated along vertex-vertex edges
• glTexCoord{1234}{sifd}(TYPE coords)
• Cones and cylinders easily mapped to rectangular coordinate spaces without distortion
• Repeating – texture coordinate > 1.0
• Clamped – texture coordinate > 1.0 is clamped
• Think about relationship between filter mode and repeat/clamp
• glTexGen
– Provides control over how texture is placed on polygon
– GL_OBJECT_LINEAR
• Consistent mapping to object’s coordinate system
– GL_EYE_LINEAR
• Mapping is relative to eyepoint
– GL_SPHERE_MAP
• Environment Mapping
• Used to model a object that reflects surrounding textures to the eye
– Polished sphere reflects walls and ceiling textures
– Cyborg in Terminator 2 reflects flaming destruction
• Texture is distorted fish-eye view of environment
• Spherical texture mapping creates texture coordinates that correctly index into this texture map
• Remember, texture coordinate interpolation is linear
• Texture coordinates can contain an optional q-parameter
• Q scales texture coordinates by dividing each coordinate by q
• This captures perspective transformations
• Pipelining of multiple texture applications to one polygon
• The results of each texture unit application is passed to the next texture unit, which adds its effects
• More bookkeeping is required to pull this off
• Seven hours in line at Walmart
• Total mayhem (two arrested)
• Fighting over 41 units
• Debt of Gratitude to:
– Vic Ludwig
– Brian Salomon
– Damian Slonneger
•300 MHz 128 bit RISC “Emotion
Engine” chip (from Toshiba)
•32 MB Rambus memory
•Standard DVD-ROM (CD-ROM compatible)
• 150 MHz clock
• 4 MB video memory
• 75 Million Polygons Per Second is absolute max
• 20 Million per second with 48 pixel quads, Zbuffering, alpha blending, and MIP mapping
• MIP-mapping
• Bi-linear filtering
• Surface/Edge
Anti-aliasing
• Texturecorrection
• 32 bit Z-buffering
• Plays DVDs right out of the box
• USB, PCMCIA, and “I-Link” I/O ports for modem and other peripherals
• Backwards compatibility with
Playstation 1 games
• Hard Drive available in 2001