43

Advanced Light and Shadow Culling Methods Eric Lengyel

Embed Size (px)

Citation preview

Page 1: Advanced Light and Shadow Culling Methods Eric Lengyel
Page 2: Advanced Light and Shadow Culling Methods Eric Lengyel

Advanced Light and Advanced Light and Shadow Culling Shadow Culling

MethodsMethods

Eric LengyelEric Lengyel

Page 3: Advanced Light and Shadow Culling Methods Eric Lengyel

Fully Dynamic Fully Dynamic EnvironmentEnvironment Anything in the world can Anything in the world can

movemove—Can’t precompute any visibility Can’t precompute any visibility

informationinformation Lights completely dynamicLights completely dynamic

—Can’t precompute any lighting Can’t precompute any lighting informationinformation

—Shadows also completely dynamicShadows also completely dynamic

Page 4: Advanced Light and Shadow Culling Methods Eric Lengyel

Problems to Be Solved Problems to Be Solved at Run-timeat Run-time Determine the set of objects Determine the set of objects

visible to the cameravisible to the camera Determine the set of lights Determine the set of lights

that can influence the region that can influence the region of space visible to the cameraof space visible to the camera

For each light, also determine For each light, also determine what subset of the visible what subset of the visible objects can be illuminatedobjects can be illuminated

Page 5: Advanced Light and Shadow Culling Methods Eric Lengyel

Problems to Be Solved Problems to Be Solved at Run-timeat Run-time Determine the set of Determine the set of

objects that could possibly objects that could possibly cast shadows into the cast shadows into the region of space visible to region of space visible to the camerathe camera—A superset of the set of the A superset of the set of the

illuminated objects that are illuminated objects that are visible to the cameravisible to the camera

Page 6: Advanced Light and Shadow Culling Methods Eric Lengyel

Visibility DeterminationVisibility Determination

Organize the world in some Organize the world in some wayway—Tree structures (BSP, octree, Tree structures (BSP, octree,

etc.)etc.)—Hierarchical bounding volumesHierarchical bounding volumes—Portal systemPortal system

A combination of these can A combination of these can work extremely wellwork extremely well

Page 7: Advanced Light and Shadow Culling Methods Eric Lengyel

Portal SystemsPortal Systems

World divided into ‘zones’World divided into ‘zones’—A zone is the region of space A zone is the region of space

bounded by a convex polyhedronbounded by a convex polyhedron Zones are connected by Zones are connected by

‘portals’‘portals’—A portal is a planar convex polygonA portal is a planar convex polygon—From the front side, a portal’s From the front side, a portal’s

vertices are wound CCWvertices are wound CCW

Page 8: Advanced Light and Shadow Culling Methods Eric Lengyel

Portal SystemsPortal Systems

During visibility During visibility determination, only have to determination, only have to worry about zones that can worry about zones that can be seen through a sequence be seen through a sequence of portalsof portals

For each reachable zone, For each reachable zone, there is a convex region of there is a convex region of space visible to the cameraspace visible to the camera

Page 9: Advanced Light and Shadow Culling Methods Eric Lengyel

Portal SystemsPortal Systems

CameraCamera

Page 10: Advanced Light and Shadow Culling Methods Eric Lengyel

Portal SystemsPortal Systems

The visible regions form a tree The visible regions form a tree structurestructure

The region in the zone The region in the zone containing the camera is the containing the camera is the root of the treeroot of the tree

Zones seen through Zones seen through nn portals portalshave regions at the have regions at the n-n-th level th level in the treein the tree

Page 11: Advanced Light and Shadow Culling Methods Eric Lengyel

Portal SystemsPortal Systems

CameraCamera

AABB

CCDD AA

BB CC

DD

Page 12: Advanced Light and Shadow Culling Methods Eric Lengyel

Portal SystemsPortal Systems

Start with view frustum in zone Start with view frustum in zone containing the cameracontaining the camera

Clip portals leading out of the Clip portals leading out of the zone against the view frustumzone against the view frustum

For any portals intersecting the For any portals intersecting the view frustum, construct a new view frustum, construct a new region by extruding clipped edges region by extruding clipped edges away from camera positionaway from camera position

Page 13: Advanced Light and Shadow Culling Methods Eric Lengyel

Portal SystemsPortal Systems

Every visibility region is Every visibility region is bounded by a convex bounded by a convex polyhedron defined by at least polyhedron defined by at least 4 planes4 planes—At least 3 lateral planesAt least 3 lateral planes—A back planeA back plane—A front plane in non-root nodesA front plane in non-root nodes

Plane normals point inwardPlane normals point inward

Page 14: Advanced Light and Shadow Culling Methods Eric Lengyel

Portal SystemsPortal Systems

After region tree has been After region tree has been built...built...—Traverse the treeTraverse the tree—Collect objects in each zone that Collect objects in each zone that

intersect the visible region of intersect the visible region of space for that zonespace for that zone Use any frustum/bounding volume Use any frustum/bounding volume

test, but test against region’s planestest, but test against region’s planes

—This is the visible object setThis is the visible object set

Page 15: Advanced Light and Shadow Culling Methods Eric Lengyel

Light Region TreesLight Region Trees

Portals can be used to Portals can be used to construct illumination treesconstruct illumination trees—Similar to the visibility tree Similar to the visibility tree

constructed for the cameraconstructed for the camera—One tree for each light sourceOne tree for each light source

Only recalculated when light movesOnly recalculated when light moves

—Each node in the tree Each node in the tree corresponds to a convex region of corresponds to a convex region of spacespace

Page 16: Advanced Light and Shadow Culling Methods Eric Lengyel

Light Region TreesLight Region Trees

Three fundamental light Three fundamental light typestypes—Point lightPoint light—Spot light, special case of Spot light, special case of

point lightpoint light—Infinite (directional) lightInfinite (directional) light

Page 17: Advanced Light and Shadow Culling Methods Eric Lengyel

Light Region TreesLight Region Trees

Point lightPoint light—OmnidirectionalOmnidirectional—Has maximum rangeHas maximum range—Root illumination region Root illumination region

bounded only be zone bounded only be zone boundary and light’s boundary and light’s bounding spherebounding sphere

Page 18: Advanced Light and Shadow Culling Methods Eric Lengyel

Point Light TreePoint Light Tree

AABB

CC

DD

BB

AA DD

CC

Page 19: Advanced Light and Shadow Culling Methods Eric Lengyel

Spot Light TreeSpot Light Tree

Spot light almost same asSpot light almost same aspoint lightpoint light—Difference is the root node of Difference is the root node of

the illumination treethe illumination tree—Spot light starts with a frustum, Spot light starts with a frustum,

just like a camera doesjust like a camera does—Point light affects entire root Point light affects entire root

zonezone

Page 20: Advanced Light and Shadow Culling Methods Eric Lengyel

Infinite Light TreeInfinite Light Tree

Light rays parallel forLight rays parallel forinfinite lightinfinite light—The lateral planes of each The lateral planes of each

illumination region intersect at illumination region intersect at parallel linesparallel lines

—The extrusion of planes from a The extrusion of planes from a portal always goes in one portal always goes in one direction instead of away from a direction instead of away from a pointpoint

Page 21: Advanced Light and Shadow Culling Methods Eric Lengyel

Visible Light Visible Light DeterminationDetermination Each zone keeps a linked Each zone keeps a linked

list of illumination regionslist of illumination regions—One or more region nodes for One or more region nodes for

each light that can shine into each light that can shine into the zonethe zone

—Each region knows which light Each region knows which light generated itgenerated it

Page 22: Advanced Light and Shadow Culling Methods Eric Lengyel

Visible Light Visible Light DeterminationDeterminationAA BB

CC DD

Light 1Light 1

Light 2Light 2

Light 3Light 3

For example, For example, consider zone consider zone CC

Page 23: Advanced Light and Shadow Culling Methods Eric Lengyel

Visible Light Visible Light DeterminationDetermination

BB

AA DD

CC

AA

BB CC

DD

DD

CC BB

AA

Light 1Light 1 Light 2Light 2 Light 3Light 3

Page 24: Advanced Light and Shadow Culling Methods Eric Lengyel

Visible Light Visible Light DeterminationDetermination For any given zone, we can walk For any given zone, we can walk

the linked list of illumination the linked list of illumination regions and collect unique lightsregions and collect unique lights

Repeat process for all zones Repeat process for all zones referenced in the camera’s referenced in the camera’s visibility treevisibility tree

We now have the set ofWe now have the set ofvisible lightsvisible lights

Page 25: Advanced Light and Shadow Culling Methods Eric Lengyel

Illuminated Object SetIlluminated Object Set

Given one visible zone and Given one visible zone and one visible light shining into one visible light shining into that zone…that zone…—Illuminated objects are those Illuminated objects are those

which intersect both a camera which intersect both a camera region and a light regionregion and a light region

Page 26: Advanced Light and Shadow Culling Methods Eric Lengyel

Illuminated Object SetIlluminated Object Set

LightLight

CameraCamera

Page 27: Advanced Light and Shadow Culling Methods Eric Lengyel

Illuminated Object SetIlluminated Object Set

Objects are often only Objects are often only partially within an partially within an illumination regionillumination region—Lighting the whole object Lighting the whole object

wastes rendering time due to wastes rendering time due to extra fillextra fill

—Fortunately, hardware provides Fortunately, hardware provides an opportunity for optimizationan opportunity for optimization

Page 28: Advanced Light and Shadow Culling Methods Eric Lengyel

Lighting OptimizationLighting Optimization

Use hardware scissor rectangleUse hardware scissor rectangle—Calculate intersections of camera Calculate intersections of camera

regions and illumination regionsregions and illumination regions—Camera-space bounding box Camera-space bounding box

determines scissor rectangledetermines scissor rectangle GL_EXT_depth_bounds_testGL_EXT_depth_bounds_test

—Works like a Works like a zz axis for scissor box axis for scissor box

Page 29: Advanced Light and Shadow Culling Methods Eric Lengyel

Lighting OptimizationLighting Optimization

CameraCamera

Image PlaneImage Plane

Max DepthMax Depth

Min DepthMin Depth

Page 30: Advanced Light and Shadow Culling Methods Eric Lengyel

Lighting OptimizationLighting Optimization

Scissor rectangle and depth Scissor rectangle and depth bounds testbounds test—Limits rendering for a single Limits rendering for a single

light to the maximal visible light to the maximal visible extentsextents

—Can also be applied to stencil Can also be applied to stencil shadow volumesshadow volumes

Page 31: Advanced Light and Shadow Culling Methods Eric Lengyel

Shadow Map Shadow Map OptimizationOptimization Same optimization can be Same optimization can be

applied from light’s perspective applied from light’s perspective when rendering shadow mapswhen rendering shadow maps—Transform vertices of region Transform vertices of region

intersections into light spaceintersections into light space—Calculate scissor rectangle and Calculate scissor rectangle and

depth boundsdepth bounds—Reduces unnecessary depth fillReduces unnecessary depth fill

Page 32: Advanced Light and Shadow Culling Methods Eric Lengyel

Shadow Map Shadow Map OptimizationOptimization

LightLight

Image PlaneImage PlaneMax DepthMax Depth Min DepthMin Depth

Page 33: Advanced Light and Shadow Culling Methods Eric Lengyel

Shadow-Casting Object Shadow-Casting Object SetSet All objects in the illuminated All objects in the illuminated

set are also in the shadow-set are also in the shadow-casting setcasting set—But an object doesn’t have to be But an object doesn’t have to be

visible to be casting a shadow visible to be casting a shadow into one of the visible camera into one of the visible camera regionsregions

—The shadow-casting set is a The shadow-casting set is a superset of the illuminated setsuperset of the illuminated set

Page 34: Advanced Light and Shadow Culling Methods Eric Lengyel

Shadow-Casting Object Shadow-Casting Object SetSet Need to find objects between Need to find objects between

visible regions and light visible regions and light sourcesource

We already have a structure We already have a structure in place to make this easyin place to make this easy

From an illumination region, From an illumination region, walk up the light’s tree to the walk up the light’s tree to the rootroot

Page 35: Advanced Light and Shadow Culling Methods Eric Lengyel

Shadow-Casting Object Shadow-Casting Object SetSet

CameraCamera

LightLight

AA BB CC

DD EE

CC

EE BB

AA

Page 36: Advanced Light and Shadow Culling Methods Eric Lengyel

Shadow-Casting Object Shadow-Casting Object SetSet Collect objects in branch of Collect objects in branch of

illumination tree containing illumination tree containing visible regionsvisible regions—Can use lateral bounding Can use lateral bounding

planes of deepest visible planes of deepest visible regionsregions

Page 37: Advanced Light and Shadow Culling Methods Eric Lengyel

Shadow-Casting Object Shadow-Casting Object SetSet

CameraCamera

LightLight

CulledCulledCasterCaster

Page 38: Advanced Light and Shadow Culling Methods Eric Lengyel

Shadow-Casting Object Shadow-Casting Object SetSet Where illumination regions Where illumination regions

and camera regions and camera regions intersect...intersect...—Some objects inside Some objects inside

illumination region, but not illumination region, but not between camera region and between camera region and light sourcelight source

Page 39: Advanced Light and Shadow Culling Methods Eric Lengyel

Shadow-Casting Object Shadow-Casting Object SetSet

ExtraExtraCasterCaster

Page 40: Advanced Light and Shadow Culling Methods Eric Lengyel

Shadow-Casting Object Shadow-Casting Object SetSet Eliminating shadow-casting Eliminating shadow-casting

objects on wrong side ofobjects on wrong side ofcamera regioncamera region—Test objects against planes of Test objects against planes of

camera region having a positive camera region having a positive dot product with light positiondot product with light position

—For infinite light, use planes For infinite light, use planes having a positive dot product with having a positive dot product with direction to lightdirection to light

Page 41: Advanced Light and Shadow Culling Methods Eric Lengyel

Shadow-Casting Object Shadow-Casting Object SetSet

Page 42: Advanced Light and Shadow Culling Methods Eric Lengyel

DemonstrationsDemonstrations

Page 43: Advanced Light and Shadow Culling Methods Eric Lengyel

Questions?Questions?

[email protected]@terathon.com

Slides available atSlides available at

http://http://www.terathon.com/www.terathon.com/