Top Banner
© 2004 Tomas Akenine- Möller 1 Shadow Generation Hardware Vision day at DTU 2004 Tomas Akenine-Möller Lund University
29

© 2004 Tomas Akenine-Möller1 Shadow Generation Hardware Vision day at DTU 2004 Tomas Akenine-Möller Lund University.

Dec 22, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: © 2004 Tomas Akenine-Möller1 Shadow Generation Hardware Vision day at DTU 2004 Tomas Akenine-Möller Lund University.

© 2004 Tomas Akenine-Möller 1

Shadow Generation Hardware

Vision day at DTU 2004

Tomas Akenine-MöllerLund University

Page 2: © 2004 Tomas Akenine-Möller1 Shadow Generation Hardware Vision day at DTU 2004 Tomas Akenine-Möller Lund University.

© 2004 Tomas Akenine-Möller 2

Outline of my presentation

• Quick review of shadow volume algorithm– Zfail– Zpass

• A hierarchical shadow volume algorithm– Overall idea– Efficient hardware implementation

Page 3: © 2004 Tomas Akenine-Möller1 Shadow Generation Hardware Vision day at DTU 2004 Tomas Akenine-Möller Lund University.

© 2004 Tomas Akenine-Möller 3

The shadow volume algorithm

• Crow's (1977) idea, shadow volumes define volumes of space in shadow.

From the School ofLeonardo Da Vinci

Page 4: © 2004 Tomas Akenine-Möller1 Shadow Generation Hardware Vision day at DTU 2004 Tomas Akenine-Möller Lund University.

© 2004 Tomas Akenine-Möller 4

Shadow volume concept• Shadow volume concept

• Create volumes of space in shadow from each polygon in light.

• Each triangle creates 3 projecting quads

Page 5: © 2004 Tomas Akenine-Möller1 Shadow Generation Hardware Vision day at DTU 2004 Tomas Akenine-Möller Lund University.

© 2004 Tomas Akenine-Möller 5

Using the volume

• To test a point, count the number of polygons between it and the eye.

• If we look through more frontfacing than backfacing polygons, then in shadow.

frontfacing

backfacing

Page 6: © 2004 Tomas Akenine-Möller1 Shadow Generation Hardware Vision day at DTU 2004 Tomas Akenine-Möller Lund University.

© 2004 Tomas Akenine-Möller 6

Eye Location Problem

• If the eye location is inside one or more shadow volumes, count is wrong.

Eye problem fixed byclearing stencil buffer to

# of volumes eye is inside.

Page 7: © 2004 Tomas Akenine-Möller1 Shadow Generation Hardware Vision day at DTU 2004 Tomas Akenine-Möller Lund University.

© 2004 Tomas Akenine-Möller 7

Frustum Location Problem

• Frustum’s near (hither) plane overlaps a shadow volume, frontface counts missed

Some form of capping is neededto make the shadow volume whole again (not trivial, nor robust)

Page 8: © 2004 Tomas Akenine-Möller1 Shadow Generation Hardware Vision day at DTU 2004 Tomas Akenine-Möller Lund University.

© 2004 Tomas Akenine-Möller 8

Solution: Count Beyond Surface“Z-fail-algorithm”

• Render to stencil only when shadow volume Z >= stored Z!

must cap endsof shadow volumes

(or project to infinity, w=0 for vertices)

Page 9: © 2004 Tomas Akenine-Möller1 Shadow Generation Hardware Vision day at DTU 2004 Tomas Akenine-Möller Lund University.

© 2004 Tomas Akenine-Möller 9

Why This Works

• (f - b) in front of plane = (b - f) in back

2-2 = 0

2 = 2

1 = 2-1

red - violet

violet - red

Page 10: © 2004 Tomas Akenine-Möller1 Shadow Generation Hardware Vision day at DTU 2004 Tomas Akenine-Möller Lund University.

© 2004 Tomas Akenine-Möller 10

Merging shadow volumes• Edge shared by two polygons facing the

light creates front and backfacing quad.

This interior edge makestwo quads, which cancel out

Instead, useonly potentialsilhouetteedges as seenfrom the light:

Page 11: © 2004 Tomas Akenine-Möller1 Shadow Generation Hardware Vision day at DTU 2004 Tomas Akenine-Möller Lund University.

© 2004 Tomas Akenine-Möller 11

Z-pass by exampleW

hat

we

have

...

Wha

t w

e w

nat.

..

Page 12: © 2004 Tomas Akenine-Möller1 Shadow Generation Hardware Vision day at DTU 2004 Tomas Akenine-Möller Lund University.

© 2004 Tomas Akenine-Möller 12

Z-fail by example

Page 13: © 2004 Tomas Akenine-Möller1 Shadow Generation Hardware Vision day at DTU 2004 Tomas Akenine-Möller Lund University.

© 2004 Tomas Akenine-Möller 13

Are there any work on accelerating shadow volume rendering?

• When we started with this project, NVIDIA’s UltraShadow technique was the only existing algorithm

• UltraShadows – two things:– Extra pipes...– Depth bounds

• Check out EGSR 2004 – several interesting shadow papers:– Lloyd et al, ”CC Shadow Volumes”– Chan and Durand: Hybrid Shadow map and volumes

Page 14: © 2004 Tomas Akenine-Möller1 Shadow Generation Hardware Vision day at DTU 2004 Tomas Akenine-Möller Lund University.

© 2004 Tomas Akenine-Möller 14

A Hierarchical Shadow Volume Algorithm

• Motivation: fillrate problem with shadow volume rendering• Correct result:

Page 15: © 2004 Tomas Akenine-Möller1 Shadow Generation Hardware Vision day at DTU 2004 Tomas Akenine-Möller Lund University.

© 2004 Tomas Akenine-Möller 15

Only ”dark shadow pixels” require per-pixel processing...

Page 16: © 2004 Tomas Akenine-Möller1 Shadow Generation Hardware Vision day at DTU 2004 Tomas Akenine-Möller Lund University.

© 2004 Tomas Akenine-Möller 16

Low-resolution version shadows (8x8 pixels)

Page 17: © 2004 Tomas Akenine-Möller1 Shadow Generation Hardware Vision day at DTU 2004 Tomas Akenine-Möller Lund University.

© 2004 Tomas Akenine-Möller 17

Green tiles may contain a shadow boundary - others are correct

Page 18: © 2004 Tomas Akenine-Möller1 Shadow Generation Hardware Vision day at DTU 2004 Tomas Akenine-Möller Lund University.

© 2004 Tomas Akenine-Möller 18

Low-res (gray) + per-pixel computed boundaries (dark)

Page 19: © 2004 Tomas Akenine-Möller1 Shadow Generation Hardware Vision day at DTU 2004 Tomas Akenine-Möller Lund University.

© 2004 Tomas Akenine-Möller 19

How to detect boundary tiles?

8

8

Zmax

Zmin

Axis-aligned screen-space bounding box of a tile {

Fundamental observation: A tile can contain a shadow boundary, iff its bounding box is intersected by at least one shadow volume triangle.

Page 20: © 2004 Tomas Akenine-Möller1 Shadow Generation Hardware Vision day at DTU 2004 Tomas Akenine-Möller Lund University.

© 2004 Tomas Akenine-Möller 20

Low-resolution rasterizer(for each tile)

Delay

Shadow volume

Temp boundaryTemp stencil

Per-pixelrasterization

Copy to2-level stencil

Low-resolution rasterizer

sv polys

sv polys

(wait until end of sv)

Boundary?

sv polys

Update2-level stencil

YesNo

Page 21: © 2004 Tomas Akenine-Möller1 Shadow Generation Hardware Vision day at DTU 2004 Tomas Akenine-Möller Lund University.

© 2004 Tomas Akenine-Möller 21

Two-pass rasterization

1. Low-res rasterization & boundary test classifications ready only when entire

shadow volume processed

2. Wait by using a delay stream stores compressed vertices and render

states

3. Per-pixel rasterization of boundary tiles skip rasterization to tiles that are fully in

shadow or fully lit, because the results are already known

Page 22: © 2004 Tomas Akenine-Möller1 Shadow Generation Hardware Vision day at DTU 2004 Tomas Akenine-Möller Lund University.

© 2004 Tomas Akenine-Möller 22

How to detect begin/end of shadow volume?

• You will have to tell the algorithm about this

• Send a marker down the pipeline– Beginning of shadow volume– End of shadow volume– Need new API calls

• E.g. glBeginShadowVolume()• glEndShadowVolume()

Page 23: © 2004 Tomas Akenine-Möller1 Shadow Generation Hardware Vision day at DTU 2004 Tomas Akenine-Möller Lund University.

© 2004 Tomas Akenine-Möller 23

Stencil buffer updates

• Could write all 64 values per tile– Bandwidth problem

• Two-level stencil buffer saves the day– [Smin, Smax] per tile

– Always test the higher level first!– Often no need to validate per-pixel values

Page 24: © 2004 Tomas Akenine-Möller1 Shadow Generation Hardware Vision day at DTU 2004 Tomas Akenine-Möller Lund University.

© 2004 Tomas Akenine-Möller 24

Speeding up Overlapping Shadow Volumes

• Several shadow volumes per light source

• The shadow area grows monotonically when more shadow volumes added– If tile already in shadow, skip rasterization

No need torasterize shadowtwice!

Page 25: © 2004 Tomas Akenine-Möller1 Shadow Generation Hardware Vision day at DTU 2004 Tomas Akenine-Möller Lund University.

© 2004 Tomas Akenine-Möller 25

New hardware

• New on-chip buffers– Two-level stencil buffer

• beneficial for other computations too

– Tile classification buffer (cache)• need multiple buffers for pipelined operation• allocate from external memory, use through cache

• Delay stream (if not already in there)• New logic

– Low-res rasterization (trivial)– Bounding box intersection (must be robust!)

Page 26: © 2004 Tomas Akenine-Möller1 Shadow Generation Hardware Vision day at DTU 2004 Tomas Akenine-Möller Lund University.

© 2004 Tomas Akenine-Möller 26

Algorithm animationShow animation

Page 27: © 2004 Tomas Akenine-Möller1 Shadow Generation Hardware Vision day at DTU 2004 Tomas Akenine-Möller Lund University.

© 2004 Tomas Akenine-Möller 27

Results

Page 28: © 2004 Tomas Akenine-Möller1 Shadow Generation Hardware Vision day at DTU 2004 Tomas Akenine-Möller Lund University.

© 2004 Tomas Akenine-Möller 28

The end

• Questions?

• Publication: Timo Aila, and Tomas Akenine-Möller, “A Hierarchical Shadow Volume Algorithm”, accepted for Graphics Hardware 2004.

Page 29: © 2004 Tomas Akenine-Möller1 Shadow Generation Hardware Vision day at DTU 2004 Tomas Akenine-Möller Lund University.

© 2004 Tomas Akenine-Möller 29

Misc notes

• A highly tesselated sphere will not add much more BW usage than a sphere with few triangles