Transcript
Page 1: EECS 487: Interactive Computer Graphics · Computer Graphics Lecture 26: • Bump mapping • Solid and procedural texture Bump Mapping 2D texture map looks unrealistically smooth

EECS487:InteractiveComputerGraphicsLecture26:•  Bumpmapping•  Solidandproceduraltexture

BumpMapping2Dtexturemaplooksunrealisticallysmoothacrossdifferentmaterial,especiallyatlowviewingangle

Foolthehumanviewer:•  perceptionofshapeisdeterminedbyshading,whichisdeterminedbysurfacenormal•  usetexturemaptoperturbthesurfacenormalperfragment•  doesnotactuallyalterthegeometryofthesurface•  shadeeachfragmentusingtheperturbednormalasifthesurfacewereadifferentshape

Spherew/DiffuseTexture SwirlyBumpMap Spherew/DiffuseTexture&BumpMap

BumpMapping

t

TP3

s

Treatthetextureasasingle-valuedheightfunction(heightmap)•  grayscaleimagestoresheight:black,higharea;white,low(orviceversa)

•  differenceinheightsdetermineshowmuchtoperturbninthe(u, v)directionsofaparametricsurface•  ∂b/∂u = bu = (h[s+1, t] − h[s−1, t])/ds•  ∂b/∂v = bv = (h[s, t+1] − h[s, t−1])/dt•  computeanew,perturbednormalfrom(bu,bv)

ComputingPerturbedNormal

!

n = pu × pv

pu =∂∂up(u,v), !pv =

∂∂vp(u,v)

p ' = p(u,v)+ b(u,v)n!⇐ !perturbed!surface

p 'u = ∂∂u

p(u,v)+ b(u,v)n( ) = pu + bun+ b(u,v)nu = pu + bun

p ' v = ∂∂vp(u,v)+ b(u,v)n( ) = pv + bvn+ b(u,v)nv = pv + bvn

0: n ⊥ p

wrinkledsurfacep’(u,v)

wrinklefunction

smoothsurfacep(u,v)

np p

p’ p’p n’

n’

TP3

Blinn

Page 2: EECS 487: Interactive Computer Graphics · Computer Graphics Lecture 26: • Bump mapping • Solid and procedural texture Bump Mapping 2D texture map looks unrealistically smooth

!

n ' = p 'u × p ' v ! ⇐ !normal!of!perturbed!surface

p 'u = pu + bunp ' v = pv + bvnn ' = (pu + bun)× (pv + bvn)

= pu × pv + bu (n× pv )+ bv (pu × n)+ bubv (n× n)= n+ bu (n× pv )− bv (n× pu )

PerturbedNormal

Recall:

a × (kb + c) = k(a × b)+ (a × c)a × b = −b × a

pv

n'

n

pu

n�pv

–n�pu

bu

bv

BumpMapvs.NormalMapComputingn’requirestheheightsamplesfrom4neighbors• eachsamplebyitselfdoesn’tperturbthenormal• anall-whiteheightmaprendersexactlythesameasanall-blackheightmap

Insteadofencodingonlytheheightofapoint,anormalmapencodesthenormalofthedesiredsurface,inthetangentspaceofthesurfaceatthepoint• canbeobtainedfrom:

•  ahigh-resolution3Dmodel•  photos(http://zarria.net/nrmphoto/nrmphoto.html)•  aheight-map(withmorecomplexofflinecomputationofperturbednormals)•  filteredcolortexture(Photoshop,Blender,Gimp,etc.withplugin)

[Hastings-Trew]

NormalMap

Hanrahan09

heightmap normalmap(nx, ny, nz) = (r, g, b)

InterprettheRGBvaluespertexelastheperturbednormal,notheightvalue

[Hastings-Trew]

NormalMapCreationonGimpOnMacOSX,runGimp-2.6.11(not2.8.4)•  loadRGBfile,thenselectFilters�Map�Normalmap

ForWindows,seehttp://code.google.com/p/gimp-normalmap/

Page 3: EECS 487: Interactive Computer Graphics · Computer Graphics Lecture 26: • Bump mapping • Solid and procedural texture Bump Mapping 2D texture map looks unrealistically smooth

NormalMapping:Complications

1.  Normalizednormalsrange[-1, 1],butRGBvaluesrange[0,1],convertnormalsbyn’= (n+1)/2Valuesinnormalmapmustbeconvertedbackbeforeuse:n = n’*2–1

2. Normalsareinobjectspace,sonormalsmustbetransformedwheneverobjectistransformed

Instead,mostimplementationsstorenormalsintangentspace,butthenlightandviewvectorsmustbetransformedtotangentspace

TangentSpaceIsacoordinatesystemattachedtothelocalsurfacewithbasisvectorscomprisingthenormalvector(N),perpendiculartothesurface,andtwovectorstangenttothesurface:thetangent(T)andbitangent(B)WewantTandBtospanourtexture:

[Premecz]N

texture/tangentspace objectspace

[s0, t0] [s1, t1]

[s2, t2]

p0

p1p1

p2

Apointp(s, t) = p0 + (s−s0)T + (t−t0)B3Dvectorsp1−p0 = (s1−s0)T + (t1−t0)B,

andp2−p0 = (s2−s0)T + (t2−t0)BLetΔsi = (si−s0)andΔti = (ti−t0),thenintexturespace,T,B,Nareorthonormal,butnotnecessarilysoinobjectspace,useGram-SchmidtOrthogonalization:B’= N×T;T’= B’×N

TangentSpace

objectspace

p1

p2

p0

[Premecz,Lengyel]

p1 − p0p2 − p0

⎣⎢⎢

⎦⎥⎥=

Δs1 Δt1Δs2 Δt2

⎣⎢⎢

⎦⎥⎥TB

⎣⎢

⎦⎥

TB

⎣⎢

⎦⎥ =

1Δs1Δt2 − Δs2Δt1

Δt2 −Δt1−Δs2 Δs1

⎣⎢⎢

⎦⎥⎥

p1 − p0p2 − p0

⎣⎢⎢

⎦⎥⎥

Ntexture/tangentspace

[s0, t0] [s1, t1]

[s2, t2]

p(s, t) p0

GivenT’,B’,Northonormal,[T’B’N]matrixtransformsfromtangenttoobjectspace([T’B’N]TmatrixinDirect3D)[WeassumeTBNorthonormalinthefigureandinsubsequentslidesandwedropthe“prime”sign]Bitangentissometimescalledbinormal,secondnormal,whichisapplicabletocurves,butnottosurfaces(seelectureonFrenetframe)Seealso:http://www.terathon.com/code/tangent.html

TangenttoObjectSpace

[Lengyel,DreijerMadsen]

ModelViewmatrix

Projectionmatrix

TBNmatrix

Page 4: EECS 487: Interactive Computer Graphics · Computer Graphics Lecture 26: • Bump mapping • Solid and procedural texture Bump Mapping 2D texture map looks unrealistically smooth

Whatwehave:•  per-texelnintangentspacestoredinnormalmap• T,Ninobjectspace•  l,vineyespaceTocomputelightingwithnormalmapintangentspace:1.  transformlandvtotangentspace(how?)2.  sampleper-texelnfromnormalmap3.  computelightingintangentspace

LightingComputation

[Lengyel,DreijerMadsen]

ModelViewmatrix

Projectionmatrix

TBNmatrix

l,v

T,B,N

n

Tangent-SpaceLightingInapp:• loadnormalmapintoitsowntextureunit• computeTpertriangleandassignittoallthreevertices

•  averageoutTofsharedverticesforcurvedsurface• passpertriangleNandTtovertexshader

Invertexshader:• transformNandTfromobjecttoeyespace(how?)• computeBandorthonormaleye-to-tangentmatrix(how?)

• transformlandvtotangentspace,normalize,andpassthem,interpolated,tothefragmentshader

Infragmentshader:• samplenormalmappertexel(n)• computelightingintangentspaceusingnormalizedn,l,andv

Bump/NormalMappingLimitations

SmoothsilhouetteSmoothwhenviewedatlowviewingangleNoself-shadowing/self-occlusion

O’Brien08

Parallax/ReliefMapping

idealparallaxmap

offsetapproximation,badforgrazingangle

offsetlimiting*a.k.a.ParallaxOcclusionMappingorSteepParallaxMapping RTR3

ParallaxMappingandReliefMapping*:•  useheightfieldandviewvectortocomputewhich“bump”isvisible•  howtoavoidcomputingviewvectorandheightfieldintersection?

reliefsampling:linearsearchtofirstpointinsidesurface,thenbinarysearchbetweenthispointandlastpointoutsidesurface

Page 5: EECS 487: Interactive Computer Graphics · Computer Graphics Lecture 26: • Bump mapping • Solid and procedural texture Bump Mapping 2D texture map looks unrealistically smooth

DisplacementMappingInterprettexelasoffsetvectortoactuallydisplacefragments:p’ = p + h(p)n•  correctsilhouettesandshadows• mustbedonebeforevisibilitydetermination•  complicatescollisiondetection,e.g.,ifdoneinvertexshader

TP3

VertexTextureFetch

Marschner08

Traditionally,duringvertexshading,theonlytexture-relatedcomputationiscomputingtexturecoordinatespervertexWithShaderModel3.0,vertexshadercanusetexturemaptoprocessvertices,e.g.,fordisplacementmapping,fluidsimulation,particlesystems

pervertex

texCoordsperfragment

TextureMapping

Alternativedefinition:ageneraltechniqueforstoringandevaluatingfunctionsTexturesarenotjustforshadingparametersanymore!

Marschner

SolidTexturesSolidtextures:•  createa3Dparameterization 2Dmapping 3D“carving”

(s, t, r)forthetexture• mapthisontotheobject•  theeasiestparameterizationistousethemodel-spacecoordinatestoindexintoa3Dtexture(s, t, r) = (x, y, z)

•  like“carving”theobjectfromthematerial

Solidproceduraltextures:• moregenerally,insteadofusingthetexturecoordinatesasanindex,usethemtocomputeafunctionthatdefinesthetexture

Wolfe

Perlin

Page 6: EECS 487: Interactive Computer Graphics · Computer Graphics Lecture 26: • Bump mapping • Solid and procedural texture Bump Mapping 2D texture map looks unrealistically smooth

SolidProceduralTextureExampleInsteadofanimage,useafunction// vertex shader varying vec3 pos; ... pos = gl_Position.xyz; ... // fragment shader varying vec3 pos; ... color = sin(pos.x)*sin(pos.y); ...

Advantagesoverimagetexture:•  infiniteresolutionandsize• morecompactthantexturemaps

•  f(x, y, z)maybeasubroutineinthefragmentshader• noneedtoparameterizesurface• noworriesaboutdistortionanddeformation• objectsappearsculptedoutofsolidsubstance•  cananimatetextures

Disadvantages:•  difficulttomatchexistingtexture•  notalwayspredictable• moredifficulttocodeanddebug•  perhapsslower•  aliasingcanbeaproblem

ProceduralTextures

Peachey

Stripe:coloreachpointoneortheothercolordependingonwherefloor(z)(orfloor(x)orfloor(y))isevenoroddRings:coloreachpointoneortheothercolordependingonwhetherthefloor(distancefromobjectcenteralongtwocoordinates)isevenorodd

SimpleProceduralTextures

Wolfe

Rampfunctions:• ramp(x, y, z, a) = ((float) mod(x, a))/a•  mod(3.75, 2.0)/2.0 = 1.75/2.0 = .875

• ramp(x, y, z) = (sin(x)+1)/2Combination:proceduralcolortablelookup:f(x, y, z) computesanindexintoacolortable,e.g.,usingtherampfunctiontocomputeanindex

SimpleProceduralTextures

Wolfe

Page 7: EECS 487: Interactive Computer Graphics · Computer Graphics Lecture 26: • Bump mapping • Solid and procedural texture Bump Mapping 2D texture map looks unrealistically smooth

WoodTextureClassifytexturespaceintocylindricalshells

f(s, t, r) = (s2 + t2)

Outerringsclosertogether,whichsimulatesthegrowthrateofrealtreesWoodcoloredcolortable• woodmap(0) = brown“earlywood”• woodmap(1) = tan“latewood”

wood(p) = woodmap( f(p) mod 1)p = (s, t, r)

f (s, t, r) = (s2 + t2)

wood(p)

woodmap( f (p))0 1

Hart08

AddingNoiseAddnoisetocylinderstowarpwood:wood(x2 + y2 + A*�

noise( fx *x + ϕx, fy *y + ϕy, fz *z + ϕz))controls:•  frequency( f ):coarsevs.finedetail,numberandthicknessofnoisepeaks,noise( fx x, fy y, fz z)•  phase(ϕ):locationofnoisepeaksnoise(x + ϕx, y + ϕy, z + ϕz)•  amplitude(A):controlsdistortionduetonoiseeffect

connectedpixel.com/blog/texture/woodHart08

noise(p):pseudo-randomnumbergeneratorwiththefollowingcharacteristics: • memoryless whitenoise Perlinnoise•  repeatable•  isotropic• bandlimited(coherent):differenceinvaluesisafunctionofdistance

• noobviousperiodicity•  translationandrotationinvariant(butnotscaleinvariant)

•  knownrange[-1, 1]•  scaleto[0,1]using0.5(noise()+1)

•  abs(noise())createsdarkveinsatzerocrossings

PerlinNoise

Hodgins07

Fractal:•  summultiplecallstonoise:

1-8octavesofturbulence

•  eachadditionaltermaddsfinerdetail,withdiminishingreturn

Turbulence

Hodgins

turbulance(p) = 12i f

noise(2i f ⋅p)i=1

octaves

Page 8: EECS 487: Interactive Computer Graphics · Computer Graphics Lecture 26: • Bump mapping • Solid and procedural texture Bump Mapping 2D texture map looks unrealistically smooth

MarbleTextureUseasinefunctiontocreatethestripes:marble = sin( f * x + A*turbulence(x, y, z))

•  thefrequency( f )ofthesinefunctioncontrolsthenumberandthicknessoftheveins

•  theamplitude(A)oftheturbulencecontrolsthedistortionoftheveins

legakis.net/justin/MarbleApplet/


Top Related