31
Cinematic Depth Of Field How to make big filters cheap Karl Hillesland Sean Skelton AMD

Cinematic Depth of Field€¦ · Depth of Field Optics Pinhole Camera Film Tiny hole Real Camera Wikipedia, User Hanabi123, CC BY-SA 3.0

  • Upload
    others

  • View
    7

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Cinematic Depth of Field€¦ · Depth of Field Optics Pinhole Camera Film Tiny hole Real Camera Wikipedia, User Hanabi123, CC BY-SA 3.0

Cinematic Depth Of FieldHow to make big filters cheap

Karl HilleslandSean SkeltonAMD

Page 2: Cinematic Depth of Field€¦ · Depth of Field Optics Pinhole Camera Film Tiny hole Real Camera Wikipedia, User Hanabi123, CC BY-SA 3.0

Outline

● Depth of Field

● Real-time approximations

● Fast Filter Spreading

● Implementation

Page 3: Cinematic Depth of Field€¦ · Depth of Field Optics Pinhole Camera Film Tiny hole Real Camera Wikipedia, User Hanabi123, CC BY-SA 3.0

Depth of Field

Page 4: Cinematic Depth of Field€¦ · Depth of Field Optics Pinhole Camera Film Tiny hole Real Camera Wikipedia, User Hanabi123, CC BY-SA 3.0

Depth of Field Optics

Pinhole Camera

Film Tiny hole

Real CameraWikipedia, User Hanabi123,

CC BY-SA 3.0

Page 5: Cinematic Depth of Field€¦ · Depth of Field Optics Pinhole Camera Film Tiny hole Real Camera Wikipedia, User Hanabi123, CC BY-SA 3.0

Thin Lens Model

Lens focuses a distance onto film (blue in this case)

f = focal length

A = aperture width

c = circle of confusion (CoC) on film

C = CoC in world Film

From Wikipedia “Circle of Confusion”

Page 6: Cinematic Depth of Field€¦ · Depth of Field Optics Pinhole Camera Film Tiny hole Real Camera Wikipedia, User Hanabi123, CC BY-SA 3.0

Gather MethodsInput (in focus)

For each output:What do we see?

Output

for i,j:

CoC = f ( z(i,j) – zInFocus )

Out_ij = Gather( CoC );

Sharp edge

Focus

Film Too Close

OverlapGreen COCBlue in focus

Page 7: Cinematic Depth of Field€¦ · Depth of Field Optics Pinhole Camera Film Tiny hole Real Camera Wikipedia, User Hanabi123, CC BY-SA 3.0

Scatter MethodsWhere does each input go?

Input (in focus) Output

for i,j:

CoC = f ( z(i,j) – zInFocus );

Spread( Input_ij, CoC );

Draw a sprite for each input pixel

Page 8: Cinematic Depth of Field€¦ · Depth of Field Optics Pinhole Camera Film Tiny hole Real Camera Wikipedia, User Hanabi123, CC BY-SA 3.0

Gather from SAT

Compute Summed Area Table

Gather with 4 lookups

Page 9: Cinematic Depth of Field€¦ · Depth of Field Optics Pinhole Camera Film Tiny hole Real Camera Wikipedia, User Hanabi123, CC BY-SA 3.0

Summed Area Table

D

(x,y) contains

𝑖=0

𝑥

𝑗=0

𝑦

𝐼𝑖,𝑗

(𝑥, 𝑦)

Page 10: Cinematic Depth of Field€¦ · Depth of Field Optics Pinhole Camera Film Tiny hole Real Camera Wikipedia, User Hanabi123, CC BY-SA 3.0

A

Gather from SAT

=

B

C

D

𝑥0 𝑥1

𝑦0

𝑦1

𝑆𝐴 − 𝑆𝐵 −𝑆𝐶 +𝑆𝐷𝑆𝐴 =

𝑖=0

𝑥1

𝑗=0

𝑦1

𝐼𝑖,𝑗 𝑆𝐵 =

𝑖=0

𝑥1

𝑗=0

𝑦0

𝐼𝑖,𝑗

𝑥1𝑦0

𝑥1𝑦1

Page 11: Cinematic Depth of Field€¦ · Depth of Field Optics Pinhole Camera Film Tiny hole Real Camera Wikipedia, User Hanabi123, CC BY-SA 3.0

Gather SAT

Niceness

● O(1) in filter size

Problems

● Box filter

● Gather method

● Precision Problem

Page 12: Cinematic Depth of Field€¦ · Depth of Field Optics Pinhole Camera Film Tiny hole Real Camera Wikipedia, User Hanabi123, CC BY-SA 3.0

Fast Filter Spreading

● Fast Filter Spreading and its ApplicationsKosloff, Hensley, Barsky, UC Berkeley tech report.

● Scatter Method

● SAT in reverse

● Poke (add) deltas at the corners

● Then sum

Page 13: Cinematic Depth of Field€¦ · Depth of Field Optics Pinhole Camera Film Tiny hole Real Camera Wikipedia, User Hanabi123, CC BY-SA 3.0

Simple ExampleDesired Result

1 1

1 1 2 2

2 2

+ =

1 1

1 3 2

2 2

Page 14: Cinematic Depth of Field€¦ · Depth of Field Optics Pinhole Camera Film Tiny hole Real Camera Wikipedia, User Hanabi123, CC BY-SA 3.0

1 -1

-1 1

2 -2

-2 2

+ =

1 -1

2 -2

-1 1

-2 2

Simple ExampleAdding Deltas

Page 15: Cinematic Depth of Field€¦ · Depth of Field Optics Pinhole Camera Film Tiny hole Real Camera Wikipedia, User Hanabi123, CC BY-SA 3.0

1 -1

2 -2

-1 1

-2 2

1 1

2 2

-1 -1

-2 -2

1 1

1 3 2

2 2

Simple ExampleSumming for the result

Page 16: Cinematic Depth of Field€¦ · Depth of Field Optics Pinhole Camera Film Tiny hole Real Camera Wikipedia, User Hanabi123, CC BY-SA 3.0

Still Only 4 Each

1 -1

2 -2

-1 1

-2 2

1 1 1 1 1

1 1 1 1 1

1 1 1 1 1

1 1 1 3 3 2 2

1 1 1 3 3 2 2

2 2 2 2

2 2 2 2

Page 17: Cinematic Depth of Field€¦ · Depth of Field Optics Pinhole Camera Film Tiny hole Real Camera Wikipedia, User Hanabi123, CC BY-SA 3.0

Bartlett

1 -2 1

-2 4 -2

1 -2 1

2 integrations

1 -1 0

-1 1 0

0 0 0

After 1st

integration

Page 18: Cinematic Depth of Field€¦ · Depth of Field Optics Pinhole Camera Film Tiny hole Real Camera Wikipedia, User Hanabi123, CC BY-SA 3.0

Implementations

DOF FXSimple demo

Open source

LadybugBig demo

Closed source

Page 19: Cinematic Depth of Field€¦ · Depth of Field Optics Pinhole Camera Film Tiny hole Real Camera Wikipedia, User Hanabi123, CC BY-SA 3.0

Implementation Topics

● Weights and Normalization

● Fixed point math

● Atomics

Page 20: Cinematic Depth of Field€¦ · Depth of Field Optics Pinhole Camera Film Tiny hole Real Camera Wikipedia, User Hanabi123, CC BY-SA 3.0

Weights and Normalization

● Box filter: divide by area

● Bartlett: divide by area*area

● Other filters/weights possible

● Catch all:

● Accumulate weights in alpha

● Divide at the end

Page 21: Cinematic Depth of Field€¦ · Depth of Field Optics Pinhole Camera Film Tiny hole Real Camera Wikipedia, User Hanabi123, CC BY-SA 3.0

Fixed Point Math

● Atomics

● Precision

● Scale examples @ ~ 64 x 64, 32 bits

● 6*2 (box area) = 12 bits -> 20 remaining

● 6*4 = 24 bits -> 8 remaining

● 6*3 = 18 bits -> 14 remaining

Page 22: Cinematic Depth of Field€¦ · Depth of Field Optics Pinhole Camera Film Tiny hole Real Camera Wikipedia, User Hanabi123, CC BY-SA 3.0

Compute Shader Sample// Scale for fixed point and filter size

int4 intColor = normalizeBlurColor(float4(vColor, 1.0), blur_amount);

for (int i = 0; i < 9; ++i)

{

// Offset the location by location of the delta and padding

// Need to offset by (1,1) because the kernel is not centered

const int2 delta = bartlettData[i].xy * (blur_amount + 1);

int2 bufLoc = loc.xy + delta + padding + uint2(1, 1);

// Filter weight

const int delta_value = bartlettData[i].z;

Page 23: Cinematic Depth of Field€¦ · Depth of Field Optics Pinhole Camera Film Tiny hole Real Camera Wikipedia, User Hanabi123, CC BY-SA 3.0

Compute Shader Samplefor (int i = 0; i < 9; ++i)

{

// Offset (previous slide)

// Weight (previous slide)

// Write the delta

// Use interlocked add to prevent the threads from stepping on each other

// 4 atomics, including alpha channel for normalization.

InterlockedAddToBuffer(deltaBuffer, bufLoc, intColor * delta_value);

}

Page 24: Cinematic Depth of Field€¦ · Depth of Field Optics Pinhole Camera Film Tiny hole Real Camera Wikipedia, User Hanabi123, CC BY-SA 3.0

Results

64x64 48x48

22x22

Page 25: Cinematic Depth of Field€¦ · Depth of Field Optics Pinhole Camera Film Tiny hole Real Camera Wikipedia, User Hanabi123, CC BY-SA 3.0

DOF FX Performance

● RadeonTM RX 480

● ~5 ms for 1080 p

● ~3 ms for 1080 p with quarter res

● Looking for further optimizations

Page 26: Cinematic Depth of Field€¦ · Depth of Field Optics Pinhole Camera Film Tiny hole Real Camera Wikipedia, User Hanabi123, CC BY-SA 3.0

Results

64x64

8x8

16x16

40x40

32x32

64x64

24x24

64x64 = 4k / pixel

Page 27: Cinematic Depth of Field€¦ · Depth of Field Optics Pinhole Camera Film Tiny hole Real Camera Wikipedia, User Hanabi123, CC BY-SA 3.0

DOF FX Performance

● RadeonTM RX 480

● ~5 ms for 1080 p

● ~3 ms for 1080 p with quarter res

● Looking for further optimizations

Page 28: Cinematic Depth of Field€¦ · Depth of Field Optics Pinhole Camera Film Tiny hole Real Camera Wikipedia, User Hanabi123, CC BY-SA 3.0

Depth of Field

Page 29: Cinematic Depth of Field€¦ · Depth of Field Optics Pinhole Camera Film Tiny hole Real Camera Wikipedia, User Hanabi123, CC BY-SA 3.0

Summary

● Scatter based DOF

● Fixed, but high-ish overhead

● Limited by precision

● Source available soon

Page 30: Cinematic Depth of Field€¦ · Depth of Field Optics Pinhole Camera Film Tiny hole Real Camera Wikipedia, User Hanabi123, CC BY-SA 3.0

Questions?

Page 31: Cinematic Depth of Field€¦ · Depth of Field Optics Pinhole Camera Film Tiny hole Real Camera Wikipedia, User Hanabi123, CC BY-SA 3.0

The information presented in this document is for informational purposes only and may contain technical inaccuracies, omissions and typographical errors.

The information contained herein is subject to change and may be rendered inaccurate for many reasons, including but not limited to product and roadmap changes, component and motherboard version changes, new model and/or product releases, product differences between differing manufacturers, software changes, BIOS flashes, firmware upgrades, or the like. AMD assumes no obligation to update or otherwise correct or revise this information. However, AMD reserves the right to revise this information and to make changes from time to time to the content hereof without obligation of AMD to notify any person of such revisions or changes.

AMD MAKES NO REPRESENTATIONS OR WARRANTIES WITH RESPECT TO THE CONTENTS HEREOF AND ASSUMES NO RESPONSIBILITY FOR ANY INACCURACIES, ERRORS OR OMISSIONS THAT MAY APPEAR IN THIS INFORMATION.

AMD SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE. IN NO EVENT WILL AMD BE LIABLE TO ANY PERSON FOR ANY DIRECT, INDIRECT, SPECIAL OR OTHER CONSEQUENTIAL DAMAGES ARISING FROM THE USE OF ANY INFORMATION CONTAINED HEREIN, EVEN IF AMD IS EXPRESSLY ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

ATTRIBUTION

© 2017 Advanced Micro Devices, Inc. All rights reserved. AMD, the AMD Arrow logo and combinations thereof are trademarks of Advanced Micro Devices, Inc. in the United States and/or other jurisdictions. Other names are for informational purposes only and may be trademarks of their respective owners.