Inverse Volume Rendering
Absorption + Emission, Automatic Differentiation
Sebastian Weiß
Lehrstuhl f¨ ur Computergrafik Technische Universit¨ at M¨ unchen
November 2020
1 / 13
Overview
1. Models and Assumptions
1.1. Absorption 1.2. Emission 1.3. Transfer Function
2. Automatic Differentiation
2.1. Forward Mode 2.2. Backward Mode
(1) (2)
(1)https://www.youtube.com/watch?v=HwJyg5o3HGg
(2)https://commons.wikimedia.org/wiki/File:Convolutional_Neural_Network_with_Color_Image_Filter.gif
2 / 13
Overview
1. Models and Assumptions
1.1. Absorption 1.2. Emission 1.3. Transfer Function
2. Automatic Differentiation
2.1. Forward Mode 2.2. Backward Mode
(1) (2)
(1)https://www.youtube.com/watch?v=HwJyg5o3HGg
(2)https://commons.wikimedia.org/wiki/File:Convolutional_Neural_Network_with_Color_Image_Filter.gif 2 / 13
1. Models and Assumptions
1. Scalar Field d : R 3 → R + 0 of densities 2. Ray r (t) = x 0 + tω , x 0 ∈ R 3 , ω ∈ S 2 3. Received Illumination I out (x 0 , ω) ∈ R + 0
d ∶ ℝ
3→ ℝ
0+r(𝑡) = 𝑥
0+ 𝑡𝜔
𝐼
𝑖𝑛: ℝ
0+𝐼
𝑜𝑢𝑡: ℝ
0+3 / 13
1.1 Only Absorption
Assume a medium that only absorbs incoming light, no emission or scattering.
I out (x 0 , ω) = Z ∞
0
g (t) exp
− Z t
0
τ (v (r (t 0 )))dt 0
dt with g (s) = c(s)τ (s) +
Z
Ω
p(ω, ω 0 )I out (r (t), ω 0 )d ω 0
Set g (∞) = I in and zero everywhere else (only absorption). Set τ (d ) = d
⇒ Transparency T (s) = exp
− Z s
0
d (r (t))dt
⇒ Received Illumination I out = T (t max )I in
Nelson Max. Optical Models for Direct Volume Rendering. TVCG 1995 Kajiya, von Herzen. Ray Tracing Volume Densities. Computer Graphics 1984
4 / 13
1.1 Only Absorption
Assume a medium that only absorbs incoming light, no emission or scattering.
I out (x 0 , ω) = Z ∞
0
g (t) exp
− Z t
0
τ (v (r (t 0 )))dt 0
dt with g (s) = c(s)τ (s) +
Z
Ω
p(ω, ω 0 )I out (r (t), ω 0 )d ω 0 Set g (∞) = I in and zero everywhere else (only absorption).
Set τ (d ) = d
⇒ Transparency T (s) = exp
− Z s
0
d (r (t))dt
⇒ Received Illumination I out = T (t max )I in
Nelson Max. Optical Models for Direct Volume Rendering. TVCG 1995 Kajiya, von Herzen. Ray Tracing Volume Densities. Computer Graphics 1984
4 / 13
1.1 Only Absorption
Assume a medium that only absorbs incoming light, no emission or scattering.
I out (x 0 , ω) = Z ∞
0
g (t) exp
− Z t
0
τ (v (r (t 0 )))dt 0
dt with g (s) = c(s)τ (s) +
Z
Ω
p(ω, ω 0 )I out (r (t), ω 0 )d ω 0 Set g (∞) = I in and zero everywhere else (only absorption).
Set τ (d ) = d
⇒ Transparency T (s) = exp
− Z s
0
d (r (t))dt
⇒ Received Illumination I out = T (t max )I in
Nelson Max. Optical Models for Direct Volume Rendering. TVCG 1995 Kajiya, von Herzen. Ray Tracing Volume Densities. Computer Graphics 1984
4 / 13
1.1 Only Absorption
5 / 13
1.1 Only Absorption: Solutions
Densities on a grid v i
(1)
Trilinear Interpolation N i (x)
(2)
⇒ log I out = X
i ∈voxels 8
X
j =1
v ij Z t
1(i )t
(i )0N j (r (t))dt
Assemble into matrices for all rays:
⇒ log I out = Nv
(1)https://en.wikipedia.org/wiki/Regular_grid
(2)https://en.wikipedia.org/wiki/Trilinear_interpolation
6 / 13
1.1 Only Absorption: Solutions
Densities on a grid v i
(1)
Trilinear Interpolation N i (x)
(2)
⇒ log I out = X
i ∈voxels 8
X
j =1
v ij
Z t
1(i )t
0(i )N j (r (t))dt
Assemble into matrices for all rays:
⇒ log I out = Nv
(1)https://en.wikipedia.org/wiki/Regular_grid
(2)https://en.wikipedia.org/wiki/Trilinear_interpolation
6 / 13
1.1 Only Absorption: Differentiation
log I out = N v
output images matrix of
voxel-pixel contributions
voxel densities
⇒ Linear in v , simply solve it
7 / 13
1.1 Only Absorption: Differentiation
log I out = N v
output images matrix of
voxel-pixel contributions
voxel densities
⇒ Linear in v , simply solve it
7 / 13
1.2 With Emission
Now every point in space also emits light g (d )
Usually dependent on τ (d ): g (d ) := c(d )τ (d ) for some color c(d ).
I out = T (t max )I in + Z t
max0
g (t)T (t)dt
with T (s) = exp
− Z s
0
τ (v (r (t)))dt
This is a nested integral and cannot be solved analytically.
8 / 13
1.2 With Emission
Now every point in space also emits light g (d )
Usually dependent on τ (d ): g (d ) := c(d )τ (d ) for some color c(d ).
I out = T (t max )I in + Z t
max0
g (t)T (t)dt
with T (s) = exp
− Z s
0
τ (v (r (t)))dt
This is a nested integral and cannot be solved analytically.
8 / 13
1.2 With Emission
τ (d ) = d , c(d ) = d
τ (d ), c(d ) arbitrary
9 / 13
1.2 With Emission
τ (d ) = d , c(d ) = d τ (d ), c(d ) arbitrary
9 / 13
1.2 With Emission
τ (d ) = d , c(d ) = d τ (d ), c(d ) arbitrary
9 / 13
2. Automatic Differentiation
x 0 = const x 1 = f 1 (x 0 , w 1 ) x 2 = f 2 (x 1 , w 2 )
. . .
x k = f k (x k−1 , w k ) with
k ∈ N number of operations x i ∈ R n state variables
x k ∈ R m size of the output / last state w i ∈ R p parameters
⇒ dx k dw 1
10 / 13
2. Automatic Differentiation
x 0 = const x 1 = f 1 (x 0 , w 1 ) x 2 = f 2 (x 1 , w 2 )
. . .
x k = f k (x k−1 , w k ) with
k ∈ N number of operations x i ∈ R n state variables
x k ∈ R m size of the output / last state w i ∈ R p parameters
⇒ dx k dw 1
10 / 13
2.1 AutoDiff: Forward Mode
x 0 = const x 1 = f 1 (x 0 , w 1 ) x 2 = f 2 (x 1 , w 2 )
. . .
x k = f n (x k−1 , w k )
Replace each x i , w i by
˜ x i =
x i , dx
idw
1, ˜ w i =
w i , dw
idw
1Note that ˜ x 0 = hx 0 , 0i, ˜ w 1 = hw 1 , 1i
Replace a function c = f (a, b) by ˜ c = ˜ f ( ˜ a, ˜ b) with
c, dc
dc 1
=
f (a, b),
J f |a (a, b) da i
dw 1 + J f |b (a, b) db i
dw 1
⇒ O(np) memory
⇒ O(kn 2 + knp) computations
11 / 13
2.1 AutoDiff: Forward Mode
x 0 = const x 1 = f 1 (x 0 , w 1 ) x 2 = f 2 (x 1 , w 2 )
. . .
x k = f n (x k−1 , w k )
Replace each x i , w i by
˜ x i =
x i , dx
idw
1, ˜ w i =
w i , dw
idw
1Note that ˜ x 0 = hx 0 , 0i, ˜ w 1 = hw 1 , 1i
Replace a function c = f (a, b) by ˜ c = ˜ f ( ˜ a, ˜ b) with
c, dc
dc 1
=
f (a, b),
J f |a (a, b) da i
dw 1 + J f |b (a, b) db i
dw 1
⇒ O(np) memory
⇒ O(kn 2 + knp) computations
11 / 13
2.1 AutoDiff: Forward Mode
x 0 = const x 1 = f 1 (x 0 , w 1 ) x 2 = f 2 (x 1 , w 2 )
. . .
x k = f n (x k−1 , w k )
Replace each x i , w i by
˜ x i =
x i , dx
idw
1, ˜ w i =
w i , dw
idw
1Note that ˜ x 0 = hx 0 , 0i, ˜ w 1 = hw 1 , 1i
Replace a function c = f (a, b) by ˜ c = ˜ f ( ˜ a, ˜ b) with
c, dc
dc 1
=
f (a, b),
J f |a (a, b) da i
dw 1 + J f |b (a, b) db i dw 1
⇒ O(np) memory
⇒ O(kn 2 + knp) computations
11 / 13
2.1 AutoDiff: Forward Mode
x 0 = const x 1 = f 1 (x 0 , w 1 ) x 2 = f 2 (x 1 , w 2 )
. . .
x k = f n (x k−1 , w k )
Replace each x i , w i by
˜ x i =
x i , dx
idw
1, ˜ w i =
w i , dw
idw
1Note that ˜ x 0 = hx 0 , 0i, ˜ w 1 = hw 1 , 1i
Replace a function c = f (a, b) by ˜ c = ˜ f ( ˜ a, ˜ b) with
c, dc
dc 1
=
f (a, b),
J f |a (a, b) da i
dw 1 + J f |b (a, b) db i dw 1
⇒ O(np) memory
⇒ O(kn 2 + knp) computations
11 / 13
2.2 AutoDiff: Backward Mode / Adjoint Method
x 0 = const x 1 = f 1 (x 0 , w 1 ) x 2 = f 2 (x 1 , w 2 )
. . .
x k = f n (x k−1 , w k )
Assume x k ∈ R is a scalar (m = 1), define x ˆ i = dx
kdx
i∈ R n , ˆ w i = dx
kdw
i∈ R p , Note: ˆ x k = 1.
1. Forward Pass, compute x k normally, but save intermediate results 2. Backward Pass: For i = k, ..., 1
ˆ
x i −1 = J f
i|x
i −1(x i −1 , w i )
Tx ˆ i ˆ
w i = J f
i|w
i(x i −1 , w i )
Tx ˆ i
⇒ O(kn) memory
⇒ O(kn 2 + np) computations
12 / 13
2.2 AutoDiff: Backward Mode / Adjoint Method
x 0 = const x 1 = f 1 (x 0 , w 1 ) x 2 = f 2 (x 1 , w 2 )
. . .
x k = f n (x k−1 , w k )
Assume x k ∈ R is a scalar (m = 1), define x ˆ i = dx
kdx
i∈ R n , ˆ w i = dx
kdw
i∈ R p , Note: ˆ x k = 1.
1. Forward Pass, compute x k normally, but save intermediate results 2. Backward Pass: For i = k, ..., 1
ˆ
x i −1 = J f
i|x
i −1(x i −1 , w i )
Tx ˆ i ˆ
w i = J f
i|w
i(x i −1 , w i )
Tx ˆ i
⇒ O(kn) memory
⇒ O(kn 2 + np) computations
12 / 13
2.2 AutoDiff: Backward Mode / Adjoint Method
x 0 = const x 1 = f 1 (x 0 , w 1 ) x 2 = f 2 (x 1 , w 2 )
. . .
x k = f n (x k−1 , w k )
Assume x k ∈ R is a scalar (m = 1), define x ˆ i = dx
kdx
i∈ R n , ˆ w i = dx
kdw
i∈ R p , Note: ˆ x k = 1.
1. Forward Pass, compute x k normally, but save intermediate results
2. Backward Pass: For i = k, ..., 1 ˆ
x i −1 = J f
i|x
i −1(x i −1 , w i )
Tx ˆ i ˆ
w i = J f
i|w
i(x i −1 , w i )
Tx ˆ i
⇒ O(kn) memory
⇒ O(kn 2 + np) computations
12 / 13
2.2 AutoDiff: Backward Mode / Adjoint Method
x 0 = const x 1 = f 1 (x 0 , w 1 ) x 2 = f 2 (x 1 , w 2 )
. . .
x k = f n (x k−1 , w k )
Assume x k ∈ R is a scalar (m = 1), define x ˆ i = dx
kdx
i∈ R n , ˆ w i = dx
kdw
i∈ R p , Note: ˆ x k = 1.
1. Forward Pass, compute x k normally, but save intermediate results 2. Backward Pass: For i = k, ..., 1
ˆ
x i −1 = J f
i|x
i −1(x i −1 , w i )
Tx ˆ i ˆ
w i = J f
i|w
i(x i −1 , w i )
Tx ˆ i
⇒ O(kn) memory
⇒ O(kn 2 + np) computations
12 / 13
2.2 AutoDiff: Backward Mode / Adjoint Method
x 0 = const x 1 = f 1 (x 0 , w 1 ) x 2 = f 2 (x 1 , w 2 )
. . .
x k = f n (x k−1 , w k )
Assume x k ∈ R is a scalar (m = 1), define x ˆ i = dx
kdx
i∈ R n , ˆ w i = dx
kdw
i∈ R p , Note: ˆ x k = 1.
1. Forward Pass, compute x k normally, but save intermediate results 2. Backward Pass: For i = k, ..., 1
ˆ
x i −1 = J f
i|x
i −1(x i −1 , w i )
Tx ˆ i ˆ
w i = J f
i|w
i(x i −1 , w i )
Tx ˆ i
⇒ O(kn) memory
⇒ O(kn 2 + np) computations
12 / 13
2.3 AutoDiff: Comparison
Forward Mode I ⇒ O(np) memory
⇒ O(kn 2 + knp) ops
I Arbitrary number of outputs
I Compile-time: implement with operator overloading I Expensive for large p
⇒ use if k large, p small
⇒ Sensitivity Analysis in simulations
Backward Mode I ⇒ O(kn) memory
⇒ O(kn 2 + np) ops
I Only one output! Or repeat backward pass
I Dynamic computation graph Dynamic memory
I Lots of memory
⇒ use if k small, p large
⇒ Neural networks
For DVR we need some hybrid method...
13 / 13
2.3 AutoDiff: Comparison
Forward Mode I ⇒ O(np) memory
⇒ O(kn 2 + knp) ops I Arbitrary number of outputs
I Compile-time: implement with operator overloading I Expensive for large p
⇒ use if k large, p small
⇒ Sensitivity Analysis in simulations
Backward Mode I ⇒ O(kn) memory
⇒ O(kn 2 + np) ops
I Only one output! Or repeat backward pass
I Dynamic computation graph Dynamic memory
I Lots of memory
⇒ use if k small, p large
⇒ Neural networks
For DVR we need some hybrid method...
13 / 13
2.3 AutoDiff: Comparison
Forward Mode I ⇒ O(np) memory
⇒ O(kn 2 + knp) ops I Arbitrary number of outputs
I Compile-time: implement with operator overloading
I Expensive for large p
⇒ use if k large, p small
⇒ Sensitivity Analysis in simulations
Backward Mode I ⇒ O(kn) memory
⇒ O(kn 2 + np) ops
I Only one output! Or repeat backward pass
I Dynamic computation graph Dynamic memory
I Lots of memory
⇒ use if k small, p large
⇒ Neural networks
For DVR we need some hybrid method...
13 / 13
2.3 AutoDiff: Comparison
Forward Mode I ⇒ O(np) memory
⇒ O(kn 2 + knp) ops I Arbitrary number of outputs
I Compile-time: implement with operator overloading I Expensive for large p
⇒ use if k large, p small
⇒ Sensitivity Analysis in simulations
Backward Mode I ⇒ O(kn) memory
⇒ O(kn 2 + np) ops
I Only one output! Or repeat backward pass
I Dynamic computation graph Dynamic memory
I Lots of memory
⇒ use if k small, p large
⇒ Neural networks
For DVR we need some hybrid method...
13 / 13
2.3 AutoDiff: Comparison
Forward Mode I ⇒ O(np) memory
⇒ O(kn 2 + knp) ops I Arbitrary number of outputs
I Compile-time: implement with operator overloading I Expensive for large p
⇒ use if k large, p small
⇒ Sensitivity Analysis in simulations
Backward Mode I ⇒ O(kn) memory
⇒ O(kn 2 + np) ops
I Only one output! Or repeat backward pass
I Dynamic computation graph Dynamic memory
I Lots of memory
⇒ use if k small, p large
⇒ Neural networks
For DVR we need some hybrid method...
13 / 13
2.3 AutoDiff: Comparison
Forward Mode I ⇒ O(np) memory
⇒ O(kn 2 + knp) ops I Arbitrary number of outputs
I Compile-time: implement with operator overloading I Expensive for large p
⇒ use if k large, p small
⇒ Sensitivity Analysis in simulations
Backward Mode I ⇒ O(kn) memory
⇒ O(kn 2 + np) ops
I Only one output! Or repeat backward pass
I Dynamic computation graph Dynamic memory
I Lots of memory
⇒ use if k small, p large
⇒ Neural networks
For DVR we need some hybrid method...
13 / 13
2.3 AutoDiff: Comparison
Forward Mode I ⇒ O(np) memory
⇒ O(kn 2 + knp) ops I Arbitrary number of outputs
I Compile-time: implement with operator overloading I Expensive for large p
⇒ use if k large, p small
⇒ Sensitivity Analysis in simulations
Backward Mode I ⇒ O(kn) memory
⇒ O(kn 2 + np) ops
I Only one output! Or repeat backward pass
I Dynamic computation graph Dynamic memory
I Lots of memory
⇒ use if k small, p large
⇒ Neural networks
For DVR we need some hybrid method...
13 / 13