1
Texturing
©Anthony Steed 1999, Celine Loscos 2000-2005, Jan Kautz 2006-2009
TextureMapping
• Haveseen:colourcanbeassignedtover7ces• But:don’twanttorepresentallthisdetailwithgeometry
TextureMapping
• Consideringsmalldetails– Wemaynotwanttoaddpolygonstorepresenteverydetail
– Instead,prefertokeepalargepolygonanduseanimagetorepresentthedetails
Images: Wikimedia
2
TheQuestforVisualRealism
Model
Model + Shading
Model + Shading + Textures
TextureMapping
• Increasetheapparentcomplexityofsimplegeometry
• Efficientpackingofflatdetail
• LikewallpaperingorgiK‐wrappingwithstretchypaper
TextureMapping
• Standardtexturemappingmodifiesdiffusecomponent– Pas7ngapictureontothepolygon
• Atextureisa2DarrayoftexelsstoringRGB(orRGBA)components
3
Differencebetweenpixelsandtexels
• Therecanbeadifferentmatchbetweenthepixelsofthedisplaywindowandthetexelofthetexture
Overview
• Texturemapping– InverseandForwardMapping
– Bilinearinterpola7on– Perspec7vecorrec7on
• Mipmapping
• Otherformsofmapping– Environment– Bumpmapping
InverseMapping
• Eachvertexisassociatedwithapointonanimage(u,v)
4
ForwardMapping
• Forpointsintheimage,mapontothepolygon– muchhardertoimplementcorrectly,andhardertomodel
• Inversemappingismuchmorecommonlyused– Most3DmodelersoutputU,Vco‐ordinatesfortextureapplica7on
QuickandDirtySolu7on
• YetmoreparametersintheET!• Bilinearinterpola7onofu&vdownpolygonedges,andacrossscan‐lines
• Works,butisveryugly– Doesnotconsiderfore‐shorteningofimageindepth
TheProblem
• SameproblemexistswithPhongandGouraudshading,butMUCHlessno7ceable
5
TheSolu7on
• Needtocompensateforfore‐shorteningbyinterpola7ngover1/z
• Interpolate(u’,v’,q)whereq=1/z– Atver7cesweknow(u1,v1,z1),(u2,v2,z2)– Interpolatebetween(u1/z1,v1/z1,1/z1)and(u2/z2,v2/z2,1/z2)toget(u’,v’,q)
– Restoreu,v,bydividingu’andv’byq
SanityCheck• Atp0
(u’,v’,q)=(0,0,0.1)
• Atp1(u’,v’,q)=(0,0.05,0.05)
• Onscanline10(u’,v’,q)=(0,0.025,0.075)(u,v)=(0,0.333)
z=1/0.075=13.33p0=(10,5,10,0,0)
pi=(xi,yi,zi,ui,vi)
p1=(15,15,20,0,1) scanlines
Y=5
Y=10
Y=15
MinorIssues
• Nowhavetwodivisionsperpixel!• Someop7misa7ons
– onlydothedivisionatendofthespansandinterpolateacrossspans
– oronlydothedivisioneverynpixels• Remainingproblem
– wehavenottoucheduponhowtoclipu,vvaluesin3Dor2D!
6
MajorIssues
• Pickingyourpixel!
image
Sampling
• Apixelmapstoanon‐rectangularregion• Usuallyonlyperformmaponcentreofpixel• S7llhaveaproblemofover‐sampling(sametexelmapstoseveralpixels)orunder‐samplingtheimage(pixelsonlysparselysamplethetexels)
Filtering
• Nearestneighbour
• Pickpixelwithclosestcentre
• Bilinear
• Weightedaveragebasedondistancetopixelcentre
7
Filtering
• Bilinearfiltering(par7ally)solvestheoversamplingproblemsinceitprovidessmoothshadingbetweenpixels
scanline
Mip‐Mapping
• Whenundersamplingweusemip‐mapping• Resampleimageatlowerresolu7on
• Createa“pyramid”oftextures.
• Interpolatetexturebetweentwoadjacentlayers
TexturePyramid
128x128 64x64
32x32 1x1 ...
8
Sampling
• Choosetwolayersbasedontexelspan– Choiceismadeselec7ngthetwolevelswheretheduanddvfordxanddyareclosesttoone
• Interpolatebetweenfourpixelsinhigherlayerandfour(orone)inlowerlayer
FilteringExamples
Images from: http://www.3dcenter.org/artikel/2003/10-26_a_english.php
Nearest Neighbor
Bilinear Filtering Bilinear Filtering
(distinct mip map levels)
Trilinear Filtering (Mip mapping)
MoreExamples
Nearest Neighbor Mip Mapping
9
TextureMappingDifficul7es
• Tedioustospecifytexturecoordinates
• Acquiringtexturesissurprisinglydifficult– Photographshaveprojec7vedistor7ons
– Varia7onsinreflectanceandillumina7on
– Tilingproblems
OtherFormsofTextureMapping
• BumpMapping• DisplacementMapping
• EnvironmentMapping
• Usetexturestoalterthesurfacenormal– Doesnotchangetheactualshapeofthesurface– Justshadedasifitwereadifferentshape
BumpMapping
Spherew/DiffuseTexture SwirlyBumpMap Spherew/DiffuseTexture&BumpMap
10
BumpMapping
• Treatthetextureasasingle‐valuedheightfunc7on• Computethenormalfromthepar7alderiva7vesinthetexture
AnotherBumpMapExample
Cylinderw/DiffuseTextureMap
BumpMap
Cylinderw/TextureMap&BumpMap
What'sMissing?
• Therearenobumpsonthesilhoueneofabump‐mappedobject
• Bumpmapsdon’tallowself‐occlusionorself‐shadowing
11
DisplacementMapping
• Usethetexturemaptoactuallymovethesurfacepoint
• Thegeometrymustbedisplacedbeforevisibilityisdetermined
DisplacementMapping
Imagefrom:
GeometryCachingforRay‐TracingDisplacementMaps
byManPharrandPatHanrahan.
Notethedetailedshadowscastbythestones
EnvironmentMaps
• Wecansimulatereflec7onsbyusingthedirec7onofthereflectedraytoindexasphericaltexturemapat"infinity".
• Assumesthatallreflectedraysbeginfromthesamepoint.
12
What'stheBestLayout?
CubeMap
EnvironmentMappingExample
TerminatorII
Recap
• Rasteriza7on– Z‐Bufferforvisibility– Needtodoperspec7vecorrectrasteriza7on
• TextureMapping– Forward/backward– Addsdetail– Needtotakecareofsamplingissues