当光线穿过胶体,由于胶体微粒对光线的散射作用,产生丁达尔现象。在实时渲染中这样的效果常称为体积光 (Volumetric Light),有时也称作上帝光 (god light)。
本文将简单介绍体积光散射效果的相关原理,及在 Unity SRP 下的简单实现。
本文大部分内容参考自 Real-time Rendering 4th Chapter 14 [0] 和 GDC 2016 上 Inside 开发者的 presentation [1].
本文需要的前置知识包括
- 数学
- 图形学
- Unity SRP
先放个效果图
![559e9c26d3a3d02d91cecc7a65192579.png](https://i-blog.csdnimg.cn/blog_migrate/5028e396d503f9457e8c80df167f8722.jpeg)
代码在 GitHub, tag: volume-light
https://github.com/SardineFish/SRP-Demos/tree/volume-lightgithub.comLight Scattering
光在介质中传播,会受以下四种因素而发生改变:
- Absorption,光线被物质吸收并由光能转化为其他能量
- Out-scattering,光线被介质中的微粒向外散射
- Emission,介质由于黑体辐射等因素产生自发光
- In-scattering,从其他地方散射到当前光路上的光线
![af65afde3c713924d2419ff88edac8be.png](https://i-blog.csdnimg.cn/blog_migrate/2363197ac88d66680b6f5d0749d75f3f.png)
其中,介质对光线的吸收和散射会影响光线在介质中的透射率 (transmittance)。
我们可以用下式来描述一个点光源发出的光线在介质中的散射效果:
其中
![0142656d18815d90ae05ed23451b7d99.png](https://i-blog.csdnimg.cn/blog_migrate/a558cfc14688ad1731fb047855e66d33.png)
Transmittance
光线在介质中两点
其中
该式又被称为 Beer-Lambert Law,式中
![89ea2cf2d13ce22f3cd51c283bf34f4a.png](https://i-blog.csdnimg.cn/blog_migrate/6b05218081b592b38353999b01e93abe.png)
Scattering
在介质中的 x 处,从点光源发出的光线散射到 v 方向上的光,可以通过下式表述
where $n$ is the number of lights, p(v, l) is the phase function, v(x, p) is the visibility function,is the direction vector to the ith light, and
is the position of the ith light. In addition,
is the radiance from the ith light as a function of the distance to its position.
Visibility Function
式中的 visibility function v(x, p) 表示从光源位置 p 到介质中位置 x 的光的通过率,可以表述为以下函数
也就是说,我们需要考虑从光源发出的光线受物体的遮挡,以及在射入到介质中 x 点所受到的衰减作用。
Phase Function
phase function 用于描述在宏观上光线在介质中经过散射到各方向上的概率分布,通常表示为入射与出射光线夹角 θ 的函数 p(θ). 因为能量守恒,phase function 在单位球上的积分必须等于1.
![d3a9abf00475342130d56b9aaefceb7b.png](https://i-blog.csdnimg.cn/blog_migrate/77dc1c07399381fc2b4d3ea5a1224c41.png)
基于物理的 phase function 根据介质中微粒与入射光线波长的相对大小
-
时适用 Rayleigh scattering (例如空气)
-
时适用 Mie scattering
-