1 / 156

CS559: Computer Graphics

This tutorial explores various texture mapping techniques used in computer graphics, including planar, cylindrical, spherical, and cube mapping. It covers the process of mapping 2D texture coordinates to 3D objects, as well as interpolating texture coordinates for smooth texture rendering. Multiple examples and code samples are provided.

Download Presentation

CS559: Computer Graphics

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS559: Computer Graphics Lecture 20: Project 2 Review and Texture mapping Li Zhang Spring 2010 Many slides from Ravi Ramamoorthi, Columbia Univ, Greg Humphreys, UVA and Rosalee Wolfe, DePaul tutorial teaching texture mapping visually

  2. Sample Code by Chi Man Liu

  3. Other basic features • How to change speed? • Add a slider with a callback to change timePerFrame • How to orient a car? • How to draw trees? • A triangle + a rectangle • A cone + a cylinder • Using gluQuadrics

  4. Piecewise Cubics P4 P3 P1 P2

  5. Piecewise Cubics Task1: draw the whole curve DrawCubic(P4,P1,P2,P3); DrawCubic(P1,P2,P3,P4); DrawCubic(P2,P3,P4,P1); DrawCubic(P3,P4,P1,P2); DrawCubic(Q1,Q2,Q3,Q4) For (t=0; t < 0.1; t+=0.01) { A=computePoint(Q1,Q2,Q3,Q4,t); B=computePoint(Q1,Q2,Q3,Q4,t+0.01); drawLine(A,B); } Fine with Hermite, Catmull-Ron, Cardinal How about Bezier? Task 2: find where the train is at time t: If (0<=t<1) return computePoint(P4,P1,P2,P3,t) If (1<=t<2) return computePoint(P1,P2,P3,P4,t-1); If (2<=t<3) return computePoint(P2,P3,P4,P1,t-2); If (3<=t<4) return computePoint(P3,P4,P1,P2,t-3);

  6. Arc-Length Parameterization • Arbitrary curves? P4 P3 P1 P2

  7. Arc-length parameterization t s 0 1 L 0 Arc-length parameterization y x Freeform

  8. Correct Orientation in 3D • Define and interpolate up vector

  9. Implement simple physics • Energy conservation

  10. Multiple Cars • Each has its own parameter t, assuming arc-length parameterization

  11. Hack Shadow (XL,YL,ZL) (x,y,z)

  12. Train smoke? • Balls moving upward and dissipating

  13. Texture Mapping • Important topic: nearly all objects textured • Wood grain, faces, bricks and so on • Adds visual detail to scenes Polygonal model With surface texture

  14. Adding Visual Detail • Basic idea: use images instead of more polygons to represent fine scale color variation

  15. Parameterization + = geometry image texture map • Q: How do we decide where on the geometry each color from the image should go?

  16. Option: Varieties of mappings [Paul Bourke]

  17. Option: unfold the surface [Piponi2000]

  18. Option: make an atlas charts atlas surface [Sander2001]

  19. Outline • Types of mappings • Interpolating texture coordinates • Broader use of textures

  20. How to map object to texture? • To each vertex (x,y,z in object coordinates), must associate 2D texture coordinates (s,t) • So texture fits “nicely” over object

  21. Implementing texture mapping • A texture lives in it own abstract image coordinates paramaterized by (u,v) in the range ([0..1], [0..1]): • It can be wrapped around many different surfaces: • Note: if the surface moves/deforms, the texture goes with it.

  22. How to map object to texture? • To each vertex (x,y,z in object coordinates), must associate 2D texture coordinates (s,t) • So texture fits “nicely” over object

  23. Planar mapping • Like projections, drop z coord (u,v) = (x/W,y/H) • Problems: what happens near silhouettes?

  24. Cylindrical Mapping • Cylinder: r, θ, z with (u,v) = (θ/(2π),z) • Note seams when wrapping around (θ = 0 or 2π)

  25. Basic procedure • First, map (square) texture to basic map shape • Then, map basic map shape to object • Or vice versa: Object to map shape, map shape to square • Usually, this is straightforward • Maps from square to cylinder, plane, … • Maps from object to these are simply coordinate transform

  26. Spherical Mapping • Convert to spherical coordinates: use latitude/long. • Singularities at north and south poles

  27. Cube Mapping

  28. Cube Mapping

  29. Piecewise Mapping From Steve Marschner

  30. Slides from Leonard Mcmillan

  31. Outline • Types of projections • Interpolating texture coordinates • Broader use of textures

  32. 1st idea: Gouraud interp. of texcoords Using barycentric Coordinates

  33. 1st idea: Gouraud interp. of texcoords Scan line

  34. Artifacts • McMillan’s demo of this is at http://graphics.lcs.mit.edu/classes/6.837/F98/Lecture21/Slide05.html • Another example http://graphics.lcs.mit.edu/classes/6.837/F98/Lecture21/Slide06.html • What artifacts do you see? • Why? • Hint: problem is in interpolating parameters

  35. Interpolating Parameters • The problem turns out to be fundamental to interpolating parameters in screen-space • Uniform steps in screen space  uniform steps in world space Texture image

  36. Linear Interpolation in Screen Space Compare linear interpolation in screen space Without loss of generality, let’s assume that the viewport is located 1 unit away from the center of projection. That is

  37. Linear Interpolation in 3-Space to interpolation in 3-space:

  38. How to make them Mesh Still need to scan convert in screen space... so we need a mapping from t values to s values. We know that the all points on the 3-space edge project onto our screen-space line. Thus we can set up the following equality: and solve for s in terms of t giving: Unfortunately, at this point in the pipeline (after projection) we no longer have z1 and z2 lingering around (Why? Efficiency, don’t need to compute 1/z all the time). However, we do have w1 = 1/z1 and w2 = 1/z2.

  39. Interpolating Parameters We can now use this expression for s to interpolate arbitrary parameters, such as texture indices (u, v), over our 3-space triangle. This is accomplished by substituting our solution for s given t into the parameter interpolation. Therefore, if we premultiply all parameters that we wish to interpolate in 3-space by their corresponding w value and add a new plane equation to interpolate the w values themselves, we can interpolate the numerators and denominator in screen-space. We then need to perform a divide a each step to get to map the screen-space interpolants to their corresponding 3-space values. This is a simple modification to the triangle rasterizer that we developed in class.

  40. 1st idea: Gouraud interp. of texcoords Scan line Replace I to uw, vw, and w, then compute (uw/w, and vw/w)

  41. 1st idea: Gouraud interp. of texcoords Scan line Do same thing for point b. From a and b, interpolate for s

  42. Perspective-Correct Interpolation • In short… • Rather than interpolating u and v directly, interpolate u/z and v/z • These do interpolate correctly in screen space • Also need to interpolate z and multiply per-pixel • Problem: we don’t keep z anymore • Solution: we do keep w  1/z • So…interpolate uw and vw and w, and compute u = uw/w and v = vw/w for each pixel • This unfortunately involves a divide per pixel • http://graphics.lcs.mit.edu/classes/6.837/F98/Lecture21/Slide14.html

  43. Texture Mapping Linear interpolation of texture coordinates Correct interpolation with perspective divide • http://graphics.lcs.mit.edu/classes/6.837/F98/Lecture21/Slide14.html Hill Figure 8.42

  44. Why don’t we notice? Traditional screen-space Gourand shading is wrong. However, you usually will not notice because the transition in colors is very smooth (And we don't know what the right color should be anyway, all we care about is a pretty picture). There are some cases where the errors in Gourand shading become obvious. • When do we notice? • When switching between differentlevels-of-detail representations • At "T" joints.

  45. Dealing with Incorrect Interpolation You can reduce the perceived artifacts of non-perspective correct interpolation by subdividing the texture-mapped triangles into smaller triangles (why does this work?). But, fundamentally the screen-space interpolation of projected parameters is inherently flawed. http://groups.csail.mit.edu/graphics/classes/6.837/F98/Lecture21/Slide15.html

  46. Outline • Types of mappings • Interpolating texture coordinates • Texture Resampling • Broader use of textures

  47. Texture Map Filtering • Naive texture mapping aliases badly • Look familiar? int uval = round(u * W); int vval = round(v * H); int pix = texture.getPixel(uval, vval); Nearest Neighbor Sampling

  48. Texture Map Filtering • Naive texture mapping aliases badly • Look familiar? int uval = round(u * W); int vval = round(v * H); int pix = texture.getPixel(uval, vval); • Actually, each pixel maps to a region in texture • |PIX| < |TEX| • Easy: interpolate (bilinear) between texel values • |PIX| > |TEX| • Hard: average the contribution from multiple texels • |PIX| ~ |TEX| • Still need interpolation!

  49. Mipmap d=3 d=2 d=1 d=0 Let d = |PIX| be a measure of pixel size Sample (u,v,d) Option 1: use the longer edge of the quadrilateral formed by the pixel's cell to approximate the pixel's coverage Using tri-linear interpolation Option 2: use the max of |du/dx|, |du/dy|, |dv/x|, |dv/dy| What’s the memory overhead? Then take logarithm

  50. Storing MIP Maps • One convienent method of storing a MIP map is shown below (It also nicely illustrates the 1/3 overhead of maintaining the MIP map).

More Related