Last Time Shading Interpolation Texture mapping Barycentric coordinates for triangles 11 11 04 University of Wisconsin CS559 Fall 2004 Today Texture Anti Aliasing Texture boundaries Modeling introduction 11 11 04 University of Wisconsin CS559 Fall 2004 Texture Recap Triangle in 8x8 Texture Map I s t Triangle in world space I s t Interpolated s t we need a texture sample from I s t t s We must reconstruct the texture image at the point s t Time to apply the theory of sampling and reconstruction 11 11 04 University of Wisconsin CS559 Fall 2004 Textures and Aliasing Textures are subject to aliasing A polygon pixel maps into a texture image essentially sampling the texture at a point The situation is essentially an image warp with the warp defined by the mapping and projection Standard approaches Pre filtering Filter the texture down before applying it Useful when the texture has multiple texels per output image pixel Post filtering Take multiple pixels from the texture and filter them before applying to the polygon fragment Useful in all situations 11 11 04 University of Wisconsin CS559 Fall 2004 Point Sampled Texture Aliasing Texture map Polygon far from the viewer in perspective projection Rasterized and textured Note that the back row is a very poor representation of the true image 11 11 04 University of Wisconsin CS559 Fall 2004 Mipmapping Pre filtering If a textured object is far away one screen pixel on an object may map to many texture pixels The problem is how to combine them A mipmap is a low resolution version of a texture Texture is filtered down as a pre processing step gluBuild2DMipmaps When the textured object is far away use the mipmap chosen so that one image pixel maps to at most four mipmap pixels Full set of mipmaps requires at most 1 3333 the storage of the original texture in the limit 1 0 25 25 25 0 25 0 25 0 25 11 11 04 University of Wisconsin CS559 Fall 2004 Many Texels for Each Pixel Texture map with pixels drawn on it Some pixels cover many texture elements texels 11 11 04 Polygon far from the viewer in perspective projection University of Wisconsin CS559 Fall 2004 Mipmaps For far objects For middle objects For near objects 11 11 04 University of Wisconsin CS559 Fall 2004 Mipmap Math Define a scale factor texels pixel A texel is a pixel from a texture is actually the maximum from x and y The scale factor may vary over a polygon It can be derived from the transformation matrices Define log2 tells you which mipmap level to use Level 0 is the original texture level 1 is the next smallest texture and so on If 0 then multiple pixels map to one texel magnification 11 11 04 University of Wisconsin CS559 Fall 2004 Post Filtering You tell OpenGL what sort of post filtering to do Magnification When 0 the image pixel is smaller than the texel glTexParameteri GL TEXTURE 2D GL TEXTURE MAG FILTER type Type is GL LINEAR or GL NEAREST Minification When 0 the image pixel is bigger than the texel GL TEX MIN FILTER Can choose to Take nearest point in base texture GL NEAREST Linearly interpolate nearest 4 pixels in base texture GL LINEAR Take the nearest mipmap and then take nearest or interpolate in that mipmap GL NEAREST MIPMAP LINEAR Interpolate between the two nearest mipmaps using nearest or interpolated points from each GL LINEAR MIPMAP LINEAR 11 11 04 University of Wisconsin CS559 Fall 2004 Filtering Example Level 2 NEAREST MIPMAP NEAREST level 0 pixel 0 0 LINEAR MIPMAP NEAREST level 0 pixel 0 0 0 51 level 1 pixel 0 0 0 49 Level 1 NEAREST MIPMAP LINEAR level 0 combination of pixels 0 0 1 0 1 1 0 1 Level 0 11 11 04 s 0 12 t 0 1 1 4 0 49 LINEAR MIPMAP LINEAR Combination of level 0 and level 1 4 pixels from each level using 8 pixels in all University of Wisconsin CS559 Fall 2004 Boundaries You can control what happens if a point maps to a texture coordinate outside of the texture image All texture images are assumed to go from 0 0 to 1 1 in texture space means that the mapping is independent of the texture size The problem is how to extend the image to make an infinite space Repeat Assume the texture is tiled glTexParameteri GL TEXTURE 2D GL TEXTURE WRAP S GL REPEAT Clamp to Edge the texture coordinates are truncated to valid values and then used glTexParameteri GL TEXTURE 2D GL TEXTURE WRAP S GL CLAMP Can specify a special border color 11 11 04 glTexParameterfv GL TEXTURE 2D GL TEXTURE BORDER COLOR R G B A University of Wisconsin CS559 Fall 2004 Repeat Border 1 1 0 0 11 11 04 University of Wisconsin CS559 Fall 2004 Clamp Border 1 1 0 0 11 11 04 University of Wisconsin CS559 Fall 2004 Border Color 1 1 0 0 11 11 04 University of Wisconsin CS559 Fall 2004 Other Texture Stuff Texture must be in fast memory it is accessed for every pixel drawn If you exceed it performance will degrade horribly Skilled artists can pack textures for different objects into one image Texture memory is typically limited so a range of functions are available to manage it Specifying texture coordinates can be annoying so there are functions to automate it Sometimes you want to apply multiple textures to the same point Multitexturing is now in most new hardware 11 11 04 University of Wisconsin CS559 Fall 2004 Yet More Texture Stuff There is a texture matrix apply a matrix transformation to texture coordinates before indexing texture There are image processing operations that can be applied to the pixels coming out of the texture There are 1D and 3D textures Mapping works essentially the same 3D textures are very memory intensive and how they are used is very application dependent 1D saves memory if the texture is inherently 1D like stripes 11 11 04 University of Wisconsin CS559 Fall 2004 Procedural Texture Mapping Instead of looking up an image pass the texture coordinates to a function that computes the texture value on the fly Renderman the Pixar rendering language does this Available in a limited form with fragment shaders on current generation hardware Advantages Near infinite resolution with small storage cost Idea works for many other things Has the disadvantage of being slow in most cases 11 11 04 University of Wisconsin CS559 Fall 2004 Other Types of Mapping Environment mapping looks up incoming illumination in a map Simulates reflections from shiny surfaces Bump mapping computes an offset to the normal vector at each rendered pixel No need to put bumps in geometry but silhouette looks wrong Displacement mapping adds an offset to the surface at each point Like putting bumps on geometry but
View Full Document
Unlocking...