Upload
robert-maldonado
View
222
Download
1
Tags:
Embed Size (px)
Citation preview
Advanced Light and Advanced Light and Shadow Culling Shadow Culling
MethodsMethods
Eric LengyelEric 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
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
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
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
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
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
Portal SystemsPortal Systems
CameraCamera
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
Portal SystemsPortal Systems
CameraCamera
AABB
CCDD AA
BB CC
DD
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
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
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
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
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
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
Point Light TreePoint Light Tree
AABB
CC
DD
BB
AA DD
CC
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
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
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
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
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
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
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
Illuminated Object SetIlluminated Object Set
LightLight
CameraCamera
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
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
Lighting OptimizationLighting Optimization
CameraCamera
Image PlaneImage Plane
Max DepthMax Depth
Min DepthMin Depth
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
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
Shadow Map Shadow Map OptimizationOptimization
LightLight
Image PlaneImage PlaneMax DepthMax Depth Min DepthMin Depth
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
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
Shadow-Casting Object Shadow-Casting Object SetSet
CameraCamera
LightLight
AA BB CC
DD EE
CC
EE BB
AA
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
Shadow-Casting Object Shadow-Casting Object SetSet
CameraCamera
LightLight
CulledCulledCasterCaster
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
Shadow-Casting Object Shadow-Casting Object SetSet
ExtraExtraCasterCaster
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
Shadow-Casting Object Shadow-Casting Object SetSet
DemonstrationsDemonstrations
Questions?Questions?
[email protected]@terathon.com
Slides available atSlides available at
http://http://www.terathon.com/www.terathon.com/