1 / 56

Texture Mapping

Texture Mapping. CMSC435 UMBC. *With lots of borrowing from the usual victims…. Motivation. Flat and Boring. “ Textured ”. Texture Mapping. “ Texture ”. Boring Geometry. Texture  An image that ’ s mapped onto something Texel  Texture pixel (Also, an island in Denmark…).

aayala
Download Presentation

Texture Mapping

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. Texture Mapping CMSC435 UMBC *With lots of borrowing from the usual victims…

  2. Motivation Flat and Boring “Textured”

  3. Texture Mapping “Texture” Boring Geometry Texture  An image that’s mapped onto something Texel  Texture pixel (Also, an island in Denmark…)

  4. Texture Mapping Interesting Geometry

  5. Kinds of Functions • Stuff we might want to map • Color • Opacity • Normals • Displacement • Specularity • Precomputed Lighting

  6. Texture Mapping Mapping Function 2D Texture Coordinate 3D Coordinate Texture Image

  7. Texture Coordinates u • Normalized 2D space • 0-1 on each axis • Letters vary: • U,V are most common • GL/RMan specs like s,t • Typically periodic D3D v Texture Coordinates as RGB OGL t s

  8. 0,0 0,0 0,0 0,0 0,1 0,4 0,8 0,2 1,0 4,0 8,0 2,0 Texture Tiling Scale UV Coordinates  Alter texture frequency

  9. Planar Mapping • For xy aligned plane • Reverse projection 9

  10. Planar Mapping 10

  11. Cylindrical Mapping • For cylinder with point • (r cos Θ, r sin Θ, h z) • Texture coordinates • (u,v) =(Θ/2π, z) 11

  12. Cylindrical Mapping 12

  13. Spherical Mapping • For sphere with point • (r cos Θ sin Φ, r sin Θ sin Φ, r cos Φ) • Texture coordinates 13

  14. Spherical Mapping 14

  15. Mapping onto Parametric Patches Use scaled surface u,v parameters for texture u,v 15

  16. Mapping onto Parametric Patches 16

  17. Mapping onto Polygons Explicit per-vertex coordinates… Wikipedia

  18. Perspective Correction One does not simply interpolate values over a projected triangle… Wikipedia

  19. Perspective Correction Worldspace midpoint Screenspace midpoint The lines sweep out the same points, but at different ‘t’ values

  20. Perspective Correction Project interpolated points != Interpolate projected points B P A Not with ten thousand interpolators could you do this! It is madness!

  21. Perspective Correction • 1/w will interpolate • u/w will interpolate

  22. Perspective Correction • Given vertices (x,y,z,w) and UV coords (u,v) • Compute 1/w at each vertex • Compute u/w, v/w at each vertex • Use multiplication! • Interpolate 1/w, u/w, v/w in screenspace • Divide u/w,v/w by 1/w at each pixel • “Perspective Divide”

  23. Properties of good UV layout: Minimizes stretch Maximize packing efficiency Easy for artist to paint into Unlike that one… Automatic is possible, but manual often preferred Texture Atlas Zhou et al.

  24. Texture Atlas Not always a 1:1 mapping

  25. Discontinuity at UV chart boundaries Solutions: Fix them: Copy/Blend texels across boundary Hide them Armpits, ankles, backs of heads, under clothing Texture Seams Peter Kojesta (Gamasutra)

  26. Environment Mapping Surround scene with maps simulating surrounding detail 26

  27. Distant Reflection Look up reflection direction in reflection or environment map 27

  28. Pick a face based on largest normal component Project onto the face Divide through Use resulting coordinates for 2D lookup Cubic Environment Maps DirectX Documentation

  29. Photograph of shiny sphere Lookup based on x/y coordinates of normal Spherical Environment Maps DirectX Documentation

  30. Point Sampling Map UV coordinate onto texel grid, grab corresponding texel i = floor(u*width) j = floor(v*height) Just like in 1995 Texture Sampling

  31. Point Sampling Point sampling under magnification

  32. Bilinear Filtering Interpolate texels in 2x2 neighborhood Top-left texel: floor(u*(width-1)), floor(v*(height-1)) Weight by fractional coordinates Filtered Sampling

  33. Point Sampling Point sampling under magnification

  34. Linear Sampling Linear sampling under magnification

  35. Array of 2D slices 3D Coordinates (u,v,w) Bilinear tap in each slice using u,v Blend using w 3D Textures

  36. Minification Aliasing! Pixels:Texels < 1: Minification Pixels:Texels ~= 1 Pixels:Texels > 1: Magnification

  37. Anti-aliasing problem Minification Filtering Projected pixel footprint Texel grid Large jumps between pixels. Texture is undersampled…

  38. One solution: Just super-sample it Minification Filtering Problems: - Expensive - Guessing the right sampling rate - Performance death spiral for heavy minification

  39. Prefiltering: Precalculate chain of filtered images Each level is ½ previous resolution Mip-Mapping From Latin: "multum in parvo" (much in little)

  40. Memory overhead is 33% Level i+1 is ½ resolution of i: W/2*H/2=WH/4 So… Mip-Mapping Geometric series

  41. Derive footprint using UV derivatives in screenspace Mip-Mapping du/dy, dv/dy du/dx, dv/dx

  42. Approximate footprint with a square W = Width of square in texels Find mip level matching footprint size Mip-Mapping w

  43. Mip-Mapping Width of square in texels Finest level that won’t alias Base texels per ith level texel Magnification “Just Right” Aliasing 0 Level of detail …

  44. Mip-Mapping Level i Blend bilinear taps at two nearest levels (8 texels accessed) Sometimes incorrectly called “Trilinear” Increasing footprint size Level i+1

  45. Without

  46. With

  47. Getting Derivatives • Rasterizer: 2x2 Quads + Differencing Missing pixels are extrapolated… Each 2x2 quad is self-contained This is a collosal pain in the collective necks of hardware architects

  48. Raytracer Intersect “differential” rays with tangent plane Track derivatives during secondary bounces Getting Derivatives

  49. Mip-Mapping • Advantages: • Cheap approximation to super-sampling • Ensures 1:1 pixel/texel ratio • May actually be FASTER than bilinear • Avoids cache thrashing

  50. Mip-Mapping • Disadvantages: • Needs derivatives • Complicates renderer • 33% Memory overhead • Needs some preprocessing

More Related