cmsc427 advanced shading – getting global illumination by local...

67
CMSC427 Advanced shading – getting global illumination by local methods Credit: slides Prof. Zwicker

Upload: others

Post on 19-Apr-2020

10 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CMSC427 Advanced shading – getting global illumination by local …reastman/slides/L17P1Advanced... · 2017-11-14 · outside shadow volume 1.Allocate a counter per pixel 2.Cast

CMSC427Advancedshading–gettingglobalilluminationbylocalmethods

Credit:slidesProf.Zwicker

Page 2: CMSC427 Advanced shading – getting global illumination by local …reastman/slides/L17P1Advanced... · 2017-11-14 · outside shadow volume 1.Allocate a counter per pixel 2.Cast

• Shadows• Environmentmaps• Reflectionmapping• Irradianceenvironmentmaps• Ambientocclusion• Reflectionandrefraction• Toonshading

Topics

Page 3: CMSC427 Advanced shading – getting global illumination by local …reastman/slides/L17P1Advanced... · 2017-11-14 · outside shadow volume 1.Allocate a counter per pixel 2.Cast

Why are shadows important?

• Cuesonscenelighting

3

Page 4: CMSC427 Advanced shading – getting global illumination by local …reastman/slides/L17P1Advanced... · 2017-11-14 · outside shadow volume 1.Allocate a counter per pixel 2.Cast

Why are shadows important?

• Contactpoints• Depthcues

4

Page 5: CMSC427 Advanced shading – getting global illumination by local …reastman/slides/L17P1Advanced... · 2017-11-14 · outside shadow volume 1.Allocate a counter per pixel 2.Cast

Why are shadows important?

• Realism

Without self-shadowing Without self-shadowing

5

Page 6: CMSC427 Advanced shading – getting global illumination by local …reastman/slides/L17P1Advanced... · 2017-11-14 · outside shadow volume 1.Allocate a counter per pixel 2.Cast

Terminology

• Umbra:fullyshadowedregion• Penumbra:partiallyshadowedregion

(area) light source

receiver shadow

occluder

umbra

penumbra

6

Page 7: CMSC427 Advanced shading – getting global illumination by local …reastman/slides/L17P1Advanced... · 2017-11-14 · outside shadow volume 1.Allocate a counter per pixel 2.Cast

Hard and soft shadows

• Pointanddirectionallightsleadtohardshadows,nopenumbra

• Arealightsourcesleadtosoftshadows,withpenumbra

point directional area

umbra penumbra7

Page 8: CMSC427 Advanced shading – getting global illumination by local …reastman/slides/L17P1Advanced... · 2017-11-14 · outside shadow volume 1.Allocate a counter per pixel 2.Cast

Hard and soft shadows

Hard shadow,point light source

Soft shadow,area light source

8

Page 9: CMSC427 Advanced shading – getting global illumination by local …reastman/slides/L17P1Advanced... · 2017-11-14 · outside shadow volume 1.Allocate a counter per pixel 2.Cast

Shadows for interactive rendering• Focusonhardshadows

• Softshadowsoftentoohardtocomputeininteractivegraphics

• Twomaintechniques• Shadowmapping• Shadowvolumes

• Manyvariations,subtleties• Stillactiveresearcharea

9

Page 10: CMSC427 Advanced shading – getting global illumination by local …reastman/slides/L17P1Advanced... · 2017-11-14 · outside shadow volume 1.Allocate a counter per pixel 2.Cast

Shadow mappinghttp://en.wikipedia.org/wiki/Shadow_mappinghttp://www.opengl-tutorial.org/intermediate-tutorials/tutorial-16-shadow-mapping/

Mainidea• Scenepointislitbylightsourceifitisvisible fromlightsource

• Determinevisibilityfromlightsourcebyplacingcameraatlightsourceposition andrenderingscene

Scene points are lit if visible from light source

Determine visibility from light source by placing camera

at light source position10

Page 11: CMSC427 Advanced shading – getting global illumination by local …reastman/slides/L17P1Advanced... · 2017-11-14 · outside shadow volume 1.Allocate a counter per pixel 2.Cast

Two pass algorithm

Firstpass• Renderscenebyplacingcameraatlightsourceposition

• Storedepthimage(shadowmap)

Depth image seen from light source

depth valuein shadow map

Page 12: CMSC427 Advanced shading – getting global illumination by local …reastman/slides/L17P1Advanced... · 2017-11-14 · outside shadow volume 1.Allocate a counter per pixel 2.Cast

Secondpass• Renderscenefromcamera(eye)position

• Ateachpixel,comparedistancetolightsource(yellow)withvalueinshadowmap(red)

• Ifyellowdistanceislargerthanred,weareinshadow

• Ifdistanceissmallerorequal,pixelislit

Two pass algorithm

Final image with shadows

vb is in shadow pixel seen

from eye vb

depth valuein shadow map

12

Page 13: CMSC427 Advanced shading – getting global illumination by local …reastman/slides/L17P1Advanced... · 2017-11-14 · outside shadow volume 1.Allocate a counter per pixel 2.Cast

Issues

• Limitedfieldofviewofshadowmap• Z-fighting• Samplingproblems

13

Page 14: CMSC427 Advanced shading – getting global illumination by local …reastman/slides/L17P1Advanced... · 2017-11-14 · outside shadow volume 1.Allocate a counter per pixel 2.Cast

Limited field of view

• Whatifascenepointisoutsidethefieldofviewoftheshadowmap?

field of view of shadow map

Page 15: CMSC427 Advanced shading – getting global illumination by local …reastman/slides/L17P1Advanced... · 2017-11-14 · outside shadow volume 1.Allocate a counter per pixel 2.Cast

Limited field of view

• Whatifascenepointisoutsidethefieldofviewoftheshadowmap?

• Usesixshadowmaps,arrangedinacube

• Requiresrenderingpassforeachshadowmap!

shadowmaps

Page 16: CMSC427 Advanced shading – getting global illumination by local …reastman/slides/L17P1Advanced... · 2017-11-14 · outside shadow volume 1.Allocate a counter per pixel 2.Cast

• Intheory,depthvaluesforpointsvisiblefromlightsourceareequalinbothrenderingpasses

• Becauseoflimitedresolution,depthofpixelvisiblefromcameracouldbelargerthanshadowmapvalue

• Needtoadd biasinfirstpasstomakesurepixelsarelit

z-fighting

Camera image

Shadow mapImagepixels

Shadow mappixels Pixel is

consideredin shadow!

Depth of pixel visiblefrom camera

Depth of shadow map

Page 17: CMSC427 Advanced shading – getting global illumination by local …reastman/slides/L17P1Advanced... · 2017-11-14 · outside shadow volume 1.Allocate a counter per pixel 2.Cast

Solution

• Addbias whenrenderingshadowmap• Movegeometryawayfromlightbysmallamount

• Findingcorrectamountofbiasistricky

Correct bias Not enough bias Too much bias17

Page 18: CMSC427 Advanced shading – getting global illumination by local …reastman/slides/L17P1Advanced... · 2017-11-14 · outside shadow volume 1.Allocate a counter per pixel 2.Cast

Bias

Correct

Not enough Too much

18

Page 19: CMSC427 Advanced shading – getting global illumination by local …reastman/slides/L17P1Advanced... · 2017-11-14 · outside shadow volume 1.Allocate a counter per pixel 2.Cast

Sampling problems

• Shadowmappixelmayprojecttomanyimagepixels

• Uglystair-steppingartifacts

19

Page 20: CMSC427 Advanced shading – getting global illumination by local …reastman/slides/L17P1Advanced... · 2017-11-14 · outside shadow volume 1.Allocate a counter per pixel 2.Cast

Solutions

• Increaseresolutionofshadowmap• Notalwayssufficient

• Splitshadowmapintoseveralslices• Tweakprojectionforshadowmaprendering

• Lightspaceperspectiveshadowmaps(LiSPSM)http://www.cg.tuwien.ac.at/research/vr/lispsm/

• WithGLSLsourcecode!

• CombinationofsplittingandLiSPSM• Basisformostseriousimplementations• Listofadvancedtechniquessee

http://en.wikipedia.org/wiki/Shadow_mapping

20

Page 21: CMSC427 Advanced shading – getting global illumination by local …reastman/slides/L17P1Advanced... · 2017-11-14 · outside shadow volume 1.Allocate a counter per pixel 2.Cast

LiSPSM

Basic shadow map Light space perspectiveshadow map

21

Page 22: CMSC427 Advanced shading – getting global illumination by local …reastman/slides/L17P1Advanced... · 2017-11-14 · outside shadow volume 1.Allocate a counter per pixel 2.Cast

Percentage closer filtering

• Goal:avoidstair-steppingartifacts• Similartotexturefiltering,butwithatwist

http://http.developer.nvidia.com/GPUGems/gpugems_ch11.html

Simpleshadow mapping Percentage closer filtering

22

Page 23: CMSC427 Advanced shading – getting global illumination by local …reastman/slides/L17P1Advanced... · 2017-11-14 · outside shadow volume 1.Allocate a counter per pixel 2.Cast

Percentage closer filtering

• Insteadoflookinguponeshadowmappixel,lookupseveral

• Performdepthtestforeachshadowmappixel• Computepercentageoflitshadowmappixels

23

Page 24: CMSC427 Advanced shading – getting global illumination by local …reastman/slides/L17P1Advanced... · 2017-11-14 · outside shadow volume 1.Allocate a counter per pixel 2.Cast

Percentage closer filtering

• Supportedinhardwareforsmallfilters(2x2shadowmappixels)

• Canuselargerfilters(lookupmoreshadowmappixels)atcostofperformancepenalty

• Fakesoftshadows• Largerfilter,softershadowboundary

24

Page 25: CMSC427 Advanced shading – getting global illumination by local …reastman/slides/L17P1Advanced... · 2017-11-14 · outside shadow volume 1.Allocate a counter per pixel 2.Cast

Shadow volumes

Shadowingobject

Partiallyshadowed object

Lightsource

Eye position(note that shadows are independent of the eye position)

Surface insideshadow volume(shadowed)

Surface outsideshadow volume(illuminated)

Shadowvolume(infinite extent)

25

Page 26: CMSC427 Advanced shading – getting global illumination by local …reastman/slides/L17P1Advanced... · 2017-11-14 · outside shadow volume 1.Allocate a counter per pixel 2.Cast

In shadow or not

• Testifsurfacevisibleingivenpixelisinsideoroutsideshadowvolume1. Allocateacounterperpixel2. Castarayintothescene,startingfromeye,goingthroughgivenpixel

3. Incrementthecounterwhentherayenterstheshadowvolume

4.Decrementthecounterwhentherayleavestheshadowvolume

5.Whenwehittheobject,checkthecounter.• Ifcounter>0,inshadow• Otherwise,notinshadow

26

Page 27: CMSC427 Advanced shading – getting global illumination by local …reastman/slides/L17P1Advanced... · 2017-11-14 · outside shadow volume 1.Allocate a counter per pixel 2.Cast

In shadow or not

OccluderLightsource

Eyeposition

+1 +2 +2+3

In shadow

+1

27

Page 28: CMSC427 Advanced shading – getting global illumination by local …reastman/slides/L17P1Advanced... · 2017-11-14 · outside shadow volume 1.Allocate a counter per pixel 2.Cast

Implementation in rendering pipeline• Raytracingnotpossibletoimplementdirectly• Useafewtricks...

28

Page 29: CMSC427 Advanced shading – getting global illumination by local …reastman/slides/L17P1Advanced... · 2017-11-14 · outside shadow volume 1.Allocate a counter per pixel 2.Cast

Shadow volume construction

• Needtogenerateshadowpolygonstoboundshadowvolume

• Extrudesilhouetteedgesfromlightsource

Extruded shadow volumes29

Page 30: CMSC427 Advanced shading – getting global illumination by local …reastman/slides/L17P1Advanced... · 2017-11-14 · outside shadow volume 1.Allocate a counter per pixel 2.Cast

Shadow volume construction

• NeedstobedoneontheCPU• Silhouetteedgedetection

• Anedgeisasilhouetteifoneadjacenttriangleisfrontfacing,theotherbackfacingwithrespecttothelight

• Extrudepolygonsfromsilhouetteedges

30

Page 31: CMSC427 Advanced shading – getting global illumination by local …reastman/slides/L17P1Advanced... · 2017-11-14 · outside shadow volume 1.Allocate a counter per pixel 2.Cast

Shadow test without ray tracing

Usingthestencilbuffer• Aframebuffer channel(likeRGBcolors,depth)thatcontainsaper-pixelcounter(integervalue)

• AvailableinOpenGL• Stenciltest

• Similartodepthtest(z-buffering)• Controlwhetherafragmentisdiscardedornot• Stencilfunction:isevaluatedtodecidewhethertodiscardafragment

• Stenciloperation:isperformedtoupdatethestencilbufferdependingontheresultofthetest

31

Page 32: CMSC427 Advanced shading – getting global illumination by local …reastman/slides/L17P1Advanced... · 2017-11-14 · outside shadow volume 1.Allocate a counter per pixel 2.Cast

Shadow volume algorithms

Z-passapproach• Countleaving/enteringshadowvolumeeventsasdescribed

• Usestencilbuffertocountnumberofvisible(i.e.notoccludedfromcamera)front-facingandbackfacingshadowvolumepolygonsforeachpixel

• Ifequal,pixelisnotinshadowZ-failapproach• Countnumberofinvisible(i.e.occludedfromcamera)front-facingandback-facingshadowvolumepolygons

• Ifequal,pixelisnotinshadow

32

Page 33: CMSC427 Advanced shading – getting global illumination by local …reastman/slides/L17P1Advanced... · 2017-11-14 · outside shadow volume 1.Allocate a counter per pixel 2.Cast

Z-pass approach: details

• Renderscenewithonlyambientlight• Updatedepthbuffer

• Turnoffdepthandcolorwrite,turnonstencil,keepthedepthteston• Initstencilbufferto0• Drawshadowvolumetwiceusingfaceculling

• 1stpass:renderfront facesandincrement stencilbufferwhendepthtestpasses

• 2ndpass:renderback facesanddecrement whendepthtestpasses• Ateachpixel

• Stencil!=0,inshadow• Stencil=0,lit

• Renderthesceneagainwithdiffuseandspecularlighting• Writetoframebufferonlypixelswithstencil=0

33

Page 34: CMSC427 Advanced shading – getting global illumination by local …reastman/slides/L17P1Advanced... · 2017-11-14 · outside shadow volume 1.Allocate a counter per pixel 2.Cast

Issues

• Z-passfailsif• Eyeisinshadow• Shadowpolygonclippedbynearclipplane

34

Page 35: CMSC427 Advanced shading – getting global illumination by local …reastman/slides/L17P1Advanced... · 2017-11-14 · outside shadow volume 1.Allocate a counter per pixel 2.Cast

Shadow volumes

• Pros• Doesnotrequirehardwaresupportforshadowmapping• Pixelaccurateshadows,nosamplingissues

• Cons• MoreCPUintensive(constructionofshadowvolumepolygons)

• Fill-rateintensive(needtodrawmanyshadowvolumepolygons)

• Expensiveforcomplexgeometry• Trickytohandleallcasescorrectly• Hardtoextendtosoftshadows

35

Page 36: CMSC427 Advanced shading – getting global illumination by local …reastman/slides/L17P1Advanced... · 2017-11-14 · outside shadow volume 1.Allocate a counter per pixel 2.Cast

Shadow maps

• Pros:• LittleCPUoverhead• Noneedtoconstructextrageometrytorepresentshadows

• Hardwaresupport• Canfakesoftshadowseasily

• Cons:• Samplingissues• Depthbiasisnotcompletelyfoolproof

• Shadowmappinghasbecomemorepopularwithbetterhardwaresupport

36

Page 37: CMSC427 Advanced shading – getting global illumination by local …reastman/slides/L17P1Advanced... · 2017-11-14 · outside shadow volume 1.Allocate a counter per pixel 2.Cast

Resources

• Overview,lotsoflinkshttp://www.realtimerendering.com/

• Basicshadowmapshttp://en.wikipedia.org/wiki/Shadow_mapping

• Avoidingsamplingproblemsinshadowmapshttp://www.comp.nus.edu.sg/~tants/tsm/tsm.pdfhttp://www.cg.tuwien.ac.at/research/vr/lispsm/

• Fakingsoftshadowswithshadowmapshttp://people.csail.mit.edu/ericchan/papers/smoothie/

• Alternative:shadowvolumeshttp://en.wikipedia.org/wiki/Shadow_volume

37

Page 38: CMSC427 Advanced shading – getting global illumination by local …reastman/slides/L17P1Advanced... · 2017-11-14 · outside shadow volume 1.Allocate a counter per pixel 2.Cast

More realistic illumination

• Inrealworld,ateachpointinscenelightarrivesfromalldirections

• Notjustfrompointlightsources

• Environmentmaps• Store“omni-directional”illuminationasimages• Eachpixelcorrespondstolightfromacertaindirection

38

Page 39: CMSC427 Advanced shading – getting global illumination by local …reastman/slides/L17P1Advanced... · 2017-11-14 · outside shadow volume 1.Allocate a counter per pixel 2.Cast

Capturing environment maps

• “360degrees”panoramicimage• Insteadof360degreespanoramicimage,takepictureofmirrorball(lightprobe)

Light probes [Paul Debevec, http://www.debevec.org/Probes/] 39

Page 40: CMSC427 Advanced shading – getting global illumination by local …reastman/slides/L17P1Advanced... · 2017-11-14 · outside shadow volume 1.Allocate a counter per pixel 2.Cast

Environment maps as light sourcesSimplifyingassumption• Assumelightcapturedbyenvironmentmapisemittedinfinitelyfaraway

• Environmentmapconsistsofdirectionallightsources

• Valueofenvironmentmapisdefinedforeachdirection,independentofpositioninscene

• Usesingleenvironmentmapaslightsourceatalllocations inthescene

• Approximation!

40

Page 41: CMSC427 Advanced shading – getting global illumination by local …reastman/slides/L17P1Advanced... · 2017-11-14 · outside shadow volume 1.Allocate a counter per pixel 2.Cast

Environment maps as light sources• Howdoyoucomputeshadingofadiffusesurfaceusinganenvironmentmap?

• Whatismoreexpensivetocompute,shadingadiffuseoraspecularsurface?

41

Page 42: CMSC427 Advanced shading – getting global illumination by local …reastman/slides/L17P1Advanced... · 2017-11-14 · outside shadow volume 1.Allocate a counter per pixel 2.Cast

Environment maps applications

• Useenvironmentmapas“lightsource”

Global illumination[Sloan et al.]

Reflection mapping

42

Page 43: CMSC427 Advanced shading – getting global illumination by local …reastman/slides/L17P1Advanced... · 2017-11-14 · outside shadow volume 1.Allocate a counter per pixel 2.Cast

Sphere & cube maps

• Storeincidentlightonsphereoronsixfacesofacube

Spherical map Cube map

Elevation, azimuthalangle

Elevationq const.

Northpoleq=90

Southpoleq=-90

43

Page 44: CMSC427 Advanced shading – getting global illumination by local …reastman/slides/L17P1Advanced... · 2017-11-14 · outside shadow volume 1.Allocate a counter per pixel 2.Cast

Cube maps in OpenGL

Applicationsetup• Load,bindacubeenvironmentmap

glBindTexture(GL_TEXTURE_CUBE_MAP, …);// the six cube facesglTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X,…);glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X,…);glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y,…);…glEnable(GL_TEXTURE_CUBE_MAP);

• Moredetails• “OpenGLShadingLanguage”,RandiRost• “OpenGLSuperbible”,Sellersetal.• Onlinetutorials

44

Page 45: CMSC427 Advanced shading – getting global illumination by local …reastman/slides/L17P1Advanced... · 2017-11-14 · outside shadow volume 1.Allocate a counter per pixel 2.Cast

Cube maps in OpenGL

Look-up• Givendirection(x,y,z)• Largestcoordinatecomponentdeterminescubemapface

• Dividingbymagnitudeoflargestcomponentyieldscoordinateswithinface

• Look-upfunctionbuiltintoGLSL• Use(x,y,z) directionastexturecoordinatestosamplerCube

45

Page 46: CMSC427 Advanced shading – getting global illumination by local …reastman/slides/L17P1Advanced... · 2017-11-14 · outside shadow volume 1.Allocate a counter per pixel 2.Cast

Environment map data

• Alsocalled„lightprobes“http://www.debevec.org/Probes/

• Toolforhighdynamicrangedata(HDR)http://projects.ict.usc.edu/graphics/HDRShop/

• Pre-renderedlightprobesforgameshttp://docs.unity3d.com/Manual/LightProbes.html

Lightprobes(http://www.debevec.org/Probes/) 46

Page 47: CMSC427 Advanced shading – getting global illumination by local …reastman/slides/L17P1Advanced... · 2017-11-14 · outside shadow volume 1.Allocate a counter per pixel 2.Cast

Reflection mapping

• Simulatemirrorreflection• Computereflectionvectorateachpixelusingviewdirectionandsurfacenormal

• Usereflectionvectortolookupcubemap• Renderingcubemapitselfisoptional

Reflection mapping 47

Page 48: CMSC427 Advanced shading – getting global illumination by local …reastman/slides/L17P1Advanced... · 2017-11-14 · outside shadow volume 1.Allocate a counter per pixel 2.Cast

Reflection mapping in GLSL

Vertexshader• Computeviewingdirectionforeachvertex• Reflectiondirection

• UseGLSLbuilt-inreflect function

• PassreflectiondirectiontofragmentshaderFragmentshader• Look-upcubemapusinginterpolatedreflectiondirectionin float3 refl;uniform samplerCube envMap;texture(envMap, refl);

48

Page 49: CMSC427 Advanced shading – getting global illumination by local …reastman/slides/L17P1Advanced... · 2017-11-14 · outside shadow volume 1.Allocate a counter per pixel 2.Cast

Reflection mapping examples

• Approximation,reflectionsarenotaccurate

[NVidia]

49

Page 50: CMSC427 Advanced shading – getting global illumination by local …reastman/slides/L17P1Advanced... · 2017-11-14 · outside shadow volume 1.Allocate a counter per pixel 2.Cast

Shading using environment map

• Assumption:distantlighting• Incidentlightisafunctionofdirection,butnotposition

• Realisticshadingrequires• Takeintoaccountlightfromalldirections• Includeocclusion

Illumination from environment

Same environment map for both points“Illumination is a function of direction,but not position”

50

Page 51: CMSC427 Advanced shading – getting global illumination by local …reastman/slides/L17P1Advanced... · 2017-11-14 · outside shadow volume 1.Allocate a counter per pixel 2.Cast

Mathematical model

• AssumeLambertian(diffuse)material,BRDFkd• Ignoreocclusionfornow

• Illuminationfrompointlightsources

• Illuminationfromenvironmentmapusinghemisphericalintegral

• Directionsw• HemisphereofdirectionsW• Environmentmap,radiancefromeachdirectionc(w)

51

Page 52: CMSC427 Advanced shading – getting global illumination by local …reastman/slides/L17P1Advanced... · 2017-11-14 · outside shadow volume 1.Allocate a counter per pixel 2.Cast

Irradiance environment maps

• Precomputeirradiance asafunctionofnormal

• Storeasirradianceenvironmentmap

• Shadingcomputationatrendertime• Dependsonlyonnormal,notposition

Environment map Irradiance map52

Page 53: CMSC427 Advanced shading – getting global illumination by local …reastman/slides/L17P1Advanced... · 2017-11-14 · outside shadow volume 1.Allocate a counter per pixel 2.Cast

Irradiance environment maps

Directional light Environment illumination

Images from http://www.cs.berkeley.edu/~ravir/papers/envmap/ 53

Page 54: CMSC427 Advanced shading – getting global illumination by local …reastman/slides/L17P1Advanced... · 2017-11-14 · outside shadow volume 1.Allocate a counter per pixel 2.Cast

Implementation

• Precomputeirradiancemapfromenvironment• HDRShoptool,“diffuseconvolution”

http://projects.ict.usc.edu/graphics/HDRShop/

• Atrendertime,lookupirradiancemapusingsurfacenormal

• Whenobjectrotates,rotatenormalaccordingly

• Canalsoapproximateglossyreflection• Blurenvironmentmaplessheavily• Lookupblurredenvironmentmapusingreflectionvector

54

Page 55: CMSC427 Advanced shading – getting global illumination by local …reastman/slides/L17P1Advanced... · 2017-11-14 · outside shadow volume 1.Allocate a counter per pixel 2.Cast

Today

Moreshading• Environmentmaps• Reflectionmapping• Irradianceenvironmentmaps• Ambientocclusion• Reflectionandrefraction• Toonshading

55

Page 56: CMSC427 Advanced shading – getting global illumination by local …reastman/slides/L17P1Advanced... · 2017-11-14 · outside shadow volume 1.Allocate a counter per pixel 2.Cast

Including occlusion

• Ateachpoint,environmentispartiallyoccludedbygeometry

• Addlightonlyfromun-occludeddirections

Visualization of un-occluded directions56

Page 57: CMSC427 Advanced shading – getting global illumination by local …reastman/slides/L17P1Advanced... · 2017-11-14 · outside shadow volume 1.Allocate a counter per pixel 2.Cast

Including occlusion

VisibilityfunctionVx(w)• Binaryfunctionofdirectionw• Indicatesifenvironmentisoccluded• Dependsonpositionx

Environment map Visibility functions

Vx0=0

Vx1=0Vx0=1

Vx1=1

x0

x1

57

Page 58: CMSC427 Advanced shading – getting global illumination by local …reastman/slides/L17P1Advanced... · 2017-11-14 · outside shadow volume 1.Allocate a counter per pixel 2.Cast

Mathematical model

• Diffuseilluminationwithvisibility

• Ambientocclusion• “Fraction”ofenvironmentthatisnotoccludedfromapointx

• Scalarvalue

• Approximation:diffuseshadinggivenbyirradianceweightedbyambientocclusion

Vx=0

Vx=1

58

Page 59: CMSC427 Advanced shading – getting global illumination by local …reastman/slides/L17P1Advanced... · 2017-11-14 · outside shadow volume 1.Allocate a counter per pixel 2.Cast

Ambient occlusion

Ambientocclusion Diffuseshading Ambientocclusioncombined(usingmultiplication)withdiffuseshading

http://en.wikipedia.org/wiki/Ambient_occlusion59

Page 60: CMSC427 Advanced shading – getting global illumination by local …reastman/slides/L17P1Advanced... · 2017-11-14 · outside shadow volume 1.Allocate a counter per pixel 2.Cast

Implementation

• Precomputation (off-line,beforerendering)• Computeambientocclusiononaper-vertexbasis• Usingraytracing• Freetoolthatsavesmesheswithper-vertexambientocclusion

http://www.xnormal.net/

• Caution• Basicpre-computedambientocclusiondoesnotworkforanimatedobjects

60

Page 61: CMSC427 Advanced shading – getting global illumination by local …reastman/slides/L17P1Advanced... · 2017-11-14 · outside shadow volume 1.Allocate a counter per pixel 2.Cast

Shading integral

• Ambient occlusion with irradiance environmentmaps is crude approximation to general shadingintegral

• BRDFfor (non-diffuse)material

Reflected radiance c(wo)

Outgoing direction wo

Incident directions wi

HemisphereW61

Page 62: CMSC427 Advanced shading – getting global illumination by local …reastman/slides/L17P1Advanced... · 2017-11-14 · outside shadow volume 1.Allocate a counter per pixel 2.Cast

Shading integral

• Accurate evaluation is expensiveto compute• Requires numerical integration

• Many tricksfor more accurate and generalapproximation than ambient occlusion and irradianceenvironment maps exist

• Spherical harmonics shadinghttp://www.research.scea.com/gdc2003/spherical-harmonic-lighting.pdf

62

Page 63: CMSC427 Advanced shading – getting global illumination by local …reastman/slides/L17P1Advanced... · 2017-11-14 · outside shadow volume 1.Allocate a counter per pixel 2.Cast

Note

• Visuallyinterestingresultsusingcombination(sum)ofdiffuseshadingwithambientocclusionandreflectionmapping

http://www.research.scea.com/gdc2003/spherical-harmonic-lighting.pdf

Diffuseshading withambient occlusion Reflection mapping Combination (sum)

63

Page 64: CMSC427 Advanced shading – getting global illumination by local …reastman/slides/L17P1Advanced... · 2017-11-14 · outside shadow volume 1.Allocate a counter per pixel 2.Cast

Today

Moreshading• Environmentmaps• Reflectionmapping• Irradianceenvironmentmaps• Ambientocclusion• Reflectionandrefraction• Toonshading

64

Page 65: CMSC427 Advanced shading – getting global illumination by local …reastman/slides/L17P1Advanced... · 2017-11-14 · outside shadow volume 1.Allocate a counter per pixel 2.Cast

Toon shading

• Simplecartoonstyleshader• Emphasizesilhouettes• Discretestepsfordiffuseshading,highlights• SometimescalledCELshading

http://en.wikipedia.org/wiki/Cel-shaded_animation

Off-line toon shader GLSL toon shader 65

Page 66: CMSC427 Advanced shading – getting global illumination by local …reastman/slides/L17P1Advanced... · 2017-11-14 · outside shadow volume 1.Allocate a counter per pixel 2.Cast

Toon shading

• Silhouetteedgedetection• Computedotproductofviewingdirectionv andnormaln

• Use1Dtexturetodefineedgerampuniform sample1D edgeramp; e=texture1D(edgeramp,edge);

0

1edgeramp

edge66

Page 67: CMSC427 Advanced shading – getting global illumination by local …reastman/slides/L17P1Advanced... · 2017-11-14 · outside shadow volume 1.Allocate a counter per pixel 2.Cast

Toon shading

• Computediffuseandspecularshading

• Use1Dtexturesdiffuseramp, specularramp tomapdiffuseandspecularshadingtocolors

• Finalcoloruniform sampler1D diffuseramp;uniform sampler1D specularramp;c = e * (texture(diffuse,diffuseramp)+

texture(specular,specularramp));

67