Computer Graphics Course 2006 Texture Mapping Part of the slides are by: Raanan Fattal David Akers Durand and Cutler
Texture Mapping � Motivation � Definition of 2D texture mapping � Coordinate generation, interpolation � Different uses of 2D textures � Beyond 2D textures
The Problem: � Motivation: Add interesting and/ or realistic detail to surfaces of objects. � Problem: Fine geometric detail is difficult to model and expensive to render.
The Problem: � We don't want to represent all this detail with geometry
Texture Mapping � Idea: Modify various shading parameters of the surface by mapping a function (such as a 2D image) onto the surface. � Given an image, think of it as a 2D function from [ 0,1] 2 (texture coordinates) to the RGB color space: → → ( , ) ( , , ) ( , ) ( , , ) T u v r g b T u v r g b � For each geometric primitive, define a mapping M that maps points on the surface to texture coordinates: = = ( , , ) ( , ) ( , , ) ( , ) M x y z u v M x y z u v � To shade a pixel corresponding to a point (x,y,z) on the surface, use the color: = = ( , , ) ( , , ) ( ( ( , , )) ( , , )) r g b T M x y z r g b T M x y z
Texture Mapping Example � Texture: � Result:
The Quest for Visual Realism
Texture Mapping � So, what do we have to do in order to make this idea work? � Coordinates generation/ assignment � Interpolation � The basic idea is simple, but… � Large number of details � Still an active research area � We will make an overview of some of the issues today. � Next time you will learn how to use/ implement part of the ideas here with OpenGL
Texture Coordinates � To render a textured triangle, we must start by assigning a texture coordinate to each vertex � A texture coordinate is a 2D point [ t x t y ] in texture space that is the coordinate of the image that will get mapped to a particular vertex
Texture Mapping (1,1) v 1 t 1 y v 0 t 2 t 0 v 2 (0,0) x Texture Space Triangle (in any space)
Texture Interpolation � The actual texture mapping computations take place at the scan conversion and pixel rendering stages of the graphics pipeline � During scan conversion, as we are looping through the pixels of a triangle, we must interpolate the t x t y texture coordinates in a similar way to how we interpolate the rgb color and z depth values � As with all other interpolated values, we must precompute the slopes of each coordinate as they vary across the image pixels in x and y � Once we have the interpolated texture coordinate, we look up that pixel in the texture map and use it to color the pixel
Interpolation for triangles Linear Interpolation: C = λ + − λ ( 1 ) D A C 1 1 = λ + − λ ( 1 ) E B C 2 2 = λ + − λ ( 1 ) F D E 3 3 λ 3 D E Bilinear Interpolation λ 2 F = λ λ + − λ λ 1 ( ( 1 ) ) F A C 3 1 1 B + − λ λ + − λ ( 1 )( ( 1 ) ) B C 3 2 2 = λ + λ + λ F A B C A a b c
Let’s start with the details � Where are a lot of issues with both texture coordinates generation/ assignment and interpolation � Let’s start with the former � Any ideas?
Photo-textures
Texture Mapping Difficulties � Tedious to specify texture coordinates � Acquiring textures is surprisingly difficult � Photographs have projective distortions � Variations in reflectance and illumination � Tiling problems
Painting on textures
Texture Chart � Pack triangles into a single image
What does a texture map for a complex model “look like”?
Texture coordinate generation cube planar spherical cylindrical face shrink-wrap
Parametrizing Objects � Certain objects have a natural parametrization (e.g., Bezier patches) � Polygons (triangles): each vertex is assigned a pair of texture coordinates (u,v). Inside, linear interpolation is used. � How do we handle a more complex object?
Two-Step Texture Mapping (Bier and Sloan 1986) � Step I: define a mapping between the texture and some intermediate surface: � plane � cylinder � sphere � cube � Step II: Project intermediate surface onto object surface
Intermediate Surface Projections
Projective Textures � Use the texture like a slide projector � No need to specify texture coordinates explicitly � A good model for shading variations due to illumination � A fair model for reflectance (can use pictures)
That’s what we get when we just interpolate the coordinates
Magnification and minification m agnification m inification texture polygon texture polygon
Better magnification
Better minification
Another Solution: Mipmapping
Mip-mapping � Mip-mapping � MIP = Multim in Parvo (many things in a small place) � Idea: store texture as a pyramid of progressively lower-resolution images, filtered down from original
Mip-Mapping Depth of Mip-Map
Mip Mapping R G B R G R G B B
Mip Mapping � Which level of mip-map to use? � Think of mip-map as 3-D pyramid � Index into mip-map with 3 coordinates: u, v, d (depth) � The size of the filter (i.e., d in the mip- map) depends on the pixel coverage area in the texture map � In general, treat d as a continuous value � Blend between nearest mip-map level using linear interpolation
Common Artifacts Better results can be achieved with trilinear filtering BTW: do you recognize this head?
Fun stuff � As we already saw in this course, hacks and ad-hoc solutions are part of the CG � Especially in the real-time rendering � Let’s see some really nice and unintended use of mip-maps. � From the Kevin Bjorke(NVIDIA) talk in the GDC.
Color & Depth � I want to create a long tunnel with a haze…
Color & Depth
Color & Depth The “correct”/ analytical way to � achieve the same result is to compute “Facing Ratio”: (N·V) C = lerp(mossColor, texColor, pow(dot(N,V)),expon))
Wrapping up some concepts together… � Is that a good idea to use this chart “as is” with a mip mapping?
Hackish, but… � The evil you see versus the evil you don’t see
What's Missing? � What's the difference between a real brick wall and a photograph of the wall texture-mapped onto a plane? � What happens if we change the lighting or the camera position?
Bump Mapping � Use textures to alter the surface normal � Does not change the actual shape of the surface � Just shaded as if it were a different shape Swirly Bump Map Sphere w/Diffuse Texture & Bump Map Sphere w/Diffuse Texture
Bump Mapping � Treat the texture as a single-valued height function � Compute the normal from the partial derivatives in the texture
Another Bump Map Example Bump Map Cylinder w/Diffuse Texture Map Cylinder w/Texture Map & Bump Map
What's Missing? � There are no bumps on the silhouette of a bump-mapped object � Bump maps don’t allow self-occlusion or self-shadowing
Generalization: Normal Mapping
Displacement Mapping � Use the texture map to actually move the surface point � The geometry must be displaced before visibility is determined
Displacement Mapping Image from: Geometry Caching for Ray-Tracing Displacement Maps by Matt Pharr and Pat Hanrahan . note the detailed shadows cast by the stones
Displacement Mapping Ken Musgrave
Environment Maps � We can simulate reflections by using the direction of the reflected ray to index a spherical texture map at "infinity". � Assumes that all reflected rays begin from the same point.
What's the Best Choice?
Environment Mapping Example Terminator II. Do you remember a movie that used it before that? Hint: same director…
Texture Maps for Illumination (“Static Light Maps“)
Combining textures � One of the basic and prevalent techniques in a (real-time) CG � We will talk more about generalization of those ideas in GPU lesson
Billboarding
Billboarding
Billboarding examples
Billboarding
Solid Textures (Peachey 1985, Perlin 1985) � Problem: mapping a 2D image/ function onto the surface of a general 3D object is a difficult problem: � Distortion � Discontinuities � Idea: use a texture function defined over a 3D domain - the 3D space containing the object � Texture function can be digitized or procedural
Procedural Textures � Advantages: � compact representation (code vs. data) � unlimited resolution � unlimited extent � controllable via parameters � Disadvantages: � Can be difficult to program and debug � Can be difficult to predict and control � Typically slower to evaluate � Can be difficult to pre-filter
.kkrieger � Download and play with it in your spare time.
Questions? Image by Henrik Wann Jensen Environment map by Paul Debevec
Recommend
More recommend