CS291A Spring2020 Lecture 06lingqi/teaching/resources/CS...Basic idea of PRT [Sloan 02] Approximate...

44
CS291A: Real-Time High Quality Rendering Spring 2020, Lingqi Yan, UC Santa Barbara Precomputed Radiance Transfer (cont.) Lecture 6:

Transcript of CS291A Spring2020 Lecture 06lingqi/teaching/resources/CS...Basic idea of PRT [Sloan 02] Approximate...

Page 1: CS291A Spring2020 Lecture 06lingqi/teaching/resources/CS...Basic idea of PRT [Sloan 02] Approximate lighting using basis functions Precomputation stage compute light transport, and

CS291A: Real-Time High Quality RenderingSpring 2020, Lingqi Yan, UC Santa Barbara

Precomputed Radiance Transfer (cont.)Lecture 6:

Page 2: CS291A Spring2020 Lecture 06lingqi/teaching/resources/CS...Basic idea of PRT [Sloan 02] Approximate lighting using basis functions Precomputation stage compute light transport, and

A Brief Recap� Precomputed Radiance Transfer� Basis functions

� Spherical Harmonics� Run-time Rendering

Page 3: CS291A Spring2020 Lecture 06lingqi/teaching/resources/CS...Basic idea of PRT [Sloan 02] Approximate lighting using basis functions Precomputation stage compute light transport, and

Rendering under environment lighting

� !/#: incoming/view directions� Brute-force computation

� Resolution: 6*64*64� Needs 6*64*64 times for each point!

$ # = &'$ ! ( ! ) !, # max(0, 0 ⋅ !) d!

BRDFlighting visibility

Page 4: CS291A Spring2020 Lecture 06lingqi/teaching/resources/CS...Basic idea of PRT [Sloan 02] Approximate lighting using basis functions Precomputation stage compute light transport, and

Basic idea of PRT [Sloan 02]

� Approximate lighting using basis functions� ! " ≈ ∑ %&'&(")

� Precomputation stage� compute light transport, and project to basis function space

� Runtime stage� dot product (diffuse) or matrix-vector multiplication (glossy)

! * = ,-! " . " / ", * max(0, 5 ⋅ ") d"

light transportlighting

Page 5: CS291A Spring2020 Lecture 06lingqi/teaching/resources/CS...Basic idea of PRT [Sloan 02] Approximate lighting using basis functions Precomputation stage compute light transport, and

Basis functions !(#)� Spherical Harmonics (SH)

https://en.wikipedia.org/wiki/Spherical_harmonics

Page 6: CS291A Spring2020 Lecture 06lingqi/teaching/resources/CS...Basic idea of PRT [Sloan 02] Approximate lighting using basis functions Precomputation stage compute light transport, and

Basis functions !(#)� Spherical Harmonics (SH)� Light Approximation Examples

Low frequency

Page 7: CS291A Spring2020 Lecture 06lingqi/teaching/resources/CS...Basic idea of PRT [Sloan 02] Approximate lighting using basis functions Precomputation stage compute light transport, and

Basis functions !(#)

� Projection to SH space

� Reconstruction

/ # ≈123!3(#)

23 = 56/ # ⋅ !3 # d#

lighting lighting coefficients

Original space SH space

/ # ≈123!3(#)

Page 8: CS291A Spring2020 Lecture 06lingqi/teaching/resources/CS...Basic idea of PRT [Sloan 02] Approximate lighting using basis functions Precomputation stage compute light transport, and

Run-time Rendering

� Rendering at each point is reduced to a dot product� First, project the lighting to the basis to obtain !"� Or, rotate the lighting instead of re-projection� Then, compute the dot product

� Real-time: easily implemented in shader

# $ ≈ &'!"("

Page 9: CS291A Spring2020 Lecture 06lingqi/teaching/resources/CS...Basic idea of PRT [Sloan 02] Approximate lighting using basis functions Precomputation stage compute light transport, and

Wavelet [Ng 03]� 2D Haar wavelet

� Projection:� Wavelet Transformation� Retain a small number of

non-zero coefficients

� A non-linear approximation

� All-frequency representation

Page 10: CS291A Spring2020 Lecture 06lingqi/teaching/resources/CS...Basic idea of PRT [Sloan 02] Approximate lighting using basis functions Precomputation stage compute light transport, and

low frequency vs all frequencyTeapot in Grace Cathedral

All frequency (Wavelet)Low frequency (SH)

Page 11: CS291A Spring2020 Lecture 06lingqi/teaching/resources/CS...Basic idea of PRT [Sloan 02] Approximate lighting using basis functions Precomputation stage compute light transport, and

Relighting as Matrix-Vector Multiply

1

2

3

N

PPP

P

é ùê úê úê úê úê úê úë û

!

11 12 11

21 22 22

31 32 3

1 2

M

M

M

NN N NM

T T TL

T T TL

T T T

LT T T

é ùé ùê úê úê úê úê ú=ê úê úê úê úë ûê úë û

!!!

"" " # "

!

Page 12: CS291A Spring2020 Lecture 06lingqi/teaching/resources/CS...Basic idea of PRT [Sloan 02] Approximate lighting using basis functions Precomputation stage compute light transport, and

Relighting as Matrix-Vector Multiply

1

2

3

N

PPP

P

é ùê úê úê úê úê úê úë û

!

11 12 11

21 22 22

31 32 3

1 2

M

M

M

NN N NM

T T TL

T T TL

T T T

LT T T

é ùé ùê úê úê úê úê ú=ê úê úê úê úë ûê úë û

!!!

"" " # "

!

� Input Lighting(Cubemap Vector)

Output Image(Pixel Vector)

TransportMatrix

Page 13: CS291A Spring2020 Lecture 06lingqi/teaching/resources/CS...Basic idea of PRT [Sloan 02] Approximate lighting using basis functions Precomputation stage compute light transport, and

Non-linear Wavelet Light Approximation

Wavelet Transform

Page 14: CS291A Spring2020 Lecture 06lingqi/teaching/resources/CS...Basic idea of PRT [Sloan 02] Approximate lighting using basis functions Precomputation stage compute light transport, and

1

2

3

4

5

6

N

LLLLLL

L

é ùê úê úê úê úê úê úê úê úê úê úê úë û

!

2

6

0

000

0

L

L

é ùê úê úê úê úê úê úê úê úê úê úê úë û

!

Non-linear Wavelet Light Approximation

Non-linearApproximation

Retain 0.1% – 1% terms

Page 15: CS291A Spring2020 Lecture 06lingqi/teaching/resources/CS...Basic idea of PRT [Sloan 02] Approximate lighting using basis functions Precomputation stage compute light transport, and

11 12 13 14 1

21 22 23 24 2

31 32 24 34 3

41 42 43 44 4

51 52 53 54 5

61 62 63 64 6

7

1 2 3 4

M

M

M

M

M

M

M

N N N N NM

T T T T TT T T T TT T T T TT T T T TT T T T TT T T T T

TT T T T T

é ùê úê úê úê úê úê úê úê úê úê úê úë û

!!!!!!

" " " " #!

Matrix Row Wavelet Encoding

Page 16: CS291A Spring2020 Lecture 06lingqi/teaching/resources/CS...Basic idea of PRT [Sloan 02] Approximate lighting using basis functions Precomputation stage compute light transport, and

11 12 13 14 1

21 22 23 24 2

31 32 24 34 3

41 42 43 44 4

51 52 53 54 5

61 62 63 64 6

7

1 2 3 4

M

M

M

M

M

M

M

N N N N NM

T T T T TT T T T TT T T T TT T T T TT T T T TT T T T T

TT T T T T

é ùê úê úê úê úê úê úê úê úê úê úê úë û

!!!!!!

" " " " #!

Extract Row

Matrix Row Wavelet Encoding

Page 17: CS291A Spring2020 Lecture 06lingqi/teaching/resources/CS...Basic idea of PRT [Sloan 02] Approximate lighting using basis functions Precomputation stage compute light transport, and

11 12 13 14 1

21 22 23 24 2

31 32 24 34 3

41 42 43 44 4

51 52 53 54 5

61 62 63 64 6

7

1 2 3 4

M

M

M

M

M

M

M

N N N N NM

T T T T TT T T T TT T T T TT T T T TT T T T TT T T T T

TT T T T T

é ùê úê úê úê úê úê úê úê úê úê úê úë û

!!!!!!

" " " " #!

Wavelet Transform

Matrix Row Wavelet Encoding

Page 18: CS291A Spring2020 Lecture 06lingqi/teaching/resources/CS...Basic idea of PRT [Sloan 02] Approximate lighting using basis functions Precomputation stage compute light transport, and

Wavelet Transform

11 12 13 14 1

21 22 23 24 2

31 32 24 34 3

41 42 43 44 4

51 52 53 54 5

61 62 63 64 6

7

1 2 3 4

M

M

M

M

M

M

M

N N N N NM

T T T T TT T T T TT T T T TT T T T TT T T T TT T T T T

TT T T T T

é ùê úê úê úê úê úê úê úê úê úê úê úë û

!!!!!!

" " " " #!

Matrix Row Wavelet Encoding

Page 19: CS291A Spring2020 Lecture 06lingqi/teaching/resources/CS...Basic idea of PRT [Sloan 02] Approximate lighting using basis functions Precomputation stage compute light transport, and

11 12 13 14 1

21 22 23 24 2

31 32 24 34 3

41 42 43 44 4

51 52 53 54 5

61 62 63 64 6

7

1 2 3 4

M

M

M

M

M

M

M

N N N N NM

T T T T TT T T T TT T T T TT T T T TT T T T TT T T T T

TT T T T T

é ùê úê úê úê úê úê úê úê úê úê úê úë û

!!!!!!

" " " " #!

Wavelet Transform

Matrix Row Wavelet Encoding

Page 20: CS291A Spring2020 Lecture 06lingqi/teaching/resources/CS...Basic idea of PRT [Sloan 02] Approximate lighting using basis functions Precomputation stage compute light transport, and

11 12 13 14 1

21 22 23 24 2

31 32 24 34 3

41 42 43 44 4

51 52 53 54 5

61 62 63 64 6

7

1 2 3 4

M

M

M

M

M

M

M

N N N N NM

T T T T TT T T T TT T T T TT T T T TT T T T TT T T T T

TT T T T T

é ùê úê úê úê úê úê úê úê úê úê úê úë û

!!!!!!

" " " " #!

Wavelet Transform

Matrix Row Wavelet Encoding

Page 21: CS291A Spring2020 Lecture 06lingqi/teaching/resources/CS...Basic idea of PRT [Sloan 02] Approximate lighting using basis functions Precomputation stage compute light transport, and

11 12 13 14 1

21 22 23 24 2

31 32 24 34 3

41 42 43 44 4

51 52 53 54 5

61 62 63 64 6

7

1 2 3 4

M

M

M

M

M

M

M

N N N N NM

T T T T TT T T T TT T T T TT T T T TT T T T TT T T T T

TT T T T T

é ùê úê úê úê úê úê úê úê úê úê úê úë û

!!!!!!

" " " " #!

Store Back in Matrix

0’ ’0 0

Matrix Row Wavelet Encoding

Page 22: CS291A Spring2020 Lecture 06lingqi/teaching/resources/CS...Basic idea of PRT [Sloan 02] Approximate lighting using basis functions Precomputation stage compute light transport, and

11 12 13 14 1

21 22 23 24 2

31 32 24 34 3

41 42 43 44 4

51 52 53 54 5

61 62 63 64 6

7

1 2 3 4

M

M

M

M

M

M

M

N N N N NM

T T T T TT T T T TT T T T TT T T T TT T T T TT T T T T

TT T T T T

é ùê úê úê úê úê úê úê úê úê úê úê úë û

!!!!!!

" " " " #!

0’ ’0 0

Only 3% – 30% are non-zero

Matrix Row Wavelet Encoding

Page 23: CS291A Spring2020 Lecture 06lingqi/teaching/resources/CS...Basic idea of PRT [Sloan 02] Approximate lighting using basis functions Precomputation stage compute light transport, and

Why Non-linear Approximation?� Linear

� Use a fixed set of approximating functions � Precomputed radiance transfer uses 25 - 100 of

the lowest frequency spherical harmonics� Non-linear

� Use a dynamic set of approximating functions (depends on each frame’s lighting)

� In our case: choose 10’s - 100’s from a basis of 24,576 wavelets

Page 24: CS291A Spring2020 Lecture 06lingqi/teaching/resources/CS...Basic idea of PRT [Sloan 02] Approximate lighting using basis functions Precomputation stage compute light transport, and

Overall Rendering Algorithm� Pre-compute (per scene)

� Compute matrix in pixel basis� Wavelet transform rows� Quantize, store

� Interactive Relighting (each frame)� Wavelet transform lighting� Prioritize and retain N wavelet coefficients� Perform sparse-matrix vector multiplication

Page 25: CS291A Spring2020 Lecture 06lingqi/teaching/resources/CS...Basic idea of PRT [Sloan 02] Approximate lighting using basis functions Precomputation stage compute light transport, and

Output Image Comparison

25 200 2,000 20,000

SHwavelet

Page 26: CS291A Spring2020 Lecture 06lingqi/teaching/resources/CS...Basic idea of PRT [Sloan 02] Approximate lighting using basis functions Precomputation stage compute light transport, and

Limitation� Wavelet: not rotationally invariant

� Re-projection at each frame� Results in flickering

� Only support dot-product operator� Limited to diffuse or fix-view glossy

Page 27: CS291A Spring2020 Lecture 06lingqi/teaching/resources/CS...Basic idea of PRT [Sloan 02] Approximate lighting using basis functions Precomputation stage compute light transport, and

Zonal Harmonics [Sloan 05]� circularly symmetric functions� Subset of SH basis (m=0)

� Low-frequency� Rotationally invariant � Much more faster in rotation

than SH

Page 28: CS291A Spring2020 Lecture 06lingqi/teaching/resources/CS...Basic idea of PRT [Sloan 02] Approximate lighting using basis functions Precomputation stage compute light transport, and

Recall -- Spherical Harmonics (SH)

https://en.wikipedia.org/wiki/Spherical_harmonics

Page 29: CS291A Spring2020 Lecture 06lingqi/teaching/resources/CS...Basic idea of PRT [Sloan 02] Approximate lighting using basis functions Precomputation stage compute light transport, and

Spherical Gaussian (SG) [Tsai 06]

� SGs (or Spherical Radial Basis Functions, SRBFs)! "; $, & = () "⋅$+,

bandwidthcenter

$1

0

$$

varying center

Page 30: CS291A Spring2020 Lecture 06lingqi/teaching/resources/CS...Basic idea of PRT [Sloan 02] Approximate lighting using basis functions Precomputation stage compute light transport, and

Spherical Gaussian (SG) [Tsai 06]

� SGs (or Spherical Radial Basis Functions, SRBFs)! "; $, & = () "⋅$+,

bandwidthcenter

$ $1

0

$

increasing bandwidth

Page 31: CS291A Spring2020 Lecture 06lingqi/teaching/resources/CS...Basic idea of PRT [Sloan 02] Approximate lighting using basis functions Precomputation stage compute light transport, and

Mathematical Properties of SGs� Closed-form integral

� The integral of an SG is closed-form

!"# $; &, ( d$ = 2,

( 1 − /012

Page 32: CS291A Spring2020 Lecture 06lingqi/teaching/resources/CS...Basic idea of PRT [Sloan 02] Approximate lighting using basis functions Precomputation stage compute light transport, and

Mathematical Properties of SGs� Closed under multiplication

� The product of two SGs is also an SGG "; $%, '% ⋅ G "; $), ') = +G "; '%$% + '%$)'%$% + '%$)

, '%$% + '%$)

Product

⋅ =

-./0 "; $%, '% -./0 "; $), ')

Page 33: CS291A Spring2020 Lecture 06lingqi/teaching/resources/CS...Basic idea of PRT [Sloan 02] Approximate lighting using basis functions Precomputation stage compute light transport, and

Mathematical Properties of SGs� Closed under convolution approximately

� The convolution of two SGs is still an SG!"# $; &', )' ⋅ # $; &+, )+ d$ ≈ ./# &'; &+,

)')+)' + )+

Convolution

∗ =

#345 $; &', )' #345 $; &+, )+

Page 34: CS291A Spring2020 Lecture 06lingqi/teaching/resources/CS...Basic idea of PRT [Sloan 02] Approximate lighting using basis functions Precomputation stage compute light transport, and

Summary of SGs� Rotationally invariant

� Lighting, BRDFs demand rotation� Capable of representing all-frequency

signals� All-frequency lighting/BRDFs

� Closed-form integral� rendering is essentially integration [Kajiya 1986]

� Closed under multiplication� multiplication of lighting, visibility and BRDFs

� Closed under convolution� support for various applications

� SGs are non-orthogonal!

Page 35: CS291A Spring2020 Lecture 06lingqi/teaching/resources/CS...Basic idea of PRT [Sloan 02] Approximate lighting using basis functions Precomputation stage compute light transport, and

Lighting Approximation

� non-linear process: iterative L-BFGS-B solver (slow)

! " ≈$%&'("; *+, -+)

Page 36: CS291A Spring2020 Lecture 06lingqi/teaching/resources/CS...Basic idea of PRT [Sloan 02] Approximate lighting using basis functions Precomputation stage compute light transport, and

BRDF Factorization [Wang 03, Liu 03]

� Precompute the factorization

! ", $ ≈&'(' " ⋅ *' $

Page 37: CS291A Spring2020 Lecture 06lingqi/teaching/resources/CS...Basic idea of PRT [Sloan 02] Approximate lighting using basis functions Precomputation stage compute light transport, and

Overall Rendering Algorithm� Derivation: Factorizing BRDF

! " = $%! & ' & ( &, " max(0, / ⋅ &) d&

! " = $%! & ' & 3

454 & ⋅ 64 " max(0, / ⋅ &) d&

! " =3464 " $

%! & ' & 54 & max(0, / ⋅ &) d&

Both represented using SGs

7(&)

Page 38: CS291A Spring2020 Lecture 06lingqi/teaching/resources/CS...Basic idea of PRT [Sloan 02] Approximate lighting using basis functions Precomputation stage compute light transport, and

Overall Rendering Algorithm� Derivation: projection to SGs

� Timing: O(N*N*M), non-orthogonal

! " =$%&% " '

(! ) *()) d)

! ) ≈$/010()) * ) ≈$2313())non-linear approx. pre. scattered approx.

! " =$%&% " $

0,3/023 '

(10 ) 13()) d)

analytic solution

Page 39: CS291A Spring2020 Lecture 06lingqi/teaching/resources/CS...Basic idea of PRT [Sloan 02] Approximate lighting using basis functions Precomputation stage compute light transport, and

Results

Page 40: CS291A Spring2020 Lecture 06lingqi/teaching/resources/CS...Basic idea of PRT [Sloan 02] Approximate lighting using basis functions Precomputation stage compute light transport, and

Piecewise Constant [Xu 08]� Spherical Piecewise Constant Basis Function

(SPCBF)� Split sphere into

regions� Each region is

represented by a constant

� Property� All-frequency� Rotation-Invariant� Multi-product� Fast projection

Page 41: CS291A Spring2020 Lecture 06lingqi/teaching/resources/CS...Basic idea of PRT [Sloan 02] Approximate lighting using basis functions Precomputation stage compute light transport, and

Piecewise Constant [Xu 08]� Light Projection

� Bottom-up optimization

Page 42: CS291A Spring2020 Lecture 06lingqi/teaching/resources/CS...Basic idea of PRT [Sloan 02] Approximate lighting using basis functions Precomputation stage compute light transport, and

Piecewise Constant [Xu 08]� Projection of visibility and BRDFs

� BRDF○ using summed area table

� Visibility○ Using visibility distance table

Page 43: CS291A Spring2020 Lecture 06lingqi/teaching/resources/CS...Basic idea of PRT [Sloan 02] Approximate lighting using basis functions Precomputation stage compute light transport, and

Results

Page 44: CS291A Spring2020 Lecture 06lingqi/teaching/resources/CS...Basic idea of PRT [Sloan 02] Approximate lighting using basis functions Precomputation stage compute light transport, and

Thank you!(Today’s slides courtesy of Prof. Kun Xu from

Tsinghua University)