Sampling CS 6965 Fall 2011 Creative Program 3 CS 6965 Fall 2011 - - PowerPoint PPT Presentation

sampling
SMART_READER_LITE
LIVE PREVIEW

Sampling CS 6965 Fall 2011 Creative Program 3 CS 6965 Fall 2011 - - PowerPoint PPT Presentation

Sampling CS 6965 Fall 2011 Creative Program 3 CS 6965 Fall 2011 2 CS 6965 Fall 2011 3 CS 6965 Fall 2011 4 CS 6965 Fall 2011 5 CS 6965 Fall 2011 6 Sampling Theory World: continuous Image: discrete samples Display:


slide-1
SLIDE 1

Sampling

CS 6965 Fall 2011

slide-2
SLIDE 2

Fall 2011 CS 6965

Creative Program 3

2

slide-3
SLIDE 3

Fall 2011 CS 6965

3

slide-4
SLIDE 4

Fall 2011 CS 6965

4

slide-5
SLIDE 5

Fall 2011 CS 6965

5

slide-6
SLIDE 6

Fall 2011 CS 6965

6

slide-7
SLIDE 7

Fall 2011 CS 6965

Sampling Theory

  • World: continuous
  • Image: discrete samples
  • Display: continuous function
  • Ray tracing is a sampling process
  • Result: jaggies!
  • Let’s understand why

7

slide-8
SLIDE 8

Fall 2011 CS 6965

Aliasing

  • Aliasing appears in several forms:
  • Jagged edges
  • Moire patterns
  • Strobe effect

8

slide-9
SLIDE 9

Fall 2011 CS 6965

Picket fences

9

Fence 1: 6 inch boards Fence 2: 4 inch boards

slide-10
SLIDE 10

Fall 2011 CS 6965

Picket fences

10

Fence 1: 6 inch boards Fence 2: 4 inch boards

slide-11
SLIDE 11

Fall 2011 CS 6965

Aliasing

  • Aliasing is just high frequencies disguised

as low frequencies

  • We need to understand where the high

frequencies come from and what we can do about them

11

Low frequencies High frequencies

slide-12
SLIDE 12

Fall 2011 CS 6965

Mathematical tools

  • Fourier transform
  • Sampling
  • Shannon theorem
  • Convolution
  • Filtering

12

slide-13
SLIDE 13

Fall 2011 CS 6965

Fourier transform

Given a function h(t) : F h t

( )

⎡ ⎣ ⎤ ⎦ = H ω

( ) =

h t

( )e−iωtdt

−∞ ∞

F−1 H ω

( )

⎡ ⎣ ⎤ ⎦ = h(t) = 1 2π H ω

( )

−∞ ∞

eiωtdt i = −1 eix = cos x

( ) + isin x ( )

13

slide-14
SLIDE 14

Fall 2011 CS 6965

Discrete Fourier Transform

Continuous Fourier Transform(FT): F h t

( )

⎡ ⎣ ⎤ ⎦ = H ω

( ) =

h t

( )e−iωtdt

−∞ ∞

F−1 H ω

( )

⎡ ⎣ ⎤ ⎦ = f (t) = 1 2π H ω

( )

−∞ ∞

eiωtdt Discrete Fourier Transform (DFT): F

n =

fke−2πik /N

k=0 N −1

fk = 1 N fke2πinn/N

n=0 N −1

Fast Fourier Transform (FFT) is just an optimized version of DFT (using half-angle identities)

14

slide-15
SLIDE 15

Fall 2011 CS 6965

Frequencies

15

slide-16
SLIDE 16

Fall 2011 CS 6965

Frequency space

16

Time domain Frequency domain

slide-17
SLIDE 17

Fall 2011 CS 6965

Frequency space

17

Time domain Frequency domain

slide-18
SLIDE 18

Fall 2011 CS 6965

Duality

18

source: http://mrl.nyu.edu/~dzorin/intro-graphics/lectures/lecture2/sld013.htm

slide-19
SLIDE 19

Fall 2011 CS 6965

19

slide-20
SLIDE 20

Fall 2011 CS 6965

Dirac delta function

δ t

( ) = ∞

t = 0 t ≠ 0 ⎧ ⎨ ⎩ δ t − t0

( ) = ∞

t = t0 t ≠ t0 ⎧ ⎨ ⎩ δ t

( )dt = 1

−∞ ∞

20

slide-21
SLIDE 21

Fall 2011 CS 6965

Sampling

δ t

( ) f t ( )dt = f (0)

−∞ ∞

δ t

( ) f t − t0

( )dt = f (t0)

−∞ ∞

The delta function allows us to sample the function f

21

slide-22
SLIDE 22

Fall 2011 CS 6965

Sampling

More samples: more delta functions comb(t) = δ t − nT

( )

−∞ ∞

comb t

( ) f t ( )dt = ..., f −2T ( ), f −T ( ), f 0 ( )

−∞ ∞

, f T

( ), f 2T ( ),...

22

T t f(t)

slide-23
SLIDE 23

Fall 2011 CS 6965

23

slide-24
SLIDE 24

Fall 2011 CS 6965

Convolution

g,h : functions g *h = c(t) = g t

( )h t − τ ( )

−∞ ∞

dτ F(g(t))* F(h(t)) = F(g(t)h(t)) F(g(t)h(t)) = F(g(t)*h(t)) Multiplication in frequency space is convolution in time and vice-versa

24

slide-25
SLIDE 25

Fall 2011 CS 6965

Sampling

given g(t): F g(t)comb(t)

( ) = F g(t) ( )* F comb(t) ( )

= F g(t)

( )*comb(t)

25

w

Sampling Frequency

slide-26
SLIDE 26

Fall 2011 CS 6965

Sampling

given g(t): F g(t)comb(t)

( ) = F g(t) ( )* F comb(t) ( )

= F g(t)

( )*comb(t)

26

w

Sampling Frequency

slide-27
SLIDE 27

Fall 2011 CS 6965

Sampling

given g(t): F g(t)comb(t)

( ) = F g(t) ( )* F comb(t) ( )

= F g(t)

( )*comb(t)

27

w

Sampling Frequency

Aliasing total

slide-28
SLIDE 28

Fall 2011 CS 6965

Nyquist theorem (Shannon theorem, sampling theorem)

  • Any function g can be represented by

samples of frequency F iff the function g is band-limited to a frequency of F/2

28

slide-29
SLIDE 29

Fall 2011 CS 6965

Fourier series

f (t) = a0 + a0 cosπn + b0 sinπn

( )

n=1 ∞

29

slide-30
SLIDE 30

Fall 2011 CS 6965

Band-limiting

  • How do we prevent aliasing?
  • Band-limited functions

30

w

Sampling Frequency

slide-31
SLIDE 31

Fall 2011 CS 6965

Fix 1: Band-limiting

31

source: http://mrl.nyu.edu/~dzorin/intro-graphics/lectures/lecture2/sld013.htm

slide-32
SLIDE 32

Fall 2011 CS 6965

Band limiting in graphics

  • No silver bullet:
  • Lines, polygon edges: analytical formulations (doesn’t handle

lines crossing)

  • Textures: mip-maps, other filters
  • Objects: level of detail
  • Fonts?

32

slide-33
SLIDE 33

Fall 2011 CS 6965

Fix 2: Increase sampling frequency

33

slide-34
SLIDE 34

Fall 2011 CS 6965

Fix 3: Non-delta function samples

  • Beam tracing
  • Cone tracing
  • Not always possible

34

slide-35
SLIDE 35

Fall 2011 CS 6965

Fix 4: Non-uniform samples

  • Idea 1: Use a few samples to estimate the frequencies to decide

the sampling rate

  • May miss some high frequencies
  • Works pretty well for edges
  • Idea 2: Use random instead of uniform samples
  • F(white noise)=white noise
  • Can potentially recover all frequencies
  • May not always recover some frequencies
  • Lost frequencies “masked” by visual system

35

slide-36
SLIDE 36

Fall 2011 CS 6965

Reconstruction

  • Nyquist/Shannon: Any function g can be represented by samples
  • f frequency F iff the function g is band-limited to a frequency of

F/2

  • How?

36

slide-37
SLIDE 37

Fall 2011 CS 6965

Reconstruction

Connect the dots? f(t)= asT t

( )

s=1 n

T(t) = −t −1 ≤ t < 0 t 0 ≤ t ≤ 1

  • therwise

⎧ ⎨ ⎪ ⎩ ⎪

37

T t f(t)

  • 1 1
slide-38
SLIDE 38

Fall 2011 CS 6965

Reconstruction

Connect the dots? F(f(t))= asF T t

( )

( )

s=1 n

38

T t f(t)

slide-39
SLIDE 39

Fall 2011 CS 6965

Triangle reconstruction

39

slide-40
SLIDE 40

Fall 2011 CS 6965

Better reconstruction

  • Ideal reconstruction filter: sinc function (infinite in time)
  • Bad news: ALL filters that have finite frequency response have

infinite time response and vice-versa

  • For a detailed discussion of some of the tradeoffs:
  • Marschner, S.R. and Lobb, R.J., An Evaluation of

Reconstruction Filters for Volume Rendering, in Proceedings

  • f

Visualization'94, Washington, DC (1994), pp. 100-107

40

slide-41
SLIDE 41

Fall 2011 CS 6965

Filter responses

41

Ken Turkowski, Apple Computer, “Filters for Common Resampling Tasks”

slide-42
SLIDE 42

Fall 2011 CS 6965

Windowed Sinc

42

Lanczos-windowed Sinc function

slide-43
SLIDE 43

Fall 2011 CS 6965

Filter compromises

  • Don P

. Mitchell, Arun N. Netravali “Reconstruction filters in computer- graphics” Computer Graphics, Volume 22, Number 4, 1988.

  • User study with over 500

subjects

  • Identified a new filter with

good properties (now called the Mitchell filter)

43

slide-44
SLIDE 44

Fall 2011 CS 6965

Sampling 2

44

slide-45
SLIDE 45

Fall 2011 CS 6965

Supersampling pipeline

  • World (continuous)
  • Fine Samples (discrete)
  • Reconstructed world (continuous)
  • Image Samples (discrete)
  • Reconstructed image (continuous)

45

slide-46
SLIDE 46

Fall 2011 CS 6965

Resampling

  • To move from one sample rate to another, we use the same

filters

  • Interpolation: increasing resolution
  • Decimation: decreasing resolution
  • Pre-aliasing: undersampling
  • Post-aliasing: errors in reconstruction

46

slide-47
SLIDE 47

Fall 2011 CS 6965

Filtering details (decimation)

filter(x) f (x)

samples

filter(x)

samples

47

Fine samples Coarse sample Fine samples

.01 .3 .8 .8 .3 .01

slide-48
SLIDE 48

Fall 2011 CS 6965

Filtering details (non-uniform sampling)

filter(x) f (x)

samples

filter(x)

samples

48

Fine samples Coarse sample Fine samples

.04 .3 .8 .9 .2 .01

slide-49
SLIDE 49

Fall 2011 CS 6965

2D Fourier transform

49

slide-50
SLIDE 50

Fall 2011 CS 6965

2D filtering

2D Filtering: filter(x,y) f (x,y)

samples

filter(x,y)

samples

2D Separable filter: filter(x,y) = filterx(x) filtery(y) filterx(x) filtery(y) f (x,y)

samples

filterx(x) filtery(y)

samples

50

Separable General

slide-51
SLIDE 51

Fall 2011 CS 6965

Sampling patterns

51

Random Uniform

slide-52
SLIDE 52

Fall 2011 CS 6965

Sampling patterns

52

Stratified n-rooks

slide-53
SLIDE 53

Fall 2011 CS 6965

Aliasing

53

256 spp 1 spp

Source: Physically Based Rendering, Pharr & Humphreys

slide-54
SLIDE 54

Fall 2011 CS 6965

Aliasing

54

1 spp, stratified 4 spp, stratified

slide-55
SLIDE 55

Fall 2011 CS 6965

55

f (x,y) = sin(500π(x2+y2))+1 2

slide-56
SLIDE 56

Fall 2011 CS 6965

Fourier transform

56

slide-57
SLIDE 57

Fall 2011 CS 6965

Box filter

57

slide-58
SLIDE 58

Fall 2011 CS 6965

9 uniform samples, box filter

58

slide-59
SLIDE 59

Fall 2011 CS 6965

9 jittered samples, box filter

59

slide-60
SLIDE 60

Fall 2011 CS 6965

9 spp, triangle filter

60

slide-61
SLIDE 61

Fall 2011 CS 6965

Perfect filter

61

slide-62
SLIDE 62

Fall 2011 CS 6965

Overlapping pixels

  • Any filter with support > 1 overlaps

multiple pixels

  • You can reuse samples, but it muddies

the architecture

  • If you don’t, it limits use of high order

filters

  • Alternatively: generate samples with a

distribution

62

ix-1 ix ix+1 ix-1 ix ix+1

slide-63
SLIDE 63

Fall 2011 CS 6965

Implementation notes:

  • Draw graphs of your filters before using them
  • Try a box filter first
  • Hardest part: get subpixel coordinates right

63

slide-64
SLIDE 64

Fall 2011 CS 6965

Pixel coordinate clarification

64

1

  • 1
  • 1

1

slide-65
SLIDE 65

Fall 2011 CS 6965

65

Pixel coordinate clarification

1

  • 1
  • 1

1

  • .75
  • .25

.25 .75

slide-66
SLIDE 66

Fall 2011 CS 6965

66

Box filter support

1

  • 1
  • 1

1

  • .75
  • .25

.25 .75

slide-67
SLIDE 67

Fall 2011 CS 6965

67

Triangle filter support

1

  • 1
  • 1

1

  • .75
  • .25

.25 .75

slide-68
SLIDE 68

Fall 2011 CS 6965

68

1 spp

slide-69
SLIDE 69

Fall 2011 CS 6965

69

9 spp jittered triangle

slide-70
SLIDE 70

Fall 2011 CS 6965

Adaptive supersampling

  • Images look better with more samples
  • More samples take longer
  • Can we put the samples where we need them?

70

slide-71
SLIDE 71

Fall 2011 CS 6965

Statistical approach

  • Compute variance of samples
  • Add more samples if variance is too large
  • Confidence interval: 90% sure that average is within some range

(+/- 1 lsb)

  • Theoretically, you must throw away old samples
  • You can still miss things

71

slide-72
SLIDE 72

Fall 2011 CS 6965

Improved statistical approach

  • Discontinuity of sampling rate introduces artifacts
  • Two pass algorithm:
  • Normal statistical supersampling
  • Go back over pixels near pixels with high sample rates
  • Could repeat

72

slide-73
SLIDE 73

Fall 2011 CS 6965

Geometric approach

  • 4 samples: corners + center
  • Recursively subdivide

pixels: (add three more)

  • Final color: area weighted

average

  • Duplicates on edges?

1 3 4 5 2

slide-74
SLIDE 74

Fall 2011 CS 6965

Geometric approach

  • 4 samples: corners + center
  • Recursively subdivide

pixels: (add three more)

  • Final color: area weighted

average

  • Duplicates on edges?

74

1 3 4 5 2

slide-75
SLIDE 75

Fall 2011 CS 6965

Geometric approach

  • 4 samples: corners + center
  • Recursively subdivide

pixels: (add three more)

  • Final color: area weighted

average

  • Duplicates on edges?

75

1 3 4 5 2 6 7 8

slide-76
SLIDE 76

Fall 2011 CS 6965

Comparison

76

slide-77
SLIDE 77

Fall 2011 CS 6965

Anti-aliasing review

  • Nyquist limit requires sampling rate of 2F
  • Graphics uses infinitely large frequencies
  • Can get reasonably close with good filters
  • Simple filters do a poor job, even at low frequencies (just above

the Nyquist limit)

77

slide-78
SLIDE 78

Fall 2011 CS 6965

Packet Traversal

78

slide-79
SLIDE 79

BVH traversal

79

slide-80
SLIDE 80

BVH packet traversal

80

slide-81
SLIDE 81

BVH packet traversal

81

slide-82
SLIDE 82

BVH packet traversal

82

slide-83
SLIDE 83

BVH packet traversal

83

slide-84
SLIDE 84

BVH packet traversal

84

slide-85
SLIDE 85

BVH packet traversal

85

slide-86
SLIDE 86

BVH packet traversal

86

slide-87
SLIDE 87

BVH packet traversal

87

slide-88
SLIDE 88

BVH packet traversal

88

slide-89
SLIDE 89

BVH packet traversal

89

slide-90
SLIDE 90

BVH packet traversal

90

slide-91
SLIDE 91

BVH packet traversal

91

slide-92
SLIDE 92

BVH packet traversal

92

slide-93
SLIDE 93

BVH packet traversal

93

slide-94
SLIDE 94

BVH packet traversal

94

slide-95
SLIDE 95

Fall 2011 CS 6965

Instancing

95

slide-96
SLIDE 96

CS6620 Spring 07

Instancing

  • Increase

geometric complexity through creating multiple copies

  • f similar
  • bjects

http://www.cs.utah.edu/~angell/cs6620/assignment6/

slide-97
SLIDE 97

CS6620 Spring 07

Instances

  • Instances may

affect position and material properties

http://www.cs.utah.edu/~bigler/classes/cs6620/final.html

slide-98
SLIDE 98

CS6620 Spring 07

Pre-transformation

Simplest way: transform

  • bjects as they are read in

+No additional overhead in ray tracing objects

  • Requires a lot of memory

for complex objects

slide-99
SLIDE 99

CS6620 Spring 07

Transform

More efficient way: transform ray at intersection time +Transform must be computed for each ray

  • Scenes with billions of

polygons are possible with modest memory requirements

slide-100
SLIDE 100

CS6620 Spring 07

Translational instances

  • Simplest instance: translation vector
  • Create a TInstance class as a

subclass of Primitive

  • Contains a translation vector and a

pointer to an underlying object

  • Intersect method subtracts

translation vector from origin and calls intersect on underlying object

  • Similar for call to normal()

T O’+tV O+tV

slide-101
SLIDE 101

CS6620 Spring 07

General instances

  • General linear transformations are more

powerful

O+tV P   = O   + tV   ʹ″ P   = M 00 M 01 M 02 Tx M10 M11 M12 Ty M 20 M 21 M 22 Tz ⎡ ⎣ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ P

x

P

y

P

z

1 ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥

slide-102
SLIDE 102

CS6620 Spring 07

General transformations

P   = O   + tV   ʹ″ P   = M 00 M 01 M 02 Tx M10 M11 M12 Ty M 20 M 21 M 22 Tz ⎡ ⎣ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ P

x

P

y

P

z

1 ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ ʹ″ P   = M P   + T   = MO   + MV   + T   = ʹ″ O   + t ʹ″ V   where : ʹ″ O   = MO   + T   ʹ″ V   = MV   O’+tV’ O+tV

slide-103
SLIDE 103

CS6620 Spring 07

Instances

  • Create an Instance class as a subclass of

Primitive

  • Contains a transform object and a pointer to an

underlying object

  • Intersect method transforms origin and direction

and then calls intersect on underlying object with the transformed ray

  • Two gotchas:

–Unit length ray directions –Normals

slide-104
SLIDE 104

CS6620 Spring 07

Unit length ray directions

  • Transformation may change length of a unit

vector

  • If your implementation relies on normalized

ray directions, then ray must be “re- normalized”

  • This involves a square root, in general

– Can be optimized for uniform scale factors

O’+tV’ O+tV l = v.normalize() intersect child t parent = tchild *l

slide-105
SLIDE 105

CS6620 Spring 07

Normal transformation

Consider a plane: N  ⋅ P   = 0 and a transform: ʹ″ P   = M P   Find a plane with normal ʹ″ N   such that ʹ″ N    ⋅ ʹ″ P   = 0 N  ⋅ P   = 0 NPT = 0 N M −1M

( )PT = 0

NM −1

( ) MPT ( ) = 0

NM −1

( ) ʹ″

P = 0 ʹ″ N    = NM −1

( ) = M −1 ( )

T N = M T

( )

−1 N

If M is a rotation matrix, M-1 = M T , so M T

( )

−1 = M

slide-106
SLIDE 106

CS6620 Spring 07

Transformed normals

  • Normal must be transformed
  • Easy with normals computed at

intersection time

  • Deferred normals (scratchpad)

require a little more thought

ʹ″ N    = M −1

( )

T N

 ʹ″ N    = ʹ″ N    ʹ″ N   

slide-107
SLIDE 107

CS6620 Spring 07

Transformed deferred normals

  • Method 1: Use scratchpad to defer transformation but

compute untransformed normal at intersection time intersect: HitInfo subhit transform ray length = normalize ray direction intersect child with subhit if(subhit.wasHit() && hit.hit(t*length, this, subhit.matl) Put normal in scratchpad

slide-108
SLIDE 108

CS6620 Spring 07

Transformed deferred normals

  • Method 2: Extend scratchpad

to allow a “stack” of objects

  • Normal is transformed only if
  • bject is actually closest
  • Good for nested

transformations

Hit object Transform 1 Transform 2

slide-109
SLIDE 109

CS6620 Spring 07

Nested transformations

  • Multiple transformations can be combined

by nesting instance objects

  • Must be careful with deferred computation

(i.e. scratchpad) mechanisms

–All of the above solutions work fine, others may not

slide-110
SLIDE 110

CS6620 Spring 07

Nested acceleration structures

  • Using nested structures

you can create enormously complex scenes (millions of bunnies)

  • Acceleration structures

can be mixed/matched (BVH on top, Grid on bottom, etc.)

Top BVH Instances Instanced

  • bject BVH

Primitives

slide-111
SLIDE 111

CS6620 Spring 07

Bounding box computation

  • To use acceleration structures you will need

the bounding box of the transformed object

  • Simplest method:

– Transform each vertex of the child bounding box (8

  • f them)

– Compute the min/max of each of these vertices – Doesn’t always result in tight bound

  • Complex method:

– Transform underlying model – Easy for polygonal objects – Not always possible for general objects

slide-112
SLIDE 112

CS6620 Spring 07

Instance optimizations

  • Precompute matrix inverse

–Perhaps store only inverse

  • Specialized methods and/or storage for special

cases:

–Pure translation –Pure rotation –Rotation + translation –Uniform scale –Uniform scale plus translation, rotation, or both –General case

slide-113
SLIDE 113

CS6620 Spring 07

Changing materials

intersect: HitInfo subhit transform ray length = normalize ray direction intersect child with subhit if(subhit.wasHit() && hit.hit(t*length, this, overide_matl) Put normal in scratchpad Similar for other mechanisms

slide-114
SLIDE 114

CS6620 Spring 07

Other instancing tricks

  • Implicitly

defined fractals

  • Uses a graph

structure instead of an instance tree

graphics.cs.uiuc.edu/~jch/papers/paradigm.pdf

slide-115
SLIDE 115

CS6620 Spring 07

Hart instancing paper

Trees and

  • ther

complex

  • bjects

can be specified with a few bytes