eecs 487: interactive computer...
TRANSCRIPT
EECS487:InteractiveComputerGraphicsLecture30:• Environmentmapping• Radiancemap• Accumulationbuffer
EnvironmentMapping
Thekeytodepictingashiny-lookingmaterialistoprovidesomethingforittoreflect• properreflectionrequiresraytracing,expensive• canbesimulatedwithapre-renderedenvironment,storedasatexture• imagineobjectisenclosedinaninfinitelylargesphereorcube• raysarebouncedoffobjectintoenvironmenttodeterminecolor
EM*surfacecolor=reflectionmapping
Hanrahan
EnvironmentMappingSteps:• loadenvironmentmap• foreachreflectivepixel,computeitsnormal• computethereflectionvectorfromthenormalandviewvectors• usethereflectionvectortocomputeanindexintotheenvironmentmapinthereflectiondirection• note:we’renotcomputingrayintersectionbetweenthereflectionvectorandtheenvironment!
• usethetexelattheindextocolorthepixel
Shortcomings:• nointer-objectreflection�workswellwhenthere’sjustasingleobject• noself-reflection
Jensenetal.
EnvironmentMappingModel:• environmentisinfinitelyfaraway
• allreflectionsasseenfromthesame,farawayviewpoint:• objectapproximatedasaninfinitelysmall,perfectlymirroringballconcentricwiththeobject
• reflectedcolorcomputedonlyfromthedirectionofreflection• notfromthepositiononsurface
• determinedbysurfacenormal
• noray-environmentintersectioncomputation
CubeMapMostpopularandfastest:easytoproducewithrenderingsystemorbyphotographyfromcenterofobject,onceforeachsideofcube
Simpletexture-coordinatescalculation
Texturecreationfromscene:• viewindependent• uniformsampling/resolution
Supportsbilinearfilteringandmipmapping
TP3
t
s
ts
t
s
y ComputingReflectionSteps:1. computereflectionvector,r• efromeyetovertex• nnormalineyecoordinates• r = e – 2n(n•e)
2. reflectionisafunctionofonedirection:largestabsolutevalueofr’scomponentsdeterminesthecubefacetoreflect• example:r = (5, −1, 2)gives+xasthereflectedface
3. dividerbythevalueofthe“reflection”coordinate(5)andmapto[0,1]�(s, t) = ((y + x)/2x, (z + x)/2x)�
= ((−1/5 + 1)/2, (2/5 + 1)/2)�= (0.4, 0.7)
+z +x -x -z
+y
-y
x
y
z
ne
r
CubeMap:DisadvantagesAngularsizeoftexelvariesacrossacubefaceUsuallydoesn’tinterpolateacrosscubefaces�cubeedgesarereflectedonobject
ToolssuchasAMD’sCubeMapGencanfixtheseproblems
RTR3
θθ
MethodstoCreateEM• Cubemap
• Latitude/longitudeprojectionsmap• createdbypainting• oversamplingofpolescomparedtotheequator
• Sphericalmap• gazingball• fisheyelens
• Parabolicmap
GazingBall(LightProbe)Createdbyphotographingareflectivesphere
Mapsalldirectionstoacircle
Reflectionindexedbynormal
Texturecreationfromscene:• resolutionfunctionoforientation• viewdependent:mustregenerateEMwhencameramovesorwillseethesamething
Hanrahan09
SphereMappingUseatexturemapofasphereviewedfrominfinityusertolookuptexel• theeyevectorsareparallel• rdeterminedonlybysurfacenormal
Want:computetexturecoordinates(s, t)fromr• textureisnotreallypastedtotheinsideoftheenvironmentsphere,butprojected(nextslide)• objectcanbeapproximatedasaninfinitelysmall,perfectlymirroringballconcentricwiththeobject• mapthenormalsofanobjecttothecorrespondingnormalsofasphere
ne r = (x, y, z)
environmentmaponasphere
viewpoint
object
h
Zhang08
Computing(s, t)fromrObservation:ncanbeexpressedintermsofrande:
r = e − 2n(n i e)r − e =αn
-e
s
RTR3Zhang08
αn = r − e =
xyz0
⎡
⎣
⎢⎢⎢⎢
⎤
⎦
⎥⎥⎥⎥
−
00−10
⎡
⎣
⎢⎢⎢⎢
⎤
⎦
⎥⎥⎥⎥
! where! αn = p = x 2 + y2 + (z +1)2
αnαn
=
x / py / p
(z +1) / p0
⎡
⎣
⎢⎢⎢⎢⎢
⎤
⎦
⎥⎥⎥⎥⎥
!since! r = 1,!p = 2(z +1)
texture
Computing(s, t)fromr
(1, 1)
(–1, –1)
h =
hx
hy
1− hx2 − hy
2
0
⎡
⎣
⎢⎢⎢⎢⎢
⎤
⎦
⎥⎥⎥⎥⎥
hx = x p hy = y p
s = x2p
+ 12
t = y2p
+ 12
!
αnαn
=
x / py / p
(z +1) / p0
⎡
⎣
⎢⎢⎢⎢⎢
⎤
⎦
⎥⎥⎥⎥⎥
where!p = 2(z +1)
Zhang08
!
scaled!to!texture!space![0,1]:
s = 12hx +
12!!!!!!!t = 1
2hy +
12
unitsphereineyespace,gazingdown–z:
-e
s
RTR3h
hx
hy
texture
ParabolicMap
RTR3
Usesz-componentofreflectedvectortodeterminetexel
Texturecreationfromscene:• viewindependent• uniformsampling• mapshardtocreate
Heidrich&Seidel
OpenGL2.1Spheremap: // insert where the texture is created glTexGeni(GL_S,GL_TEXTURE_GEN_MODE,GL_SPHERE_MAP); glTexGeni(GL_T,GL_TEXTURE_GEN_MODE,GL_SPHERE_MAP); glEnable(GL_TEXTURE_GEN_S); glEnable(GL_TEXTURE_GEN_T); Cubemap:• loadsiximages,oneforeachfacewith:glTexImage2D(target)
• texturecoordinatesgeneratedusingglTexGen*(…,GL_TEXTURE_GEN_MODE,GL_REFLECTION_MAP); glEnable(GL_TEXTURE_CUBE_MAP);
Functionsdeprecated
CubeMappingwithGLSL==== OpenGL app: initialize texture sampler to texture unit 0 ==== GLuint cubeid = glGetUniformLocation(myprog, “mycube”); glUniform1i(cubeid,0); // assign texure unit 0 to cubeid ==================== // vertex shader: compute r ================= varying vec3 r; void main() { gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; vec3 n = normalize(gl_NormalMatrix * gl_Normal); vec4 e = gl_ModelViewMatrix * gl_Vertex; r = reflect(-e,n); } ==================== // fragment shader =========================== varying vec3 r; uniform samplerCube mycube; void main() { gl_FragColor = textureCube(mycube, r); }
Angel09
LimitationofEM
Environmentmapassumesobjectinfinitesimallysmallandreflectionsinfinitelyfaraway
EMerrorshardtonoticeonnon-flatobjects,butdoesn’tworkwellforflat/planarsurfaces,• reflectedraysusuallydonotvarybymorethanafewdegrees�asmallpartoftheEMisappliedtoalargearea• worsewithorthographicprojection:allorthographicreflectedvectorsareparallel
CansimulatereflectionfromstillwaterButnotwavywater(viabumpmap)
1. reflectiondoesn’tmeetboat2. reflectionbehindtheboat3. environmentmapmagnified
LimitationsofEM
env.map
Hart08
BoatreflectedinwavywaterrenderedusinganenvironmentmapCanyoufindthreethingswrongwiththispicture?
DiffuseReflectanceWithEM,eachtexelisadirectionallightsource:• forperfectlyspecularsurfaces,onlylightinginthereflecteddirectioncontributestolighting• inthediffusecase,lightingisintegratedoverthehemisphereaboveapoint• costofcomputingdiffusecolorofapoint(c)isontheorderofthenumberoftexelsintheEM!
• kdirectionallights(texels)• l(j): directionoflightj• s(j):intensityoflightj• n:surfacenormal• m:materialreflectance
Schulze
c = m s( j ) max((l( j )in),0)j=1...k∑
IrradianceMapPrecomputationofdiffusereflection
Observations:• irradianceatvariouspointsdiffersonlyonincomingdirectionsandthesurfacenormal• allpointswiththesamenormalreflectthesameirradiance• (methodlimitedtolightingcontributionfromadistantenvironment!)
Idea:• precomputesumforallpossiblenormals• storeresultsinasecondenvironmentmapcalledthediffuse(irradianceenvironment)map• radiancemapindexedbysurfacenormal
r
n
IlluminationmapIrradiancemap
Schulze,Ramamoorthi
Moregenerally,giventheBRDFofthesurface,theReflectanceEquationis:needto(pre-)computeirradiance*BRDF
GlossySurfaces lv
ρωi
ωo
Ramamoorthi,Kautz
L(ωo ) = L(−π 2
π 2
∫ ωi )ρ(ωi ,ωo )dωi
Reflected Light (ρ)
InteractiveVisualFXAnti-aliasing:• accumulationbufferCameraeffects:• motionblur• depthoffield• accumulationbuffer
Shadows:• projected(soft)shadows• stencilbuffer• depthbufferasshadowmap
Otherglobalilluminationeffects:• reflection• refraction• colorbleed(onebounce)• caustics
Environmentaleffects:• participatingmediumandvolumerendering• particlesystems• fluiddynamics
LimitationsofGL_MULTISAMPLE
Nocontrolof:• numberofsamples,can’thaveadaptivequality/performancetrade-off• samplelocations:can’tdostochasticsamplingoradaptivesamplingorusedifferentsamplingpatterns(perhapsdifferentperpixel)• averagingfunction(filtershapesandextents)WecanusetheaccumulationbuffertoaddressmostoftheshortcomingsofGL_MULTISAMPLE(exceptforper-pixelsamplingpattern,andatthecostofslowerperformance)
TheAccumulationBuffer
Samesizeasthecolorbuffer,usedtohold(accumulate)resultsfrompartialcomputationDeprecatedsinceOpenGL3.1
Instead,useframebufferobjectwithfloating-pointpixelformat• sameconceptasaccumulationbuffer
MultisamplingwiththeAccumulationBuffer
Akeley07
glutInitDisplayMode(… | GLUT_ACCUM); // set up desired rendering modes glAccum(GL_LOAD, 0.0); // or glClear(GL_ACCUM_BUFFER_BIT); for (int i=0; i<n; ++i) {
// specify sampling location for the i-th pass // by offsetting the frustrum // (google accpersp.c for the redbook source samples) render(scene); // to color buffer // accumulate the color buffer (multiplied by // a weight) to the accumulation buffer glAccum(GL_ACCUM, sampleweight[i]);
} // copy the accumulation buffer to color buffer glAccum(GL_RETURN, 1.0);
Hart,RTR3
Samplethescenektimes,placethemovingobject(s)atanewlocationeachtime
Eachsamplecontributes1/k-thofthefinalcolor:glAccum(GL_ACCUM, 1/k)
MotionBlurSamplethescenektimes,eachtimewithaslightlydifferenteyeposition,butsuchthatthefocalplaneboundedbythefrustrumisthesameineachsample
Eachsamplecontributes1/k-thofthefinalcolor:glAccum(GL_ACCUM, 1/k)
focalplaneHart
DepthofField
ShadowsforInteractiveRenderingLet’sstartwithhardshadowsPhongilluminationmodelwithhardshadows:(k:lightnumber,notexponentiation!)• includesvisibilityterm(v(k) = 1),ifalightcan“see”thepoint• ifpointisinshadow,onlyambienttermappliesHowtodetermineifpointisinshadow?
ct = cg + me + sspot(k )
k=1
n
∑ (ca(k ) + v(k ) f (d (k ) )(cd
(k ) + cs(k ) ))
Merrell
ComputingShadows
Planarreceiver• projectedshadows
Non-planarreceiver• shadowmaps• projectivetexture• shadowvolumes
Allperformedinreal-time/interactive(sortof)
ProjectedShadowsWaystothinkaboutshadows:• asadarkvolumeofspace• asplacesnotseenfromalightsourcelookingatthescene• asaseparateobject• projectobjecttothereceiveranddrawitasecondtime
Akenine-Möller02,Durand
Worksonlywithpointlights Forprojectionontoy = 0:andplanarreceivers• projectoccludersontoreceivers• usingshadowprojectionmatrix
What’stheprojectionmatrixforplanarreceiveringeneral,otherthanfory = 0?
ProjectedShadows
x
y
l
v
p lx vx
p =Mv
pxpypzpw
⎡
⎣
⎢⎢⎢⎢⎢
⎤
⎦
⎥⎥⎥⎥⎥
=
ly −lx 0 0
0 0 0 00 −lz ly 0
0 −1 0 ly
⎡
⎣
⎢⎢⎢⎢⎢
⎤
⎦
⎥⎥⎥⎥⎥
vxvyvz1
⎡
⎣
⎢⎢⎢⎢⎢
⎤
⎦
⎥⎥⎥⎥⎥
lylx − px
=vy
vx − pxlyvx − ly px = lxvy − pxvylyvx − lxvy = px (ly − vy )
px =lyvx − lxvyly − vy
Pointpisattheintersectionofrayandplaneif(mixingnotation):nip + D = 0, D = −niani L + t(v −L)( )+ D = 0
t = − D + niLni(v −L)
p = L − D + niLni(v −L)
⎛⎝⎜
⎞⎠⎟(v −L)
Shadowprojectionmatrix(M)cannowbecomputed:p =Mv
M =
niL + D − Lxnx −Lxny −Lxnz −LxD
−Lynx niL + D − Lyny −Lynz −LyD
−Lznx −Lzny niL + D − Lznz −LzD
−nx −ny −nz niL
⎡
⎣
⎢⎢⎢⎢⎢
⎤
⎦
⎥⎥⎥⎥⎥
ProjectedShadows
L
vp
plane:n•p + D = 0, D = −n•a
ray:L + t(v − L)
Yu Hart
Samplethescenektimes,withobjectprojectedontothereceiver,eachtimewithaslightlydifferentlightposition
Eachsamplecontributes1/k-thofthefinalshadowcolor:glAccum(GL_ACCUM, 1/k)
SoftShadows