A Real-Time Soft Shadow Volume Algorithm DTU Vision days Tomas Akenine-Möller Department of...

28
A Real-Time A Real-Time Soft Shadow Volume Soft Shadow Volume Algorithm Algorithm DTU Vision DTU Vision days days Tomas Akenine-Möller Tomas Akenine-Möller Department of Computer Engineering Department of Computer Engineering Chalmers University of Technology Chalmers University of Technology Sweden Sweden 2003-06-13 2003-06-13
  • date post

    20-Dec-2015
  • Category

    Documents

  • view

    219
  • download

    3

Transcript of A Real-Time Soft Shadow Volume Algorithm DTU Vision days Tomas Akenine-Möller Department of...

Page 1: A Real-Time Soft Shadow Volume Algorithm DTU Vision days Tomas Akenine-Möller Department of Computer Engineering Chalmers University of Technology Sweden2003-06-13.

A Real-Time A Real-Time Soft Shadow Volume Soft Shadow Volume AlgorithmAlgorithm

DTU Vision DTU Vision daysdays

Tomas Akenine-MöllerTomas Akenine-MöllerDepartment of Computer EngineeringDepartment of Computer EngineeringChalmers University of TechnologyChalmers University of TechnologySwedenSweden2003-06-132003-06-13

Page 2: A Real-Time Soft Shadow Volume Algorithm DTU Vision days Tomas Akenine-Möller Department of Computer Engineering Chalmers University of Technology Sweden2003-06-13.

Copyright 2003 Tomas Akenine-Möller 2

Shadow GenerationShadow Generation

• Why?• In computer graphics, shadows are not

generated automatically• Must create algorithms for this!• Shadows help with:

– Realism– Atmosphere– Spatial relationships

Page 3: A Real-Time Soft Shadow Volume Algorithm DTU Vision days Tomas Akenine-Möller Department of Computer Engineering Chalmers University of Technology Sweden2003-06-13.

Copyright 2003 Tomas Akenine-Möller 3

Spatial relationshipsSpatial relationships

Page 4: A Real-Time Soft Shadow Volume Algorithm DTU Vision days Tomas Akenine-Möller Department of Computer Engineering Chalmers University of Technology Sweden2003-06-13.

Copyright 2003 Tomas Akenine-Möller 4

Other classical images on the need for Other classical images on the need for shadowsshadows

Images courtesy of Micheal McCool, University of Waterloo

Page 5: A Real-Time Soft Shadow Volume Algorithm DTU Vision days Tomas Akenine-Möller Department of Computer Engineering Chalmers University of Technology Sweden2003-06-13.

Copyright 2003 Tomas Akenine-Möller 5

Hard vs soft shadowsHard vs soft shadows• Two different light source types

point source

umbra

area source

umbrapenumbra

Page 6: A Real-Time Soft Shadow Volume Algorithm DTU Vision days Tomas Akenine-Möller Department of Computer Engineering Chalmers University of Technology Sweden2003-06-13.

Copyright 2003 Tomas Akenine-Möller 6

Example: hard vs softExample: hard vs soft

Point light Point light sourcesource

Area light Area light sourcesource

umbrumbraa

penumbrpenumbraa

umbrumbraa

Page 7: A Real-Time Soft Shadow Volume Algorithm DTU Vision days Tomas Akenine-Möller Department of Computer Engineering Chalmers University of Technology Sweden2003-06-13.

Copyright 2003 Tomas Akenine-Möller 7

Ways of thinking about Ways of thinking about shadowsshadows

• As separate objects (like Peter Pan's shadow)

• As volumes of space that are dark• As places not seen from a light source

looking at the scene

• We base our work on Crow’s shadow volume algorithm (option 2 above) from 1977

Page 8: A Real-Time Soft Shadow Volume Algorithm DTU Vision days Tomas Akenine-Möller Department of Computer Engineering Chalmers University of Technology Sweden2003-06-13.

Copyright 2003 Tomas Akenine-Möller 8

Shadow mappingShadow mapping• Shadow mapping is used in Pixar’s rendering SW,

but also in real time using graphics hardware• Render from light’s view (white is far and black is

near)• Use pixel shader to

determine if point is in shadow

• Use percentage-closer filtering for better quality

• Pros and cons:– BAD: Discrete representation– BAD: Incorrect self-shadowing– BAD: frustum limited– GOOD: can reuse SM if geometry & light static– GOOD: can use any shadow casters and receivers

Page 9: A Real-Time Soft Shadow Volume Algorithm DTU Vision days Tomas Akenine-Möller Department of Computer Engineering Chalmers University of Technology Sweden2003-06-13.

Copyright 2003 Tomas Akenine-Möller 9

(Hard) Shadow volumes(Hard) Shadow volumesVery popular method for real Very popular method for real timetimeShadow volume conceptCreate volumes of space in shadow

from each polygon in light.Each triangle creates 3 projecting

quads

Page 10: A Real-Time Soft Shadow Volume Algorithm DTU Vision days Tomas Akenine-Möller Department of Computer Engineering Chalmers University of Technology Sweden2003-06-13.

Copyright 2003 Tomas Akenine-Möller 10

Using the Shadow VolumeUsing the Shadow 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 11: A Real-Time Soft Shadow Volume Algorithm DTU Vision days Tomas Akenine-Möller Department of Computer Engineering Chalmers University of Technology Sweden2003-06-13.

Copyright 2003 Tomas Akenine-Möller 11

Soft shadow algorithms in Soft shadow algorithms in generalgeneral

Fundamental problem in computer graphics

Inherently difficult!

Page 12: A Real-Time Soft Shadow Volume Algorithm DTU Vision days Tomas Akenine-Möller Department of Computer Engineering Chalmers University of Technology Sweden2003-06-13.

Copyright 2003 Tomas Akenine-Möller 12

A Real-Time Soft Shadow Volume A Real-Time Soft Shadow Volume AlgorithmAlgorithm• Insight

• Given that there is geometry inside a wedge, how can we compute the light contribution accurately?

Page 13: A Real-Time Soft Shadow Volume Algorithm DTU Vision days Tomas Akenine-Möller Department of Computer Engineering Chalmers University of Technology Sweden2003-06-13.

Copyright 2003 Tomas Akenine-Möller 13

Visibility computationVisibility computation• Really want to compute how much we can

see of the light source

Page 14: A Real-Time Soft Shadow Volume Algorithm DTU Vision days Tomas Akenine-Möller Department of Computer Engineering Chalmers University of Technology Sweden2003-06-13.

Copyright 2003 Tomas Akenine-Möller 14

Precomputed coverage in 4D Precomputed coverage in 4D texturestextures

Page 15: A Real-Time Soft Shadow Volume Algorithm DTU Vision days Tomas Akenine-Möller Department of Computer Engineering Chalmers University of Technology Sweden2003-06-13.

Copyright 2003 Tomas Akenine-Möller 15

4D textures used as look-up 4D textures used as look-up tabletable

• Enables– Fast computation– Textured light sources

(e.g., fire)

• Texturing is normally very fast on today’s graphics hardware because of:– Texture caches– Intelligent prefetching

Page 16: A Real-Time Soft Shadow Volume Algorithm DTU Vision days Tomas Akenine-Möller Department of Computer Engineering Chalmers University of Technology Sweden2003-06-13.

Copyright 2003 Tomas Akenine-Möller 16

More examples using textured More examples using textured lightslights

Page 17: A Real-Time Soft Shadow Volume Algorithm DTU Vision days Tomas Akenine-Möller Department of Computer Engineering Chalmers University of Technology Sweden2003-06-13.

Copyright 2003 Tomas Akenine-Möller 17

The Soft Shadow Volume The Soft Shadow Volume AlgorithmAlgorithm• 1st pass: Render hard shadow quads (as usual)

– To be sure that we register when we enter/exit umbra

• 2nd pass: compensate for overstated umbra

Page 18: A Real-Time Soft Shadow Volume Algorithm DTU Vision days Tomas Akenine-Möller Department of Computer Engineering Chalmers University of Technology Sweden2003-06-13.

Copyright 2003 Tomas Akenine-Möller 18

Example of how it worksExample of how it works

Page 19: A Real-Time Soft Shadow Volume Algorithm DTU Vision days Tomas Akenine-Möller Department of Computer Engineering Chalmers University of Technology Sweden2003-06-13.

Copyright 2003 Tomas Akenine-Möller 19

Some details on our hardware Some details on our hardware implementation…implementation…

• Performance was poor when we finally got a higly programmable graphics card– SW rendering > HW rendering!

• Had to fine tune the implementation:– Tighter wedges for rectangular lights– Optimized pixel shaders– Frame buffer blending– Culling

Page 20: A Real-Time Soft Shadow Volume Algorithm DTU Vision days Tomas Akenine-Möller Department of Computer Engineering Chalmers University of Technology Sweden2003-06-13.

Copyright 2003 Tomas Akenine-Möller 20

Optimized pixel shadersOptimized pixel shaders

• Have implemented both spherical and rectangular light sources

• Rectangular case:– Create frustum from point-to-be-shaded, p, to light, and clip edge to frustum

– Transform so that p is in (0,0,0) and normal of light parallel to z-axis

– Use projection matrix to transform to clip-space

– Clip in homogeneous space, divide by w– Use 4D texture of clipped endpoints

• Shaders are about 60 instructions long

Page 21: A Real-Time Soft Shadow Volume Algorithm DTU Vision days Tomas Akenine-Möller Department of Computer Engineering Chalmers University of Technology Sweden2003-06-13.

Copyright 2003 Tomas Akenine-Möller 21

Reserved for overflow

Frame buffer blendingFrame buffer blending• Need: add and subtract hires-values to V-buffer

– Need >8 bits if you want 256 shadow levels– Not available on Radeon 9700 or GeForce FX!

• Solution: split value across 8-bit components• Use 5 bits of overflow: allows 32 overlapping

wedges7 6 5 4 3 2 1 0 One byte

7 6 5 4 3 2 1 0Bit 3

Bit 4Bit 5• Gives a 12-bit coverage value using 4 bytes• To create final value using LUT:

– 8*XXXXX543+XXXX210=YYYYY543210

• Two rendering passes: one for additive and one for subtractive values

Page 22: A Real-Time Soft Shadow Volume Algorithm DTU Vision days Tomas Akenine-Möller Department of Computer Engineering Chalmers University of Technology Sweden2003-06-13.

Copyright 2003 Tomas Akenine-Möller 22

Shadow receiver

wedge

Pixel shader cullingPixel shader culling• PS only change V-buffer if (x,y,z) is inside

wedge cull everything else!• Culling:

– Frontfacing (FF) tris of wedge rendered into stencil buffer if tris in front of rendered geometry

– Render BF tris where stencil is one, and tris are farther away than rendered geometry

– Execute pixel shader that passes these testsFF

BF

Page 23: A Real-Time Soft Shadow Volume Algorithm DTU Vision days Tomas Akenine-Möller Department of Computer Engineering Chalmers University of Technology Sweden2003-06-13.

Copyright 2003 Tomas Akenine-Möller 23

ResultsResults

• Optimizations for graphics hardware:– Gives real-time performance– This is the only existing algorithm with

this kind of performance, and with high quality (no sampling artifacts)

– At least as far as we know…

Video

Page 24: A Real-Time Soft Shadow Volume Algorithm DTU Vision days Tomas Akenine-Möller Department of Computer Engineering Chalmers University of Technology Sweden2003-06-13.

Copyright 2003 Tomas Akenine-Möller 24

Two artifacts!Two artifacts!• Overlapping geometry is

handled incorrectly

• Single silhouette error

Page 25: A Real-Time Soft Shadow Volume Algorithm DTU Vision days Tomas Akenine-Möller Department of Computer Engineering Chalmers University of Technology Sweden2003-06-13.

Copyright 2003 Tomas Akenine-Möller 25

For better quality, use 2x2 area For better quality, use 2x2 area lights…lights…(and 2x2 does not cost 4 times as (and 2x2 does not cost 4 times as much!)much!)

Page 26: A Real-Time Soft Shadow Volume Algorithm DTU Vision days Tomas Akenine-Möller Department of Computer Engineering Chalmers University of Technology Sweden2003-06-13.

Copyright 2003 Tomas Akenine-Möller 26

On Shadow Volume Silhouettes On Shadow Volume Silhouettes (SVS)(SVS)• We use silhouette edges as seen from light• Many people believe that a SVS vertex is

connected to two edges

• We prove that SVS vertices can be connected to any even number of edges

Page 27: A Real-Time Soft Shadow Volume Algorithm DTU Vision days Tomas Akenine-Möller Department of Computer Engineering Chalmers University of Technology Sweden2003-06-13.

Copyright 2003 Tomas Akenine-Möller 27

Our soft shadow contributionsOur soft shadow contributions

• Work done with Ulf Assarsson (soon PhD!)

• Publications:– Tomas Akenine-Möller and Ulf Assarsson, “Rapid Soft Shadows

on Arbitrary Surfaces using Penumbra Wedges,” Eurographics Workshop on Rendering 2002, pp. 309--318, June 2002.

– Ulf Assarsson and Tomas Akenine-Möller, “Optimized and Generalized Real-Time Soft Shadows using Penumbra Wedges,” to appear in The Visual Computer, 2003.

– Ulf Assarsson and Tomas Akenine-Möller, “A Geometry-based Soft Shadow Volume Algorithm using Graphics Hardware,” to appear in SIGGRAPH 2003, July 2003.

– Ulf Assarsson, Michael Dougherty, Michael Mounier, and Tomas Akenine-Möller, “An Optimized Soft Shadow Volume Algorithm with Real-Time Performance,” to appear in Graphics Hardware 2003.

– Tomas Akenine-Möller and Ulf Assarsson, “On Shadow Volume Silhouettes,” submitted to journal of graphics tools, April 2003.

Page 28: A Real-Time Soft Shadow Volume Algorithm DTU Vision days Tomas Akenine-Möller Department of Computer Engineering Chalmers University of Technology Sweden2003-06-13.

Thanks for listening…Thanks for listening…

Over to real-time soft shadow Over to real-time soft shadow demo…demo…

1024 hard shadow samples Our algorithm