texturing - ucl computer science - ucl · 2009. 11. 4. · forward mapping • for points in the...

12
1 Texturing ©Anthony Steed 1999, Celine Loscos 2000-2005, Jan Kautz 2006-2009 Texture Mapping Have seen: colour can be assigned to ver7ces But: don’t want to represent all this detail with geometry Texture Mapping Considering small details We may not want to add polygons to represent every detail Instead, prefer to keep a large polygon and use an image to represent the details Images: Wikimedia

Upload: others

Post on 21-Apr-2021

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Texturing - UCL Computer Science - UCL · 2009. 11. 4. · Forward Mapping • For points in the image, map onto the polygon – much harder to implement correctly, and harder to

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

Page 2: Texturing - UCL Computer Science - UCL · 2009. 11. 4. · Forward Mapping • For points in the image, map onto the polygon – much harder to implement correctly, and harder to

2

TheQuestforVisualRealism

Model

Model + Shading

Model + Shading + Textures

TextureMapping

•  Increasetheapparentcomplexityofsimplegeometry

•  Efficientpackingofflatdetail

•  LikewallpaperingorgiK‐wrappingwithstretchypaper

TextureMapping

•  Standardtexturemappingmodifiesdiffusecomponent– Pas7ngapictureontothepolygon

•  Atextureisa2DarrayoftexelsstoringRGB(orRGBA)components

Page 3: Texturing - UCL Computer Science - UCL · 2009. 11. 4. · Forward Mapping • For points in the image, map onto the polygon – much harder to implement correctly, and harder to

3

Differencebetweenpixelsandtexels

•  Therecanbeadifferentmatchbetweenthepixelsofthedisplaywindowandthetexelofthetexture

Overview

•  Texturemapping–  InverseandForwardMapping

– Bilinearinterpola7on– Perspec7vecorrec7on

•  Mipmapping

•  Otherformsofmapping– Environment– Bumpmapping

InverseMapping

•  Eachvertexisassociatedwithapointonanimage(u,v)

Page 4: Texturing - UCL Computer Science - UCL · 2009. 11. 4. · Forward Mapping • For points in the image, map onto the polygon – much harder to implement correctly, and harder to

4

ForwardMapping

•  Forpointsintheimage,mapontothepolygon– muchhardertoimplementcorrectly,andhardertomodel

•  Inversemappingismuchmorecommonlyused– Most3DmodelersoutputU,Vco‐ordinatesfortextureapplica7on

QuickandDirtySolu7on

•  YetmoreparametersintheET!•  Bilinearinterpola7onofu&vdownpolygonedges,andacrossscan‐lines

•  Works,butisveryugly– Doesnotconsiderfore‐shorteningofimageindepth

TheProblem

•  SameproblemexistswithPhongandGouraudshading,butMUCHlessno7ceable

Page 5: Texturing - UCL Computer Science - UCL · 2009. 11. 4. · Forward Mapping • For points in the image, map onto the polygon – much harder to implement correctly, and harder to

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!

Page 6: Texturing - UCL Computer Science - UCL · 2009. 11. 4. · Forward Mapping • For points in the image, map onto the polygon – much harder to implement correctly, and harder to

6

MajorIssues

•  Pickingyourpixel!

image

Sampling

•  Apixelmapstoanon‐rectangularregion•  Usuallyonlyperformmaponcentreofpixel•  S7llhaveaproblemofover‐sampling(sametexelmapstoseveralpixels)orunder‐samplingtheimage(pixelsonlysparselysamplethetexels)

Filtering

•  Nearestneighbour

•  Pickpixelwithclosestcentre

•  Bilinear

•  Weightedaveragebasedondistancetopixelcentre

Page 7: Texturing - UCL Computer Science - UCL · 2009. 11. 4. · Forward Mapping • For points in the image, map onto the polygon – much harder to implement correctly, and harder to

7

Filtering

•  Bilinearfiltering(par7ally)solvestheoversamplingproblemsinceitprovidessmoothshadingbetweenpixels

scanline

Mip‐Mapping

•  Whenundersamplingweusemip‐mapping•  Resampleimageatlowerresolu7on

•  Createa“pyramid”oftextures.

•  Interpolatetexturebetweentwoadjacentlayers

TexturePyramid

128x128 64x64

32x32 1x1 ...

Page 8: Texturing - UCL Computer Science - UCL · 2009. 11. 4. · Forward Mapping • For points in the image, map onto the polygon – much harder to implement correctly, and harder to

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

Page 9: Texturing - UCL Computer Science - UCL · 2009. 11. 4. · Forward Mapping • For points in the image, map onto the polygon – much harder to implement correctly, and harder to

9

TextureMappingDifficul7es

•  Tedioustospecifytexturecoordinates

•  Acquiringtexturesissurprisinglydifficult–  Photographshaveprojec7vedistor7ons

–  Varia7onsinreflectanceandillumina7on

–  Tilingproblems

OtherFormsofTextureMapping

•  BumpMapping•  DisplacementMapping

•  EnvironmentMapping

•  Usetexturestoalterthesurfacenormal– Doesnotchangetheactualshapeofthesurface–  Justshadedasifitwereadifferentshape

BumpMapping

Spherew/DiffuseTexture SwirlyBumpMap Spherew/DiffuseTexture&BumpMap

Page 10: Texturing - UCL Computer Science - UCL · 2009. 11. 4. · Forward Mapping • For points in the image, map onto the polygon – much harder to implement correctly, and harder to

10

BumpMapping

•  Treatthetextureasasingle‐valuedheightfunc7on•  Computethenormalfromthepar7alderiva7vesinthetexture

AnotherBumpMapExample

Cylinderw/DiffuseTextureMap

BumpMap

Cylinderw/TextureMap&BumpMap

What'sMissing?

•  Therearenobumpsonthesilhoueneofabump‐mappedobject

•  Bumpmapsdon’tallowself‐occlusionorself‐shadowing

Page 11: Texturing - UCL Computer Science - UCL · 2009. 11. 4. · Forward Mapping • For points in the image, map onto the polygon – much harder to implement correctly, and harder to

11

DisplacementMapping

•  Usethetexturemaptoactuallymovethesurfacepoint

•  Thegeometrymustbedisplacedbeforevisibilityisdetermined

DisplacementMapping

Imagefrom:

GeometryCachingforRay‐TracingDisplacementMaps

byManPharrandPatHanrahan.

Notethedetailedshadowscastbythestones

EnvironmentMaps

•  Wecansimulatereflec7onsbyusingthedirec7onofthereflectedraytoindexasphericaltexturemapat"infinity".

•  Assumesthatallreflectedraysbeginfromthesamepoint.

Page 12: Texturing - UCL Computer Science - UCL · 2009. 11. 4. · Forward Mapping • For points in the image, map onto the polygon – much harder to implement correctly, and harder to

12

What'stheBestLayout?

CubeMap

EnvironmentMappingExample

TerminatorII

Recap

•  Rasteriza7on– Z‐Bufferforvisibility– Needtodoperspec7vecorrectrasteriza7on

•  TextureMapping– Forward/backward– Addsdetail– Needtotakecareofsamplingissues