Shadows Graphics & Visualization: Principles & Algorithms - - PowerPoint PPT Presentation

shadows
SMART_READER_LITE
LIVE PREVIEW

Shadows Graphics & Visualization: Principles & Algorithms - - PowerPoint PPT Presentation

Graphics & Visualization Chapter 13 Shadows Graphics & Visualization: Principles & Algorithms Chapter 13 Introduction Wherever there is light, there is shadow Shadows are not just a photorealistic image


slide-1
SLIDE 1

Graphics & Visualization

Chapter 13

Shadows

Graphics & Visualization: Principles & Algorithms Chapter 13

slide-2
SLIDE 2

Graphics & Visualization: Principles & Algorithms Chapter 13

  • Wherever there is light, there is shadow
  • Shadows

are not just a photorealistic image enhancement:

Help the eyes register objects relative to their surroundings

Define the direction of the incident light

Provide clues for the shape and depth of 3D objects:

Important in the case of monoscopic imaging

u Perspective cannot always give enough clues about the

perceived objects

u Shadows help resolve part of the depth ambiguities that

may arise

Introduction

2

slide-3
SLIDE 3

Graphics & Visualization: Principles & Algorithms Chapter 13

  • Size and depth clues from shadow:

(a) A lit scene showing a ball in front of a staircase

(b) Size/distance ambiguity, when scene perceived from viewpoint

  • f (a)

(c)–(e) Images rendered from the same viewpoint as (a). Shadows help us define the object relative to its surroundings

Introduction (2)

3

slide-4
SLIDE 4

Graphics & Visualization: Principles & Algorithms Chapter 13

  • In real-time graphics applications, shadow-generation algorithms

are utilized to add a complex look to an otherwise simple geometry:

  • Illumination transitions:

help our vision system justify the lack of detail-related contrast

Introduction (3)

4

slide-5
SLIDE 5

Graphics & Visualization: Principles & Algorithms Chapter 13

  • Shadows are formed on surfaces due to the blocking of direct

illumination from other surfaces

  • A shadow consists of two zones:

Umbra: surface area where shadow is cast with full light-source occlusion

Penumbra: area where shadow is partially lit by the light-emitting source

  • In order for a surface to be partially in shadow, the light source

needs to be of non-negligible volume compared to the size of the

  • bjects

As distance affects the apparent size of objects, the apparent projection of the light emitter on the surface needs to be non-negligible to create a penumbra

Shadows & Light Sources

5

slide-6
SLIDE 6

Graphics & Visualization: Principles & Algorithms Chapter 13

  • Shadows caused by non-infinitesimal light sources & have an umbra

& a penumbra are called soft shadows

  • Hard shadows only consist of an umbra & are caused by point-sized

light sources and infinitely far light emitters

  • Sharpness & shape of a shadow depend on size and distance of the

light source(s)

(a) Point light source (hard shadow) (b) Small non-infinitesimal light source (soft shadow) (c) Large area light (soft shadow) (d) Infinite (directional) light source (hard shadow)

Shadows & Light Sources (2)

6

slide-7
SLIDE 7

Graphics & Visualization: Principles & Algorithms Chapter 13

  • Interaction of a point light source & a shadow caster produces a

pyramidal shadow shaft clipped at the caster surface:

  • The volume that represents the unlit space is called shadow volume
  • Normally a shadow volume is infinite:

It extends away from the light source to infinity, unless the light source has a

local effect & a finite range:

Shadow volume extends up to the range of influence of light source

Shadows & Light Sources (3)

7

slide-8
SLIDE 8

Graphics & Visualization: Principles & Algorithms Chapter 13

  • Directional lights are considered to be casting light in parallel rays

toward the scene:

Shadow shafts produced by directional lights are prismatic volumes with parallel sides and the resulting shadows neither converge nor diverge

Shadows & Light Sources (4)

8

slide-9
SLIDE 9

Graphics & Visualization: Principles & Algorithms Chapter 13

  • For offline photorealistic rendering, shadow generation is usually

integral part of ray-tracing or global illumination procedure

  • In real-time computer graphics, there are 2 algorithms most

commonly employed for shadow casting:

Shadow volumes: works in object space and is ideal for casting hard, precise shadows on polygonal objects

Shadow mapping: works in image/texture space, it is applicable in a wide range of geometric entity representations, can be adapted to handle semi- transparent and partially occluding media, NOT effective in producing sharp- edged shadows.

Shadows Generation Algorithms

9

slide-10
SLIDE 10

Graphics & Visualization: Principles & Algorithms Chapter 13

GENERAL CONCEPT:

  • The algorithm attempts to construct in object space the frusta that

are formed for each combination of light source and light-blocking piece of geometry (occluder)

  • Then, each pixel to be drawn that lies on the visible geometry is

tested for containment in the shadow volumes, and its shading is determined according to this query

  • The shadow-volume algorithm:

Requires that the occluders are polygonal

Assumes that connectivity information is available for these meshes

Or can be determined as a pre-processing step

Shadow Volumes

10

slide-11
SLIDE 11

Graphics & Visualization: Principles & Algorithms Chapter 13

  • Stencil buffer:

Is a buffer, allocated in the graphics hardware or the system memory

Implements a counter and comparator unit per image pixel

Is equal in dimension to the frame buffer and usually has a resolution of 8 bpp

  • The result stored in the stencil buffer can work as a mask
  • Perform one or more rendering passes that fill the buffer with the

appropriate values and then use these results to prevent areas of the final rendering pass to be drawn in the frame buffer

  • Contents of the stencil buffer are compared to a reference value

and depending on the stencil test, the incoming fragments are eliminated

  • r propagated to the frame buffer
  • Stencil test is a comparison operator (always/never pass, ≠, =, ≥, ≤,

>, <)

The Stencil Buffer (1)

11

slide-12
SLIDE 12

Graphics & Visualization: Principles & Algorithms Chapter 13

  • Example of using the stencil buffer to draw the silhouette of a group
  • f primitives in the frame buffer, using an unconditional increment
  • perator on the stencil values and

an equality test as the stencil masking operator:

(a) Stencil buffer update pass: writing to the frame buffer is disabled and the operation on the stencil values is set to always increase (b) Conditional rendering pass in the frame buffer: fragments are rendered only if the corresponding stencil values are equal to zero.

The Stencil Buffer (2)

12

slide-13
SLIDE 13

Graphics & Visualization: Principles & Algorithms Chapter 13

  • Stencil buffer can be conditionally updated
  • Operations on the stencil buffer include:

replacing,

setting,

maintaining,

incrementing,

decrementing,

inverting the current values

13

The Stencil Buffer (3)

slide-14
SLIDE 14

Graphics & Visualization: Principles & Algorithms Chapter 13

  • Surface-in-shadow test in the basic shadow-volume algorithm:

A counter is incremented each time the eye-to-fragment line enters a shadow volume and decremented when it exits

The surface is in shadow when the counter is other than 0

If the rendered point lies within the shadow volume, surface will be hit before ray exits one or more of the overlapping shadow volumes  counter > 0

  • This procedure can be supported by graphics hardware if the

counter is implemented via the stencil buffer.

Stenciled Shadow Volumes

14

slide-15
SLIDE 15

Graphics & Visualization: Principles & Algorithms Chapter 13

  • Stenciled Shadow Algorithm:

1. Initialization: Clear depth and frame buffers, ignore the stencil operations 2. Shadow lighting: Render the geometry using only the indirect illumination components and emissive effects (lights off) 3. For each occluder, prepare and render the shadow volume: (a) Shadow volume construction. Construct a closed shadow volume by extruding the faces of the caster away from light source. (b) Volume Z-pass test. Render the front-facing polygons of the shadow volumes without updating frame or depth buffer. Each time a fragment successfully passes the depth test, the stencil buffer is incremented. (c) Render the back-facing polygons of the shadow volumes, without depth and frame buffer updates. This time, decrement the corresponding stencil values when fragments pass the depth test. 4. Render the lit geometry. Enable the light source and shade all pixels whose corresponding stencil value is zero.

Stenciled Shadow Volumes (2)

15

slide-16
SLIDE 16

Graphics & Visualization: Principles & Algorithms Chapter 13

  • Shadows from multiple light sources are handled by repeating Steps

3 and 4 for each light source

  • Step 4

should use additive blending when writing to the frame buffer and completely disable the ambient component of the light sources  mix the illumination of the shadowed areas & avoid

  • vershooting the lit surfaces

Stenciled Shadow Volumes (3)

16

slide-17
SLIDE 17

Graphics & Visualization: Principles & Algorithms Chapter 13

Stenciled Shadow Volumes (4)

17

slide-18
SLIDE 18

Graphics & Visualization: Principles & Algorithms Chapter 13

Stenciled Shadow Volumes (5)

18

slide-19
SLIDE 19

Graphics & Visualization: Principles & Algorithms Chapter 13

Remarks:

  • For one light source, 2 passes are

required to render the visible geometry (shadow & diffuse / specular

  • passes 1 & 4) + 2 shadow-

volume geometry passes (front & back faces – passes 2 & 3 )

Stenciled Shadow Volumes (6)

19

slide-20
SLIDE 20

Graphics & Visualization: Principles & Algorithms Chapter 13

  • Select all the polygons that face the light source and extrude them

away from the light position

This will create a shadow shaft for every polygon

The shadow volume of the entire object is the union of these polygonal frusta

All of the common interior shaft faces eventually cancel out in the stencil buffer

  • Let p1

p2 p3 be a polygon that is visible from the light source

  • Shadow frustum extends away from this polygon toward the

direction of the incident light

  • Let pL be the position of a light source with attenuation range rL

(13.1)

Shadow-Volume Construction

20

 

i i L i L i L i L

= + r -

  • ·(
  • ) /

p p p p p p p p

slide-21
SLIDE 21

Graphics & Visualization: Principles & Algorithms Chapter 13

  • Light sources are considered infinite with respect to the size of the

scene

Therefore the shadow-volume sides are very long and need not be sized according to the caster position relative to the light source

  • This simplifies the calculation of the extruded point

considering that rL >> |pi −pL |:

(13.2)

  • For infinite light sources (rays are always parallel to a direction ),

for every point of all casters, equation (13.2) is simplified:

Shadow-Volume Construction (2)

21

·( ) /     

i i L i L i L

p p r p p p p ˆ l ˆ ·

i i L

r    p p l

slide-22
SLIDE 22

Graphics & Visualization: Principles & Algorithms Chapter 13

  • Extrusion:

(a) Casters do not need to be convex and may be self-shadowed (b) Silhouette edges as seen from the point of view of the light (c) Silhouette edge determination (d) 2-triangle shaft-sides are formed by extruding the triangle or silhouette edges (e) The “bright” and “dark” caps are the polygons facing toward and away from the light source, respectively (f) The final closed shadow volume

Shadow-Volume Construction (3)

22

slide-23
SLIDE 23

Graphics & Visualization: Principles & Algorithms Chapter 13

  • This technique is straightforward
  • Cost: building of the geometry for the shafts
  • It takes no advantage of the following fact:

Triangles on the occluder surface share edges, which, when extruded, will create triangles that share all vertices and eventually cancel each other

  • These shadow-shaft polygons are transformed and rasterized

 slowing down the rendering procedure

  • Many overlapping shafts:

render all front-facing shadow volume polygons in one pass

render all back-facing polygons in another pass

  •  Stencil buffer saturation

Shadow-Volume Construction (4)

23

slide-24
SLIDE 24

Graphics & Visualization: Principles & Algorithms Chapter 13

  • Alternative methodology:

More complex frusta generation stage

Far fewer polygons

  • Extra computations can slow down performance in case of highly

tessellated models in dynamic environments scenes

  • This variation is recommended:

For low polygon models

For static light-object relationships

Shadow-Volume Construction (5)

24

slide-25
SLIDE 25

Graphics & Visualization: Principles & Algorithms Chapter 13

  • Shadow-frustum generation is performed as a pre-processing step
  • Extrusion of the silhouette of the union of the faces visible from the

light source  Pairs of sides that form the frusta for the occluder triangles can be efficiently removed

Union of triangles also forms the “near” cap, relative to the light source

  • Above consideration leads from shadow-volume construction into:

A silhouette-determination stage

An edge-extrusion stage

Silhouette-based Volume Construction

25

slide-26
SLIDE 26

Graphics & Visualization: Principles & Algorithms Chapter 13

  • Silhouette
  • f a polygonal surface (relative to a viewpoint in space):

Set of all visible polygon edges that are shared by at least one back-facing and

  • ne front-facing polygon with respect to the particular point of view

For open 3D shapes, this set is extended to include all open edges

  • As a preprocessing step, assuming a polygon soup:

Determine all neighboring polygons

Mark the common edges

Silhouette-based Volume Construction (2)

26

slide-27
SLIDE 27

Graphics & Visualization: Principles & Algorithms Chapter 13

  • For a manifold triangulated surface, the basic structure that holds the

information about the polygon points and normals has to be enriched with connectivity information:

Silhouette-based Volume Construction (3)

27

typedef struct { Point3f v[3]; Vector3f n[3]; Vector3f facenormal; long neighbor[3]; // <-- initialize to -1; } Triangle; int CommonEdge( Point3f a1, Point3f a2, Point3f b1, Point3f b2) { extern float weld_thres_squared; // avoid sqr. root Vector3f d1 = PointSubtract(a1-b1); Vector3f d2 = PointSubtract(a2-b2); return ( DotProduct(d1,d1) < weld_thres_squared && DotProduct(d2,d2) < weld_thres_squared ); }

slide-28
SLIDE 28

Graphics & Visualization: Principles & Algorithms Chapter 13

void FindConnectivity (Triangle *tri, long numOfTris) { long i,j; int k,n; for (i=0;i<numOfTris-1;i++) for (j=i+1;j<numOfTris;j++) for (k=0;k<3;k++) for (n=0;n<3;n++) if ( CommonEdge(tri[i].v[k], tri[i].v[(k+1)%3] tri[j].v[n], tri[j].v[(n+1)%3] ) { tri[i].neighbor[k] = j; // edge v[k]-v[k+1] is shared with tr. j tri[j].neighbor[n] = -1; // mark adjacency only on one triangle to // avoid double edges during sil. // detection Break; } }

28

Silhouette-based Volume Construction (4)

slide-29
SLIDE 29

Graphics & Visualization: Principles & Algorithms Chapter 13

  • When the silhouette needs to be updated, connectivity

information of the mesh is used

  • If

< 0 for 2 polygons i, j, their common edge belongs to the edge list of the silhouette:

29

 

 

ˆ ˆ · · ·

i L i j L j

          n p p n p p

typedef struct { Point3f * edgeVertex; int numOfEdges; } edgeList;

Silhouette-based Volume Construction (5)

slide-30
SLIDE 30

Graphics & Visualization: Principles & Algorithms Chapter 13

edgeList* FindSilhouette( Triangle * tri, long numOfTris, Vector3f light, boolean infinite) { long i,j, edges=0; int k; Vector3f L, ni, nj; float visi, visj; // Allocate a large edge buffer: Point3f * endpts = (Point3f*)malloc(sizeof(Point3f)*numOfTris*3*2); (continued)

30

Silhouette-based Volume Construction (6)

slide-31
SLIDE 31

Graphics & Visualization: Principles & Algorithms Chapter 13

for (i=0; i<numOfTris; i++) for (k=0; k<3; k++){ j = tri[i].neighbor[k]; if (j!=-1) // if neighbor is marked: { ni=tri[i].facenormal; L = infinite? VectorInvert(light): VectorNorm(PointSubtract(light,tri[i].v[0]); visi = DotProduct(ni,L); nj = tri[j].facenormal; L = infinite? VectorInvert(light): VectorNorm(PointSubtract(light,tri[j].v[0]); visj = DotProduct(nj,L); if (visi*visj<0) { PointCopy(endpts[2*edges+0],tri[i].v[k]; PointCopy(endpts[2*edges+1],tri[i].v[(k+1)%3]; edges++; } } } (continued)

31

Silhouette-based Volume Construction (7)

slide-32
SLIDE 32

Graphics & Visualization: Principles & Algorithms Chapter 13

edgeList * list = (edgeList*)malloc(sizeof(edgeList)); list->numOfEdges = edges; list->edgeVertex =(Point3f*)malloc(sizeof(Point3f)*2*edges); for (i=0;i<2*edges;i++) PointCopy(list->edgeVertex[i],endpts[i]); free(endpts); return(list); }

32

Silhouette-based Volume Construction (8)

slide-33
SLIDE 33

Graphics & Visualization: Principles & Algorithms Chapter 13

  • Interesting observation for watertight meshes:

Near cap of the shadow volume consists of all the triangles that face towards the light source

Far cap is made of the rest of the mesh’s faces, after extruding their vertices

The shadow-volume sides are the extruded silhouette edges.

33

Silhouette-based Volume Construction (9)

slide-34
SLIDE 34

Graphics & Visualization: Principles & Algorithms Chapter 13

  • At the bright cap, polygons belong to both the shadow volume and

the lit geometry 

  • Shadow artifacts during the second pass (inadequate depth-test

accuracy - Z-fighting).

  • To overcome this problem:

Push the near cap a little further away from the light source, using the same extrusion direction as the far- cap vertices

Shadow-Volumes and Self Shadowing

34

slide-35
SLIDE 35

Graphics & Visualization: Principles & Algorithms Chapter 13

  • SV demands that the near clipping plane of the viewing frustum

does not intersect the shadow volume

This also includes the case when the viewpoint lies inside the shadow volume

  • The problem is not as simple as determining whether the viewpoint

is inside the shadow frustum

Cases may occur where view plane is entirely in shadow while the viewer is

  • utside the shadow frustum

Pitfalls & Improvements

35

slide-36
SLIDE 36

Graphics & Visualization: Principles & Algorithms Chapter 13

  • A popular solution to the Z-pass algorithm is Z-fail algorithm:

Removes the near clipping problem but raises the same problem at the far clipping plane

Fortunately, it is easier to ensure that the far clipping plane does not intersect the shadow volumes:

Either by consistently preparing the far caps of the shadow volume

Or by pushing the clipping plane to infinity

Pitfalls & Improvements (2)

36

slide-37
SLIDE 37

Graphics & Visualization: Principles & Algorithms Chapter 13

1. Initialization: Clear depth and frame buffers, ignore the stencil operations 2. Shadow lighting: Render the geometry using only the indirect illumination components and emissive effects (lights off) 3. For each occluder, prepare and render the shadow volume: (a) Shadow volume construction. Construct a closed shadow volume by extruding the faces of the caster away from light source. (b) Volume Z-fail test. Render the back-facing polygons of the shadow volumes without updating frame or depth buffer. Each time a fragment fails the depth test, the stencil buffer is incremented. (c) Render the front-facing polygons of the shadow volumes, without depth and frame buffer updates. This time, decrement the corresponding stencil values when depth test fails. 4. Render the lit geometry. Enable the light source and shade all pixels whose corresponding stencil value is zero.

Z-fail Shadow Volumes Algorithm

37

slide-38
SLIDE 38

Graphics & Visualization: Principles & Algorithms Chapter 13 38

Z-fail Shadow Volumes Algorithm (2)

slide-39
SLIDE 39

Graphics & Visualization: Principles & Algorithms Chapter 13 39

Z-fail Shadow Volumes Algorithm (2)

slide-40
SLIDE 40

Graphics & Visualization: Principles & Algorithms Chapter 13

Z-fail algorithm transposes the problem of intersection of the near clipping plane with the shadow volume to the far clipping plane:

Instead counting shadow volume enters/exits along the eye-pixel ray starting from the eye & ending at the nearest visible fragment:

Z-fail algorithm counts ray intersections starting from infinity & ending at the nearest visible fragment

  • Near-plane clipping of the shadow volume causes no problems
  • As counting starts from back to front:

All backfacing shadow-volume fragments should be closer than or at “infinity”

  • f the view frustum in order to be taken into account
  • Otherwise, the resulting stencil mask may be incorrect
  • By capping the open far end of the shadow volume at or before the

far clipping plane  infinity is always outside the shadow volume

40

Z-fail SV Algorithm – Comments (1)

slide-41
SLIDE 41

Graphics & Visualization: Principles & Algorithms Chapter 13

  • Finite shadow-frustum deficiency: When light source is close to the

shadow-casting geometry, distance between bright & dark caps is shortened, leaving shadowed geometry outside the shadow volume:

41

Pitfalls & Improvements

slide-42
SLIDE 42

Graphics & Visualization: Principles & Algorithms Chapter 13

  • As light position approaches the geometry of the caster:

Solid angle subtended by the silhouette increases

Radial distance remains fixed

  • This means that the far cap moves closer to the light  leaves parts
  • f the scene outside the shadow volume
  • A solution:

Using the Z-fail variation of the stenciled shadow- volume algorithm but setting the far clipping plane at “infinity” and constructing an infinite closed shadow volume

  • Setting far clipping plane at infinity can be achieved by changing

the standard projection matrix used to render the scene:

By estimating the limit of the matrix as the far clipping plane distance tends to infinity

Pitfalls & Improvements (2)

42

slide-43
SLIDE 43

Graphics & Visualization: Principles & Algorithms Chapter 13

  • For instance: Transformation matrix specified in OpenGL:

(13.3)

  • Where

n: near clipping plane distance, f: far clipping plane range, l, r, t, and b: extents of the frustum at the near distance

  • We need to evaluate the limit of the matrix in equation (13.3)

Only the 3rd row of the matrix is affected by the limit operation

It holds:

Pitfalls & Improvements (3)

43

2 2 2 1 n r l r l r l n t b t b t b f n nf f n f n                                  P

 

lim / 1

x

x a x b



  

slide-44
SLIDE 44

Graphics & Visualization: Principles & Algorithms Chapter 13

  • Finally we get:

(13.4)

  • Z-fail approach is slower than the Z-pass one
  • The 2 methods can be used interchangeably:

according to whether the viewport intersects the shadow volume or not

  • Z-fail method may be applied only when necessary

Pitfalls & Improvements (4)

44

 

inf

2 2 lim 1 2 1

f

n r l r l r l n t b t b t b n



                             P P

slide-45
SLIDE 45

Graphics & Visualization: Principles & Algorithms Chapter 13

  • Successive stencil increases or decreases can saturate the stencil
  • buffer. This can happen when depth complexity of the overlapping

shadow frusta exceeds the stencil-buffer counter limit

  • In simple terms:

for an 8-bit stencil buffer  room for

  • nly 255 overlapping shadow volumes:

The stencil-buffer values can only be incremented that many times

  • A solution:

utilize wrap-around stencil operations, supported by modern graphics hardware

Stencil Buffer Saturation

45

slide-46
SLIDE 46

Other Optimizations

  • Many optimizations of the basic shadow-volume

algorithm can be devised

  • For static lights & casters, the shadow volumes need
  • nly be calculated once
  • After the shadow frusta have been determined and the

corresponding geometry set, the shadow volumes for light sources that do not move and light-blocking static geometry are valid as long as both conditions hold

  • This knowledge can greatly improve the speed of the

algorithm

slide-47
SLIDE 47

Graphics & Visualization: Principles & Algorithms Chapter 13

  • Shadow-volume method is geometry-based
  • Shadow maps operate in image space

Use depth buffer to sort surfaces with respect to the light source line of sight

  • Its variations are widely used in:

Rendering software

Real-time applications

Shadow Maps

47

slide-48
SLIDE 48

Graphics & Visualization: Principles & Algorithms Chapter 13

  • Geometry is projected once from the viewpoint of light source
  • The light source Z-buffer (shadow map) determines which parts of

the objects have a clear line of sight to the light-source location

  • Then, the visible (eye-space) fragments are transformed to the light-

space reference frame, where their depth value is compared with the shadow map

  • If fragment's depth in light-space > shadow map value:

Fragment is hidden from the light source‘s point of view 

In shadow

Shadow Maps – Main Concept

48

slide-49
SLIDE 49

Graphics & Visualization: Principles & Algorithms Chapter 13

  • Place a directional spotlight with a lighting range rL

at a location pL in the scene & point along the direction

  • Define a local coordinate system for this light source
  • Let ML

, PL be the transformation & projection matrices of light source

  • PL

can be defined by the symmetrical frustum formed along the spotlight central axis

the far clipping plane can be adjusted to rL

  • Top, bottom, right and left extents of the frustum depend on the

spotlight-beam aperture

Shadow Map Configuration

49

ˆ L n ˆ ˆ ˆ ( , , )

L L L

 u v n ˆ L n : ·tan( / 2)

a a

l r t b n      

slide-50
SLIDE 50

Graphics & Visualization: Principles & Algorithms Chapter 13

  • Shadow test is divided into the following 2 steps:
  • Render the scene from the light source :

Transform every object according to ML

  • 1

Project it using PL

Store corresponding depth map ZL (shadow map)

  • Revert to the normal camera view & render the scene:

Point p = (x, y, z) on a surface is shadowed if located at greater distance than the value stored in ZL when p expressed in the light source's viewport coordinates:

p΄ = (x’, y’, z’) = PL ML

  • 1 p,  if z’

> ZL (x’, y’)

If z’ is outside the range [n, rL ], p is considered to be in shadow

Shadow Map Fragment Test

50

ˆ ˆ ˆ ( , , , )

L L L L

 p u v n

slide-51
SLIDE 51

Graphics & Visualization: Principles & Algorithms Chapter 13

(a) Spotlight set-up (b) Depth-buffer capture of the scene from the point of view of the light source (c) Final pass: Each fragment is tested for visibility against the light-space depth map

Rendering with Shadow Maps

51

slide-52
SLIDE 52

Graphics & Visualization: Principles & Algorithms Chapter 13

  • To apply this method to omni-directional sources:

Multiple shadow maps to cover the sphere around the point light source so that any direction on the unit sphere centered at pL is addressable

If multiple light sources participate in the scene, above procedure is duplicated for each one of them

  • Shadow information need not be recalculated at every frame in the

basic algorithm:

Only whenever the lit environment changes or the light source moves

Change in the camera viewpoint has no impact on the shadow map

  • Graphics hardware provide good quality shadows in real time:

Take advantage of projective texture-coordinate transformations

Take advantage of complex texture-component manipulations

Shadow Maps - Comments

52

slide-53
SLIDE 53

Graphics & Visualization: Principles & Algorithms Chapter 13

  • Rendering shadows with the shadow-map algorithm using hardware

acceleration and standard APIs requires a number of simple steps

  • Caution:

Operating on screen-order, scan-converted fragments:

Have to transform these eye-clip-space coordinates back to world space coordinates and then to light-clip space:

(13.5) where Mc : Rigid transformation that places the virtual camera in the world Pc : Camera-projection matrix

H/W Shadow Maps

53

1 · 1 frag frag frag frag frag

( , , ) · · ·

L L C C

x y z

 

      p P M M P p

slide-54
SLIDE 54

Graphics & Visualization: Principles & Algorithms Chapter 13

  • (If necessary) Compute the shadow map of one or more lights by

rendering the world from the light source's point of view

  • Maintain affine & projection transformation matrices used for the light-space

frustum set-up

  • Render unlit world into the normal-view frame buffer

The WCS-to-VCS transformation of this pass needs to be inverted and stored (see equation (13.5))

Requires all eye-clip-space fragments to be transformed to the normalized texture space of the shadow map

Transformed fragments are scaled and translated so that (x’frag , y’frag ) pair may correspond to the (u, v) shadow-map texture coordinates & z’frag can be compared to the stored, normalized depth map

  • The above procedure (camera view rendering) is easily

implemented both as a shader program and uisng the standard graphics pipeline of modern hardware in a single pass

54

H/W Shadow Maps (2)

slide-55
SLIDE 55

Graphics & Visualization: Principles & Algorithms Chapter 13

Shadow Map Trasnformations

55

slide-56
SLIDE 56

Graphics & Visualization: Principles & Algorithms Chapter 13

H/W Shadow Maps without Shaders

56

slide-57
SLIDE 57

Graphics & Visualization: Principles & Algorithms Chapter 13

  • Simplicity
  • Utilization of a well-established hardware-accelerated algorithm
  • No direct dependence on the scene complexity

Affected by the image-level depth comparisons & depth-map rendering time

  • Most attractive choice for complex, dynamic environments
  • Relying on the very generic Z-buffer algorithm:

Shadow maps can be used with any type of rendering primitive, provided that a depth buffer can be prepared from the rendered fragments of the geometry

  • They operate at fragment level  allow generation of shadows from

transparent geometry

If a fragment is A-culled in the light-space rendering pass, it will not produce a shadow in the eye-space pass

This fact can be exploited to produce elaborate shadows from simple geometry

Advantages of Shadow Maps

57

slide-58
SLIDE 58

Graphics & Visualization: Principles & Algorithms Chapter 13

  • They suffer from aliasing, which comes in various forms
  • A depth map has a limited resolution
  • Each shadow-map cell represents a sheared pyramidal ray projected

through the shadow frustum‘s near clip plane toward the world:

Footprint size sshadow

  • f the corresponding shadow texel

varies according to the distance from & the angle at which a surface is encountered

  • If sshadow

> pixel  shadow map is oversampled  magnification aliasing manifested as jagged shadow boundaries

  • If sshadow

< pixel  shadow map is undersampled  may cause noise artifacts (perspective aliasing)

Problems of Shadow Maps

58

slide-59
SLIDE 59

Graphics & Visualization: Principles & Algorithms Chapter 13

  • Aliasing in the shadow-map algorithm due to shadow-map

resolution and depth comparison inaccuracy:

Problems of Shadow Maps (2)

59

slide-60
SLIDE 60

Graphics & Visualization: Principles & Algorithms Chapter 13

  • Projection aliasing
  • ccurs when the projected light from the light

source becomes almost parallel to the surface

This can only be partially alleviated by increasing resolution of the shadow buffer at the expense, of course, of rendering time and texture memory

  • Depth-value quantization can cause serious aliasing problems:

Depth map (shadow map) granularity and numerical accuracy affect the shadow tests  poor and misplaced shadow boundaries

Problem is most noticeable in self-shadowing cases

  • Solution:

Offset depth values a little further away from the near depth value (0), according to the expected “worse” resolution of the shadow-map depth quantization

Problems of Shadow Maps (3)

60

slide-61
SLIDE 61

Graphics & Visualization: Principles & Algorithms Chapter 13

  • This depth bias:

Introduces a safety margin in the self-shadowing depth comparisons

Moves the shadows a little further away from the light source  appear detached from the shadow casters in some cases

  • In shadow-mapped light sources, there is always the trade-off

between range & shadow accuracy  smart ways to adjust the light frustum near and far planes are sought:

  • To use shadow maps with point lights 

multiple shadow maps have to be used to cover all directions around the light source

  • These maps are organized in a cubical configuration:

Light source at the center of the cube (allows a straightforward implementation in hardware-accelerated APIs)

Reasonable depth distortion due to the 90-degree aperture of resulting frusta

Problems of Shadow Maps (4)

61

slide-62
SLIDE 62

Graphics & Visualization: Principles & Algorithms Chapter 13

  • Problem:

Filtering the depth information of the shadow map would not effectively remove the aliasing  making the rendering of soft shadow boundaries impossible:

Near & far values on surface boundaries would be erroneously averaged  filtered depth values along the edges of objects would not correspond to the depicted geometry

  • Swapping the order of filtering & depth comparisons results in

Percentage Closer Filtering (PCF)

  • With PCF, the shadow value is no longer binary
  • A number of depth samples

distributed in the neighborhood of the final eye-space fragment to be rendered

are compared to the unfiltered shadow-map depth values

Percentage Closer Filtering

62

slide-63
SLIDE 63

Graphics & Visualization: Principles & Algorithms Chapter 13

  • Binary results are averaged
  • Final shadow value is the percentage of the surface area

corresponding to the fragment in shadow

  • PCF has been implemented in most software renderers and has been

adapted for modern GPUs

  • The original algorithm rendered the surfaces using micro-polygons
  • Now this is commonly implemented with multiple samples from the

shadow map

Percentage Closer Filtering (2)

63

slide-64
SLIDE 64

Graphics & Visualization: Principles & Algorithms Chapter 13

  • Percentage Closer Filtering (PCF)

vs shadow-map pre-filtering: Averaged map samples produce wrong depth-sort results & also can not avoid jagged edges. PCF filters produce smooth shadows

64

Percentage Closer Filtering (3)

slide-65
SLIDE 65

Graphics & Visualization: Principles & Algorithms Chapter 13

  • Post-filtering of the shadow samples produces smooth shadow

boundaries by default

Although desirable in some cases, the jagged pattern samples can still be noticeable, especially in a real-time implementation  PCF is sub-optimal

  • Another way to deal with aliasing & avoid significant loss of

shadow-boundary crispness:

Try to sample the object space over a grid that more closely matches the eye- space sample distribution of the world

  • Quality of the shadow depends on the relation between view

frustum & shadow frustum

Enhancing the Shadow Map Resolution

65

slide-66
SLIDE 66

Graphics & Visualization: Principles & Algorithms Chapter 13

Approaches:

  • Cascaded shadow maps

Create multiple shadow maps of same resolution but increasing area coverage and choose the appropriate shadow map according to the distance from the viewpoint

This is commonly used for outdoor lighting (distant light). Difficult to model arbitrary viewpoint-light position configurations.

Enhancing the Shadow Map Resolution (2)

66

slide-67
SLIDE 67

Graphics & Visualization: Principles & Algorithms Chapter 13

  • Perspective shadow maps

A modification of the shadow-map algorithm adapts the map resolution to the current view angle:

Instead of transforming & projecting the geometry expressed in the world coordinate system, the method creates the shadow maps after transforming the world and the light source into the camera-view clip-space (CSS)

Programmer must handle many special cases of relative camera/light position

Captured shadow map “sees” the scene after the camera perspective projection  perspective aliasing is significantly reduced

Need to update the shadow volume when the view changes, regardless of whether the world has changed or not

Enhancing the Shadow Map Resolution (3)

67

slide-68
SLIDE 68

Graphics & Visualization: Principles & Algorithms Chapter 13 68

Enhancing the Shadow Map Resolution (4)

Regular SM PSM

slide-69
SLIDE 69

Graphics & Visualization: Principles & Algorithms Chapter 13

  • PSM light/camera special configurations

69

Enhancing the Shadow Map Resolution (5)