Real-Time Rendering - UBIagomes/cig/teoricas/06-Shadows-Intro.pdf · Fake Hardware Assisted...

30
Real-Time Rendering Intro to Shadows CSE 781 Prof. Roger Crawfis

Transcript of Real-Time Rendering - UBIagomes/cig/teoricas/06-Shadows-Intro.pdf · Fake Hardware Assisted...

Page 1: Real-Time Rendering - UBIagomes/cig/teoricas/06-Shadows-Intro.pdf · Fake Hardware Assisted Pre-computed Ray tracing Rather slow for large scenes Shadows are pre-computed and stored

Real-Time Rendering Intro to Shadows

CSE 781 Prof. Roger Crawfis

Page 2: Real-Time Rendering - UBIagomes/cig/teoricas/06-Shadows-Intro.pdf · Fake Hardware Assisted Pre-computed Ray tracing Rather slow for large scenes Shadows are pre-computed and stored

Shadows can be Wonderful!

Page 3: Real-Time Rendering - UBIagomes/cig/teoricas/06-Shadows-Intro.pdf · Fake Hardware Assisted Pre-computed Ray tracing Rather slow for large scenes Shadows are pre-computed and stored

Importance of Shadows

Trapezoid?

Page 4: Real-Time Rendering - UBIagomes/cig/teoricas/06-Shadows-Intro.pdf · Fake Hardware Assisted Pre-computed Ray tracing Rather slow for large scenes Shadows are pre-computed and stored

Importance of Shadows

l Cue to object-object relationship. l Provides additional depth cue.

Page 5: Real-Time Rendering - UBIagomes/cig/teoricas/06-Shadows-Intro.pdf · Fake Hardware Assisted Pre-computed Ray tracing Rather slow for large scenes Shadows are pre-computed and stored

Importance of Shadows

Page 6: Real-Time Rendering - UBIagomes/cig/teoricas/06-Shadows-Intro.pdf · Fake Hardware Assisted Pre-computed Ray tracing Rather slow for large scenes Shadows are pre-computed and stored

Importance of Shadows

Page 7: Real-Time Rendering - UBIagomes/cig/teoricas/06-Shadows-Intro.pdf · Fake Hardware Assisted Pre-computed Ray tracing Rather slow for large scenes Shadows are pre-computed and stored

Importance of Shadows

Page 8: Real-Time Rendering - UBIagomes/cig/teoricas/06-Shadows-Intro.pdf · Fake Hardware Assisted Pre-computed Ray tracing Rather slow for large scenes Shadows are pre-computed and stored

Importance of Shadows

Without shadows With shadows

Page 9: Real-Time Rendering - UBIagomes/cig/teoricas/06-Shadows-Intro.pdf · Fake Hardware Assisted Pre-computed Ray tracing Rather slow for large scenes Shadows are pre-computed and stored

Importance of Shadows

Page 10: Real-Time Rendering - UBIagomes/cig/teoricas/06-Shadows-Intro.pdf · Fake Hardware Assisted Pre-computed Ray tracing Rather slow for large scenes Shadows are pre-computed and stored

Definition

Shadow: Darkness caused when part or all of the illumination from a light source is blocked by an occluder.

light

occluder

shadow

Page 11: Real-Time Rendering - UBIagomes/cig/teoricas/06-Shadows-Intro.pdf · Fake Hardware Assisted Pre-computed Ray tracing Rather slow for large scenes Shadows are pre-computed and stored

Terminology (area) light source

receiver shadow

occluder

umbra

penumbra

•  umbra – fully shadowed region •  penumbra – partially shadowed region

Page 12: Real-Time Rendering - UBIagomes/cig/teoricas/06-Shadows-Intro.pdf · Fake Hardware Assisted Pre-computed Ray tracing Rather slow for large scenes Shadows are pre-computed and stored

Terminology

Page 13: Real-Time Rendering - UBIagomes/cig/teoricas/06-Shadows-Intro.pdf · Fake Hardware Assisted Pre-computed Ray tracing Rather slow for large scenes Shadows are pre-computed and stored

Definition: Shadow Volume

l  Volume formed by extruding the occluder from the light source.

l  Open and infinite l  Space inside the

volume is in shadow. l  Space outside the

volume is not.

Page 14: Real-Time Rendering - UBIagomes/cig/teoricas/06-Shadows-Intro.pdf · Fake Hardware Assisted Pre-computed Ray tracing Rather slow for large scenes Shadows are pre-computed and stored

14

umbra umbra

penumbra

point light

extended light

Hard shadow Soft shadow

Hard and soft shadows

Page 15: Real-Time Rendering - UBIagomes/cig/teoricas/06-Shadows-Intro.pdf · Fake Hardware Assisted Pre-computed Ray tracing Rather slow for large scenes Shadows are pre-computed and stored

Soft Shadows

l Shadow is a function of the area of the light source and the distance.

Page 16: Real-Time Rendering - UBIagomes/cig/teoricas/06-Shadows-Intro.pdf · Fake Hardware Assisted Pre-computed Ray tracing Rather slow for large scenes Shadows are pre-computed and stored

Hard shadow creation

•  For every pixel, light source is either visible or occluded

Page 17: Real-Time Rendering - UBIagomes/cig/teoricas/06-Shadows-Intro.pdf · Fake Hardware Assisted Pre-computed Ray tracing Rather slow for large scenes Shadows are pre-computed and stored

Soft shadow creation

Page 18: Real-Time Rendering - UBIagomes/cig/teoricas/06-Shadows-Intro.pdf · Fake Hardware Assisted Pre-computed Ray tracing Rather slow for large scenes Shadows are pre-computed and stored

Issues Affecting Shadows

l  Scene Complexity l  Number of light sources l  Types of light sources l  Number of occluders l  Number of receivers l  Position, size and strength of lights

l  Static vs. dynamic l  Objects l  Lighting

l  Self-shadowing l  Opaque vs. transparent objects l  Precision or realism of shadows

Page 19: Real-Time Rendering - UBIagomes/cig/teoricas/06-Shadows-Intro.pdf · Fake Hardware Assisted Pre-computed Ray tracing Rather slow for large scenes Shadows are pre-computed and stored

19

Current Shadow Methods

l There exist a very large number of methods

l We are interested in methods suitable for interactive walkthroughs, speed is crucial

l We will classify them on complexity:

no shadows Sharp shadows Soft shadows Special effects

Page 20: Real-Time Rendering - UBIagomes/cig/teoricas/06-Shadows-Intro.pdf · Fake Hardware Assisted Pre-computed Ray tracing Rather slow for large scenes Shadows are pre-computed and stored

Sharp Shadows

l Point or directional light sources

Fake Pre-computed Hardware Assisted Ray tracing

Rather slow for large scenes

Shadows are pre-computed and stored for repeated use • Detail polygons

Use of specialized hardware to generate shadows • Shadow texture • Shadow volumes

Fast but often inadequate • Billboard • Projected object

Page 21: Real-Time Rendering - UBIagomes/cig/teoricas/06-Shadows-Intro.pdf · Fake Hardware Assisted Pre-computed Ray tracing Rather slow for large scenes Shadows are pre-computed and stored

Soft Shadows

l Area light sources

Pre-computed Hardware Assisted Ray-based

Mainly analytical computation on the geometry of the source • Light maps • Discontinuity Meshing

Mainly treat the light source as a collection of points • Accumulation buffer • Shadow volumes • Shadow textures

Radiosity • Distributed ray tracing • Cone Tracing

This is also pre-computed • Hemi-cube • Ray casing

Page 22: Real-Time Rendering - UBIagomes/cig/teoricas/06-Shadows-Intro.pdf · Fake Hardware Assisted Pre-computed Ray tracing Rather slow for large scenes Shadows are pre-computed and stored

Approaches

l Ad-hoc / Custom l  Artist directed shadows l  Very simple and constrained conditions.

l Analytical l  Find all boundaries within the umbra /

penumbra. Precise. l Sampling

l  Probabilistic sampling of whether a particular fragment is within the umbra / penumbra. With enough samples can be made precise.

Page 23: Real-Time Rendering - UBIagomes/cig/teoricas/06-Shadows-Intro.pdf · Fake Hardware Assisted Pre-computed Ray tracing Rather slow for large scenes Shadows are pre-computed and stored

Shadows and Illumination

l Given a point is in shadow, how do we change the illumination?

Light Source

Viewer

Point is in shadow

Occluder

Point is lit

Page 24: Real-Time Rendering - UBIagomes/cig/teoricas/06-Shadows-Intro.pdf · Fake Hardware Assisted Pre-computed Ray tracing Rather slow for large scenes Shadows are pre-computed and stored

Shadows and Illumination

l Illumination model with included visibility term:

l Visibility term determines if a light can “see” the point

l If point is in shadow, only ambient term applies

24

Visibility Term: 0 or 1 for point/directional lights

For all lights

∑=

⋅+⋅+=N

i

nsdliaa kkIVIkI

i1

)),0max(),0max(( ii rvln

Page 25: Real-Time Rendering - UBIagomes/cig/teoricas/06-Shadows-Intro.pdf · Fake Hardware Assisted Pre-computed Ray tracing Rather slow for large scenes Shadows are pre-computed and stored

Shadows and OpenGL

l  In OpenGL we send the geometry for a model through the pipeline.

l The Visibility function, V, is not a constant in our illumination model. l  Per vertex information? l  Per fragment using a texture map? l  Some per-pixel masking function?

l Recall that we need a V for each light.

Page 26: Real-Time Rendering - UBIagomes/cig/teoricas/06-Shadows-Intro.pdf · Fake Hardware Assisted Pre-computed Ray tracing Rather slow for large scenes Shadows are pre-computed and stored

Shadows and Illumination

l Note, we can re-write our illumination equation:

l Negative light.

( )[ ]∑

=

=

=

−−+=

+=

⋅+⋅+=

N

iiliilaa

N

iiliaa

N

i

nsdliaa

cIVcIIk

cIVIk

kkIVIkI

ii

i

i

1

1

1

1

)),0max(),0max(( ii rvln

ci

Page 27: Real-Time Rendering - UBIagomes/cig/teoricas/06-Shadows-Intro.pdf · Fake Hardware Assisted Pre-computed Ray tracing Rather slow for large scenes Shadows are pre-computed and stored

Masking in OpenGL

l OpenGL provides several ways of masking pixels l  Stencil buffer with stencil test l  Alpha test with fragment’s alpha values l  Blending with fragment’s and framebuffer’s

alpha values. l  Texture sampling and shaders.

Page 28: Real-Time Rendering - UBIagomes/cig/teoricas/06-Shadows-Intro.pdf · Fake Hardware Assisted Pre-computed Ray tracing Rather slow for large scenes Shadows are pre-computed and stored

Negative Light

l Algorithm (single light) l  Render receivers with full illumination l  For each occluder

l  Project occluder from the light to the receivers l  Darken (set to black or ambient) the illumination.

Page 29: Real-Time Rendering - UBIagomes/cig/teoricas/06-Shadows-Intro.pdf · Fake Hardware Assisted Pre-computed Ray tracing Rather slow for large scenes Shadows are pre-computed and stored

Negative Light

l With multiple light sources this technique does not work. If the algorithm simply sets the pixels to black (or ambient), then it will erases the contributions from all light sources.

Page 30: Real-Time Rendering - UBIagomes/cig/teoricas/06-Shadows-Intro.pdf · Fake Hardware Assisted Pre-computed Ray tracing Rather slow for large scenes Shadows are pre-computed and stored

Positive Light

l Algorithm l  Render scene with ambient illumination only l  For each light source

l  Render scene with illumination from this light only

l  Scale illumination by shadow mask l  Add contribution to frame buffer