赞
踩
本文主要参考作者在Siggraph上的PPT,都在参考文献中给出,详细理论证明请看论文,代码也在以下链接的论文主页上
最终计算方法在最后两张图上,参考代码在参考文献网站上
参考代码,相关解释需要看参考文献[3]
对于游戏开发而言,实际意义在于,可以预先给定一个场景的CubeMap,计算出球谐函数的9个参数,用着9个参数可以计算出mesh表面顶点的irradiance。
We must scale E by the surface albedo ρ, which may be dependent on position p and be described by a texture, to find the radiosity B, which corresponds directly to the image intensity.
B ( p , n ) = ρ ( p ) E ( n ) B(p,n)=\rho(p)E(n) B(p,n)=ρ(p)E(n)
以下提到的符号请参考https://en.wikipedia.org/wiki/Radiance
The irradiance E is then a function of the surface normal n only and is given by an integral over the upper hemisphere Ω(n).
E
(
n
)
=
∫
Ω
(
n
)
L
(
ω
)
(
n
⋅
ω
)
d
ω
E(n) = \int_{\Omega(n)}L(\omega)(n \cdot \omega)d\omega
E(n)=∫Ω(n)L(ω)(n⋅ω)dω
Spherical harmonics
Y
l
m
Y_{lm}
Ylm, with
l
≥
0
l \ge 0
l≥0 and
−
l
≤
m
≤
l
−l \le m \le l
−l≤m≤l, are the analogue on the sphere to the Fourier basis on the line or circle. The first 9 spherical harmonics (with
l
≤
2
l \le 2
l≤2) are simply constant (
l
=
0
l = 0
l=0), linear (
l
=
1
l = 1
l=1), and quadratic (
l
=
2
l = 2
l=2) polynomials of the cartesian components (x, y, z). and are given numerically by
(3)
(
x
,
y
,
z
)
=
(
sin
θ
cos
ϕ
,
sin
θ
sin
ϕ
,
cos
θ
)
Y
00
=
0.282095
(
Y
11
;
Y
10
;
Y
1
−
1
)
(
θ
,
ϕ
)
=
0.488603
(
x
;
z
;
y
)
(
Y
21
;
Y
2
−
1
;
Y
2
−
2
)
(
θ
,
ϕ
)
=
1.092548
(
x
z
;
y
z
;
x
y
)
Y
20
(
θ
,
ϕ
)
=
0.315392
(
3
z
2
−
1
)
Y
22
(
θ
,
ϕ
)
=
0.546274
(
x
2
−
y
2
)
(x,y,z)amp;=(sinθcosϕ,sinθsinϕ,cosθ)Y00amp;=0.282095(Y11;Y10;Y1−1)(θ,ϕ)amp;=0.488603(x;z;y)(Y21;Y2−1;Y2−2)(θ,ϕ)amp;=1.092548(xz;yz;xy)Y20(θ,ϕ)amp;=0.315392(3z2−1)Y22(θ,ϕ)amp;=0.546274(x2−y2)
E
(
θ
,
ϕ
)
E(\theta, \phi)
E(θ,ϕ) and
L
(
θ
,
ϕ
)
L(\theta, \phi)
L(θ,ϕ) can be represented by the coefficients—
E
l
m
E_{lm}
Elm and
L
l
m
L_{lm}
Llm—in their spherical harmonic expansion.
We also define
A
=
(
n
⋅
ω
)
A=(n \cdot \omega)
A=(n⋅ω) with coefficients
A
l
A_l
Al. Since
A
A
A has no azimuthal dependence,
m
=
0
m=0
m=0 and we use only the
l
l
l index.
A
(
θ
)
=
m
a
x
[
cos
θ
,
0
]
=
∑
l
A
l
Y
l
0
(
θ
)
A(\theta)=max[\cos \theta, 0]=\sum_l A_l Y_{l0}(\theta)
A(θ)=max[cosθ,0]=l∑AlYl0(θ)
With these definitions one can show (参考文献[1]可知) that
E
l
m
=
4
π
2
l
+
1
A
l
L
l
m
E_{lm}=\sqrt{\frac{4 \pi}{2l+1}}A_lL_{lm}
Elm=2l+14π
AlLlm
It will be convenient to define a new variable
A
l
^
\hat{A_{l}}
Al^ by
A
l
^
=
4
π
2
l
+
1
A
l
\hat{A_l}=\sqrt{\frac{4 \pi}{2l+1}}A_l
Al^=2l+14π
Al
For rendering, it will be convenient to expand out the irradiance.
(7)
E
(
θ
,
ϕ
)
=
∑
l
,
m
A
^
l
L
l
m
Y
l
m
(
θ
,
ϕ
)
E(\theta, \phi)=\sum_{l,m} \hat{A}_l L_{lm} Y_{lm}(\theta, \phi) \tag{7}
E(θ,ϕ)=l,m∑A^lLlmYlm(θ,ϕ)(7)
An analytic formula for
A
l
A^l
Al can be derived. It can be shown that
A
l
A^l
Al vanishes for odd values of
l
>
1
l > 1
l>1, and even terms fall off very rapidly as
l
−
5
/
2
l^{-5/2}
l−5/2. The analytic formulae are given by
l
=
1
A
^
1
=
2
π
3
l
>
1
,
o
d
d
A
^
l
=
0
l
e
v
e
n
A
^
l
=
2
π
(
−
1
)
l
2
−
1
(
l
+
2
)
(
l
−
1
)
[
l
!
2
l
(
l
2
!
)
2
]
l=1amp;ˆA1=2π3lgt;1,oddamp;ˆAl=0levenamp;ˆAl=2π(−1)l2−1(l+2)(l−1)[l!2l(l2!)2]
Numerically, the first few terms are
(9)
A
^
0
=
3.141593
A
^
1
=
2.094395
A
^
2
=
0.785398
A
^
3
=
0
A
^
4
=
−
0.130900
A
^
5
=
0
A
^
6
=
0.049087
\hat{A}_0 = 3.141593 \quad \hat{A}_1 = 2.094395 \quad \hat{A}_2 = 0.785398 \\ \hat{A}_3 = 0 \quad \hat{A}_4 = −0.130900 \quad \hat{A}_5 = 0 \quad \hat{A}_6 = 0.049087 \tag{9}
A^0=3.141593A^1=2.094395A^2=0.785398A^3=0A^4=−0.130900A^5=0A^6=0.049087(9)
给定envmap,计算9个lighting coefficient
L
l
m
L_{lm}
Llm
For rendering, we can find the irradiance using equation 7. Since we are only considering
l
≤
2
l \le 2
l≤2, the irradiance is simply a quadratic polynomial of the coordinates of the (normalized) surface normal. Hence, with
n
t
=
(
x
y
z
1
)
n^t = (x \ y\ z\ 1)
nt=(x y z 1), we can write
E
(
n
)
=
n
t
M
n
E(n)=n^tMn
E(n)=ntMn
M is a symmetric 4x4 matrix. Each color has an independent matrix M. Equation 11 is particularly useful for rendering, since we require only a matrix-vector multiplication and a dot-product to compute E. The matrix M is obtained by expanding equation 7:
(12)
M
=
(
c
1
L
22
c
1
L
2
−
2
c
1
L
21
c
2
L
11
c
1
L
2
−
2
−
c
1
L
22
c
1
L
2
−
1
c
2
L
1
−
1
c
1
L
21
c
1
L
21
c
3
L
20
c
2
L
10
c
2
L
11
c
2
L
1
−
1
c
2
L
10
c
4
L
00
−
c
5
L
20
)
c
1
=
0.429043
c
2
=
0.511664
c
3
=
0.743125
c
4
=
0.886227
c
5
=
0.247708
M= (c1L22amp;c1L2−2amp;c1L21amp;c2L11c1L2−2amp;−c1L22amp;c1L2−1amp;c2L1−1c1L21amp;c1L21amp;c3L20amp;c2L10c2L11amp;c2L1−1amp;c2L10amp;c4L00−c5L20)
The entries of M depend on the 9 lighting coefficients
L
l
m
L_{lm}
Llm and the expressions for the spherical harmonics. The constants come from the numerical values of
A
^
l
\hat{A}_l
A^l given in equation 9, and the spherical harmonic normalizations given in equation 3.
On systems not optimized for matrix and vector operations, it may be more efficient to explicitly write out equation 7 for the irradiance as a sum of terms, i.e. expand equation 12:
E
(
n
)
=
c
1
L
22
(
x
2
−
y
2
)
+
c
3
L
20
z
2
+
c
4
L
00
−
c
5
L
20
+
2
c
1
(
L
2
−
2
x
y
+
L
21
x
z
+
L
2
−
1
y
z
)
+
2
c
2
(
L
11
x
+
L
1
−
1
y
+
L
10
z
)
E(n)amp;=c1L22(x2−y2)+c3L20z2+c4L00−c5L20amp;+2c1(L2−2xy+L21xz+L2−1yz)amp;+2c2(L11x+L1−1y+L10z)
[1] An Efficient Representation for Irradiance Environment Maps
[2] On the Relationship between Radiance and Irradiance: Determining the illumination from images of a convex Lambertian object
[3] Light Probe Image Gallery
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。