installshieldd的 thumbl按键在哪里

您所在位置: &
&nbsp&&nbsp&nbsp&&nbsp
l.a. banks - vampire huntress legend 3 - the hunted:(洛杉矶银行吸血鬼女猎人传说3 -猎物).pdf 327页
本文档一共被下载:
次 ,您可全文免费在线阅读后下载本文档。
下载提示
1.本站不保证该用户上传的文档完整性,不预览、不比对内容而直接下载产生的反悔问题本站不予受理。
2.该文档所得收入(下载+内容+预览三)归上传者、原创者。
3.登录后可充值,立即自动返金币,充值渠道很便利
l.a. banks - vampire huntress legend 3 - the hunted:(洛杉矶银行吸血鬼女猎人传说3 -猎物)
你可能关注的文档:
··········
··········
Generated by ABC Amber LIT Converter, /abclit.html
The Hunted.
Copyright (C) 2004 by Leslie Esdaile Banks.
All rights reserved.
Generated by ABC Amber LIT Converter, /abclit.html
St. Martin's Press,
175Fifth Avenue ,
New York,N.Y.10010.
ISBN 0-312-32030-2
EAN 978--0
First Edition: June 2004
Printed in theUnited States of America .
DEDICATION AND SPECIAL ACKNOWLEDGMENTS
This book is dedicated to my support system, those individuals who have always had my back and
helped me through the exciting process of writing an ongoing saga. Everyone, even my series heroine (the
Neteru), needs a squad, backup, and in that regard I'm truly blessed. Those who have helped me (in
both seen and unseen methods) are many… and they are loving, patient, and bring boundless
encouragement in ways too numerous to list. So, this book and this series are dedicated to my husband
and children, my sisters and parents, my sister-authors, and the many book clubs and readers groups that
keep me so thoroughly engaged in developing the next installment.
Special acknowledgments go to &the engine& of people who are also dear friends who consistently fuel
me: my agent, Manie Barron, who created the opportunity—THANK YOU; my editor, Monique
Patterson, who is a visionary, a pure joy to work with, and a consummate professional whom I consider
Monica Peters of GritsNCheese, who is tireless in her publicizing and diligent promotion of
Penny Makras, who always hits the mark and
Harriet Seltzer, for
her invaluable help in setting up venues for our H Christopher Bonelli, my webmaster of
Vince Natale, the cover artist for this seriesùVince, your images blow my mind and
are awesome!; Michael Storrings, whose cover d my alumni brother and homeboy,
Ray Jones, who makes sure my science is tight and my head is right
正在加载中,请稍后...&p&在计算机图形学领域,着色(Shading)是指根据表面或者多边形相对光源和相机的角度和距离来计算它的颜色的过程。不同的用途可以使用不同的着色算法,CAD等追求响应速度的交互式图形领域可以使用简单快速的着色算法,卡通油画等艺术效果可以使用非真实感(Nonphotorealistic)着色算法,而追求真实感的CG电影或游戏则可以使用基于物理建模的着色算法。&/p&&p&本文关注基于物理着色的BRDF模型,希望能将BRDF的来龙去脉讲清楚,并分析Cook-Torrance BRDF公式的推导过程。本人水平有限,如有错误,请不吝指教。&/p&&p&要模拟真实光照,我们先要弄清光照的现象。&/p&&h2&光照现象&/h2&&p&光由光子组成,光子既具有粒子的特性,又表现出波的特性。从波的角度看,光是电磁波的一种,不同频率(波长)的光波能量不同,频率越高(波长越短),能量越高,频率越低(波长越长),能量越低,其中波长在380nm-780nm范围内的光波能被人类的视网膜感知到,这个范围的光波称为可见光,不同频率的可见光被人感知为不同的颜色,频率越高的光偏蓝,频率较低的光则偏红。&br&&/p&&figure&&img src=&https://pic2.zhimg.com/fce81f9d4badfd4915eab_b.jpg& data-rawwidth=&1500& data-rawheight=&735& class=&origin_image zh-lightbox-thumb& width=&1500& data-original=&https://pic2.zhimg.com/fce81f9d4badfd4915eab_r.jpg&&&/figure&&p&光学根据研究的尺度可以分为波动光学(Wave Optics)和几何光学(Geometric Optics),波动光学比几何光学复杂,而由于图形学领域关注的尺度远大于可见光的波长(380nm-780nm),也很少涉及光的偏振、干涉和衍射等波动光学才能解释的现象,所以我们一般用几何光学来建立光照模型。&br&&/p&&p&&b&光学平面边界上的散射&/b&&br&&/p&&br&&p&我们在中学物理课上学过光学平面边界的散射。&/p&&figure&&img src=&https://pic4.zhimg.com/cc25239f2cbd0188e36ccb68b40e9bf1_b.jpg& data-rawwidth=&1149& data-rawheight=&647& class=&origin_image zh-lightbox-thumb& width=&1149& data-original=&https://pic4.zhimg.com/cc25239f2cbd0188e36ccb68b40e9bf1_r.jpg&&&/figure&&p&平面边界两边物质的折射率(Refractive Index)不同,当一束光线从一种物质照射到平面边界上时,其中一部分在平面边界被反射回这种物质,反射方向为入射方向关于平面法线的对称向量:&/p&&img src=&https://www.zhihu.com/equation?tex=r_i+%3D+2+%28+n+%5Ccdot+l+%29+n+-+l& alt=&r_i = 2 ( n \cdot l ) n - l& eeimg=&1&&&br&&blockquote&其中&img src=&https://www.zhihu.com/equation?tex=r_i& alt=&r_i& eeimg=&1&&是反射向量,&img src=&https://www.zhihu.com/equation?tex=l& alt=&l& eeimg=&1&&是光线入射向量,&img src=&https://www.zhihu.com/equation?tex=n& alt=&n& eeimg=&1&&是平面法线&br&向量间的&img src=&https://www.zhihu.com/equation?tex=%5Ccdot+& alt=&\cdot & eeimg=&1&&表示向量的点积,两个单位向量的点积等于它们夹角的余弦。&/blockquote&&p&另一部分光穿过平面边界折射进入另一种物质,折射方向可由Snell法则(&a href=&https://link.zhihu.com/?target=https%3A//en.wikipedia.org/wiki/Snell%2527s_law& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&Snell's Law&/a&)计算得出:&/p&&img src=&https://www.zhihu.com/equation?tex=%5Cfrac%7Bsin+%5Ctheta+_%7Bi%7D+%7D%7Bsin+%5Ctheta+_%7Bt%7D%7D++%3D+%5Cfrac%7Bv+_%7Bi%7D+%7D%7Bv+_%7Bt%7D%7D+%3D+%5Cfrac%7B%5Clambda++_%7Bi%7D+%7D%7B%5Clambda++_%7Bt%7D%7D+%3D+%5Cfrac%7Bn+_%7Bt%7D+%7D%7Bn+_%7Bi%7D%7D& alt=&\frac{sin \theta _{i} }{sin \theta _{t}}
= \frac{v _{i} }{v _{t}} = \frac{\lambda
_{i} }{\lambda
_{t}} = \frac{n _{t} }{n _{i}}& eeimg=&1&&&blockquote&其中下标&img src=&https://www.zhihu.com/equation?tex=i& alt=&i& eeimg=&1&&表示入射介质,下标&img src=&https://www.zhihu.com/equation?tex=t& alt=&t& eeimg=&1&&表示折射介质,&img src=&https://www.zhihu.com/equation?tex=%5Ctheta+& alt=&\theta & eeimg=&1&&表示光线相对于边界法线的角度,&img src=&https://www.zhihu.com/equation?tex=v& alt=&v& eeimg=&1&&表示介质中的光速,&img src=&https://www.zhihu.com/equation?tex=%5Clambda+& alt=&\lambda & eeimg=&1&&表示介质中的波长,&img src=&https://www.zhihu.com/equation?tex=n& alt=&n& eeimg=&1&&表示介质的折射率。&/blockquote&&p&反射和折射的比例由菲涅尔方程(&a href=&https://link.zhihu.com/?target=https%3A//en.wikipedia.org/wiki/Fresnel_equations& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&Fresnel Equations&/a&)给出,菲涅尔方程比较复杂,图形学里一般使用近似公式计算。&/p&&p&&b&非光学平面上的散射&/b&&/p&&p&现实世界中的表面绝大多数都是凹凸不平的,尽管这种凹凸不平小于肉眼可见的尺度,但远大于光线的波长。在这种情况下,可以把表面看成是大量朝向各异的微小光学平面的集合,我们肉眼可见的每个点都包含了很多个这样的微小光学平面。&/p&&p&光线照射到这些微小表面上时,同样&i&&b&一部分在表面发生反射&/b&&/i&。这些朝向不同的微表面把入射光线反射到不同的方向。&/p&&figure&&img src=&https://pic2.zhimg.com/f1869d153af_b.jpg& data-rawwidth=&1379& data-rawheight=&854& class=&origin_image zh-lightbox-thumb& width=&1379& data-original=&https://pic2.zhimg.com/f1869d153af_r.jpg&&&/figure&&p&从上图可以看出表面粗糙程度对光线反射方向的影响。上面的物体表面相对光滑,微表面朝向差别较小,反射光线的方向差别也比较小,表面反射环境的图像比较锐利。下面的物体表面比较粗糙,微表面朝向差别大,反射光线的方向差别也比较大,表面反射环境的图像比较模糊。&/p&&p&&i&&b&另一部分光线发生折射&/b&&/i&,折射光线何去何从取决于物质的组成成分。&/p&&p&对于玻璃等透明物质,光线穿透玻璃,在另一边再次发生反射折射,图形学用双向透射分布函数BTDF来模拟这种现象,以后有机会再写。下面我们看看不透明和半透明物质。&/p&&p&对于金属,折射进表面的光线的能量会立即被金属中的自由电子吸收,转换成电子的能量,不再可见(下图左边)。对于非金属(电介质或绝缘体),它们往往不是由单一成分构成,而可以认为其中包含了很多折射率不同的微粒,光线遇到这些粒子后发生反射折射,在物质内部不断传播,散射到不同方向,其中一部分会再次穿过表面被观察到,这种现象称为次表面散射(Subsurface Scattering,下图右边穿出表面的蓝色光线),也有一部分在传输过程中被吸收。&/p&&figure&&img src=&https://pic2.zhimg.com/41b6e086c47de7dc6b35e14e_b.jpg& data-rawwidth=&1492& data-rawheight=&315& class=&origin_image zh-lightbox-thumb& width=&1492& data-original=&https://pic2.zhimg.com/41b6e086c47de7dc6b35e14e_r.jpg&&&/figure&&p&根据物质属性和观察尺度的不同,次表面散射会表现出不同的效果。&/p&&p&如下面的左上图,如果光线在物质中传播距离小于观察尺度(绿色区域,可以认为是一个像素区域),我们看到情况如下面的右上图,入射点、反射点、次表面散射的出射点看起来是同一个点。其中反射部分(图中浅棕色出射光)就是我们常说的高光(Specular Light),常聚集在一个方向周围,向这个方向观察该点会看到明显的高光,从其他方向观察该点时高光则比较微弱;次表面散射部分(图中蓝色出射光)是漫射光(Diffuse Light),光线被散射到各个方向。双向反射分布函数BRDF就是用来模拟这种现象的,这也是本文关注的重点。&br&&/p&&p&如果光线在物质中的传播距离大于观察尺度,如下面的下图,就需要使用次表面散射算法来建模,&a href=&https://www.zhihu.com/people/d7b054c8339422dde6773& data-hash=&d7b054c8339422dde6773& class=&member_mention& data-editable=&true& data-title=&@文刀秋二& data-hovercard=&p$b$d7b054c8339422dde6773&&@文刀秋二&/a& 写了一篇很好的&a href=&https://zhuanlan.zhihu.com/p/?refer=graphics& class=&internal&&关于次表面散射的文章&/a&。&/p&&br&&figure&&img src=&https://pic3.zhimg.com/74f9aeff347dc1ec6f943a61f7d5ddee_b.jpg& data-rawwidth=&1500& data-rawheight=&815& class=&origin_image zh-lightbox-thumb& width=&1500& data-original=&https://pic3.zhimg.com/74f9aeff347dc1ec6f943a61f7d5ddee_r.jpg&&&/figure&&h2&光照模型&/h2&&p&为了模拟非光学平面的散射,人们建立了各种模型,大致可以分为以下几类:&/p&&p&&b&1. 测量模型&/b&&/p&&p&MERL等实验室使用仪器测量了上百种真实材质表面在不同光照角度和观察角度下的反射数据,并记录在&a href=&https://link.zhihu.com/?target=http%3A//www.merl.com/brdf/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&MERL BRDF Database&/a&等数据库中。这些数据由于采集自真实材质,所以使用它渲染出来的结果很真实,但缺点是没有可供调整效果的参数,无法基于这些数据修改成想要的效果,另外部分极端角度由于仪器限制,无法获取到数据,而且采样点密集,数据量非常庞大,所以并不适合游戏等实时领域,一般可用在电影等离线渲染领域,也可以用来做图形学研究,衡量其他模型的真实程度。&/p&&p&&b&2. 经验模型&/b&&/p&&p&经验模型并不是基于物理原理,而是提出经验公式,通过调整参数来模拟光照。&/p&&p&1975年Phong提出Phong反射模型(Phong Reflection Model) :&/p&&img src=&https://www.zhihu.com/equation?tex=I_%7BPhong%7D+%3D+k_a+I_a+%2B+k_d+%28n+%5Ccdot+l%29I_d+%2B+k_s+%28r+%5Ccdot+v%29%5E%7B%5Calpha+%7D+I_s& alt=&I_{Phong} = k_a I_a + k_d (n \cdot l)I_d + k_s (r \cdot v)^{\alpha } I_s& eeimg=&1&&&blockquote&其中下标&img src=&https://www.zhihu.com/equation?tex=a& alt=&a& eeimg=&1&&表示环境光(Ambient Light),下标&img src=&https://www.zhihu.com/equation?tex=d& alt=&d& eeimg=&1&&表示漫射光(Diffuse Light),下标&img src=&https://www.zhihu.com/equation?tex=s& alt=&s& eeimg=&1&&表示高光(Specular Light),&img src=&https://www.zhihu.com/equation?tex=k& alt=&k& eeimg=&1&&表示反射系数或者材质颜色,&img src=&https://www.zhihu.com/equation?tex=I& alt=&I& eeimg=&1&&表示光的颜色或者亮度,&img src=&https://www.zhihu.com/equation?tex=%5Calpha+& alt=&\alpha & eeimg=&1&&可以模拟表面粗糙程度,值越小越粗糙,越大越光滑。&br&反射向量&img src=&https://www.zhihu.com/equation?tex=r& alt=&r& eeimg=&1&&根据光线入射向量&img src=&https://www.zhihu.com/equation?tex=l& alt=&l& eeimg=&1&&相对法线&img src=&https://www.zhihu.com/equation?tex=n& alt=&n& eeimg=&1&&做反射得到:&img src=&https://www.zhihu.com/equation?tex=r+%3D+2+%28n+%5Ccdot+l%29+n+-+l& alt=&r = 2 (n \cdot l) n - l& eeimg=&1&&&/blockquote&&p&Phong模型中,漫射光和高光分别会根据入射方向&img src=&https://www.zhihu.com/equation?tex=L& alt=&L& eeimg=&1&&、反射方向&img src=&https://www.zhihu.com/equation?tex=R& alt=&R& eeimg=&1&&和观察方向&img src=&https://www.zhihu.com/equation?tex=V& alt=&V& eeimg=&1&&的变化而变化,还可以通过&img src=&https://www.zhihu.com/equation?tex=%5Calpha+& alt=&\alpha & eeimg=&1&&参数来调节表面粗糙程度,从而控制高光区域大小和锐利程度,而且运算简单,适合当时的计算机处理能力。&/p&&p&1977年Blinn对Phong模型做出修改,这就是后来广泛使用的Blinn-Phong反射模型:&br&&/p&&img src=&https://www.zhihu.com/equation?tex=I_%7BBlinn-Phong%7D+%3D+k_a+I_a+%2B+k_d+%28n+%5Ccdot+l%29I_d+%2B+k_s+%28n+%5Ccdot+h%29%5E%7B%5Calpha+%7D+I_s& alt=&I_{Blinn-Phong} = k_a I_a + k_d (n \cdot l)I_d + k_s (n \cdot h)^{\alpha } I_s& eeimg=&1&&&br&&blockquote&其中半角(Half-Angle)向量&img src=&https://www.zhihu.com/equation?tex=H& alt=&H& eeimg=&1&&是光线入射向量&img src=&https://www.zhihu.com/equation?tex=L& alt=&L& eeimg=&1&&和观察向量&img src=&https://www.zhihu.com/equation?tex=V& alt=&V& eeimg=&1&&的中间向量:&img src=&https://www.zhihu.com/equation?tex=h+%3D+%5Cfrac%7Bl+%2B+v%7D%7B%7C%7Cl+%2B+v%7C%7C%7D+& alt=&h = \frac{l + v}{||l + v||} & eeimg=&1&&&/blockquote&&p&Blinn-Phong相比Phong,在观察方向趋向平行于表面时,高光形状会拉长,更接近真实情况。&/p&&p&Blinn-Phong模型运算简单,适合早期硬件实现,在显卡只支持固定管线(Fixed Pipeline)的年代,Blinn-Phong模型是设计在显卡硬件中的,OpenGL/Direct3D固定管线的光照模型就是Blinn-Phong模型。但是Blinn-Phong模型毕竟只是一个经验模型,表现力有限,&u&&i&看起来有较重的塑料感&/i&&/u&(&b&此处有误&/b&,参见 &a href=&https://www.zhihu.com/people/0b21747b1fec79ad8af7e68a2b1ff681& data-hash=&0b21747b1fec79ad8af7e68a2b1ff681& class=&member_mention& data-editable=&true& data-title=&@叛逆者& data-hovercard=&p$b$0b21747b1fec79ad8af7e68a2b1ff681&&@叛逆者&/a& 的 &a href=&https://zhuanlan.zhihu.com/p/?refer=highwaytographics& class=&internal&&金属,塑料,傻傻分不清楚&/a&)。要想模拟各种不同材质的质感,得从光照的物理模型入手。&/p&&p&&b&3. 基于物理的分析模型&/b&&/p&&p&1967年Torrance-Sparrow在Theory for Off-Specular Reflection From Roughened Surfaces中使用辐射度学和微表面理论推导出粗糙表面的高光反射模型,1981年Cook-Torrance在A Reflectance Model for Computer Graphics中把这个模型引入到计算机图形学领域,现在无论是CG电影,还是3D游戏,基于物理着色都是使用的这个模型。我们将在下文中详细分析它的推导过程。&/p&&h2&辐射度学基本量&/h2&&p&图形学模拟可见光与各种材质的交互,这个过程涉及到能量的传输。辐射度学(Radiometry)是度量电磁辐射能量传输的学科,也是基于物理着色模型的基础。&/p&&p&我们看看常用的辐射度学的基本量。&/p&&br&&b&1. 能量&/b&&p&能量(Energy),用符号&img src=&https://www.zhihu.com/equation?tex=Q& alt=&Q& eeimg=&1&&表示,单位焦耳(&img src=&https://www.zhihu.com/equation?tex=J& alt=&J& eeimg=&1&&),每个光子都具有一定量的能量,和频率相关,频率越高,能量也越高。&br&&/p&&p&&b&2. 功率&/b&&/p&&p&功率(Power),单位瓦特(Watts),或者焦耳/秒(&img src=&https://www.zhihu.com/equation?tex=J%2Fs& alt=&J/s& eeimg=&1&&)。辐射度学中,辐射功率也被称为辐射通量(Radiant Flux)或者通量(Flux),指单位时间内通过表面或者空间区域的能量的总量,用符号&img src=&https://www.zhihu.com/equation?tex=%5CPhi+& alt=&\Phi & eeimg=&1&&表示,定义&img src=&https://www.zhihu.com/equation?tex=%5CPhi+%3D+%5Cfrac%7B+dQ%7D%7Bdt%7D& alt=&\Phi = \frac{ dQ}{dt}& eeimg=&1&&。&/p&&p&&b&3. 辐照度和辐出度&/b&&/p&&p&辐照度(Irradiance),指单位时间内到达单位面积的辐射能量,或到达单位面积的辐射通量,也就是通量对于面积的密度。用符号&img src=&https://www.zhihu.com/equation?tex=E& alt=&E& eeimg=&1&&表示,单位&img src=&https://www.zhihu.com/equation?tex=W+%2F+m%5E%7B2%7D+& alt=&W / m^{2} & eeimg=&1&&。定义为&img src=&https://www.zhihu.com/equation?tex=E+%3D+%5Cfrac%7Bd%5CPhi+%7D%7BdA%7D& alt=&E = \frac{d\Phi }{dA}& eeimg=&1&&。&/p&&p&辐出度(Radiant Existance),也称为辐射出射度、辐射度(Radiosity),用符号M表示。辐出度与辐照度类似,唯一的区别在辐出度衡量的是离开表面的通量密度,辐照度衡量的是到达表面的通量密度。辐照度和辐出度都可以称为辐射通量密度(Radiant Flux Density)。&/p&&p&处理通量密度时,我们需要注意表面朝向和光线方向的角度。如下图所示,当光线垂直表面照射时,照射到表面上时的间距为d;而当光线倾斜照射表面时(光照向量l和表面法线n的夹角为&img src=&https://www.zhihu.com/equation?tex=%5Ctheta_%7Bi%7D+& alt=&\theta_{i} & eeimg=&1&&),间距为&img src=&https://www.zhihu.com/equation?tex=d+%2F+cos+%5Ctheta_i& alt=&d / cos \theta_i& eeimg=&1&&,光线间距相对垂直照射时变大了,也就是说倾斜照射时通量密度降低了。光照角度影响通量密度在我们日常生活中有很多实际例子,地球的季节变化就是因为光照角度变化,导致通量密度发生了变化。&/p&&figure&&img src=&https://pic4.zhimg.com/749a01b706ea4b07f0d3dbaaccf84401_b.jpg& data-rawwidth=&1178& data-rawheight=&429& class=&origin_image zh-lightbox-thumb& width=&1178& data-original=&https://pic4.zhimg.com/749a01b706ea4b07f0d3dbaaccf84401_r.jpg&&&/figure&&p&假定不垂直于光线传输方向的表面面积为&img src=&https://www.zhihu.com/equation?tex=A& alt=&A& eeimg=&1&&,将它投影到垂直于光线方向得到一个虚拟表面,这个虚拟表面的面积为&img src=&https://www.zhihu.com/equation?tex=A%5E%7B%5Cbot%7D+%3D+A+cos+%5Ctheta_i& alt=&A^{\bot} = A cos \theta_i& eeimg=&1&&,通过这两个面积的通量是相同的,均为&img src=&https://www.zhihu.com/equation?tex=%5CPhi+& alt=&\Phi & eeimg=&1&&,则表面接收到的辐照度&img src=&https://www.zhihu.com/equation?tex=E+%3D+%5Cfrac%7B%5CPhi+%7D%7BA%7D& alt=&E = \frac{\Phi }{A}& eeimg=&1&&,虚拟表面上的辐照度&img src=&https://www.zhihu.com/equation?tex=E_L+%3D+%5Cfrac%7B%5CPhi+%7D%7BA%5E%7B%5Cbot%7D%7D++%3D+%5Cfrac%7B%5CPhi+%7D%7BA+cos+%5Ctheta+_i%7D& alt=&E_L = \frac{\Phi }{A^{\bot}}
= \frac{\Phi }{A cos \theta _i}& eeimg=&1&&,于是&img src=&https://www.zhihu.com/equation?tex=E+%3D+E_L+cos+%5Ctheta_i& alt=&E = E_L cos \theta_i& eeimg=&1&&。&br&&/p&&p&点光源向四周辐射能量,假想以点光源为中心不同半径的球包围着点光源,穿过这些球的辐射通量是相同的,均为&img src=&https://www.zhihu.com/equation?tex=%5CPhi+& alt=&\Phi & eeimg=&1&&,而球的表面积为&img src=&https://www.zhihu.com/equation?tex=4+%5Cpi+r%5E2& alt=&4 \pi r^2& eeimg=&1&&,可得通量密度&img src=&https://www.zhihu.com/equation?tex=E+%3D+%5Cfrac%7B%5CPhi+%7D%7B4+%5Cpi++r%5E%7B2%7D+%7D+& alt=&E = \frac{\Phi }{4 \pi
r^{2} } & eeimg=&1&&,也就是说通量密度与距离的平方成反比,离光源越远,通量密度越低,这也是为什么光的衰减与距离的平方成正比。&/p&&figure&&img src=&https://pic3.zhimg.com/2cbba08d13fbbb7e64674d7f_b.jpg& data-rawwidth=&1024& data-rawheight=&520& class=&origin_image zh-lightbox-thumb& width=&1024& data-original=&https://pic3.zhimg.com/2cbba08d13fbbb7e64674d7f_r.jpg&&&/figure&&p&&b&4. 辐射强度&/b&&/p&&p&讲辐射强度前,我们需要先知道立体角(Solid Angle)的概念,立体角可以看成是弧度的三维扩展。我们知道弧度是度量二维角度的量,等于角度在单位圆上对应的弧长,单位圆的周长是&img src=&https://www.zhihu.com/equation?tex=2%5Cpi+& alt=&2\pi & eeimg=&1&&,所以整个圆对应的弧度也是&img src=&https://www.zhihu.com/equation?tex=2%5Cpi+& alt=&2\pi & eeimg=&1&&。立体角则是度量三维角度的量,用符号&img src=&https://www.zhihu.com/equation?tex=%5Comega+& alt=&\omega & eeimg=&1&&表示,单位为立体弧度(也叫球面度,Steradian,简写为sr),等于立体角在单位球上对应的区域的面积(实际上也就是在任意半径的球上的面积除以半径的平方&img src=&https://www.zhihu.com/equation?tex=%5Comega+%3D+%5Cfrac%7Bs%7D%7Br%5E%7B2%7D+%7D+& alt=&\omega = \frac{s}{r^{2} } & eeimg=&1&&),单位球的表面积是&img src=&https://www.zhihu.com/equation?tex=4%5Cpi+& alt=&4\pi & eeimg=&1&&,所以整个球面的立体角也是&img src=&https://www.zhihu.com/equation?tex=4%5Cpi+& alt=&4\pi & eeimg=&1&&。&/p&&br&&p&我们可以用一个向量和一个立体角来表示一束光线,向量表示这束光线的指向,立体角表示这束光线投射在单位球上的面积,也就是光束的粗细。如下图左边,向量l表示光源方向,微分立体角&img src=&https://www.zhihu.com/equation?tex=d+%5Comega+_%7Bi%7D+& alt=&d \omega _{i} & eeimg=&1&&表示光束的粗细是无穷小。右边则表示面积光照到平面上的一点,立体角&img src=&https://www.zhihu.com/equation?tex=%5Comega+_%7BL%7D+& alt=&\omega _{L} & eeimg=&1&&不再是无穷小。&/p&&figure&&img src=&https://pic2.zhimg.com/a56ff2ccc6cf_b.jpg& data-rawwidth=&1300& data-rawheight=&500& class=&origin_image zh-lightbox-thumb& width=&1300& data-original=&https://pic2.zhimg.com/a56ff2ccc6cf_r.jpg&&&/figure&&p&辐射强度(Radiant Intensity),指通过单位立体角的辐射通量。用符号&img src=&https://www.zhihu.com/equation?tex=I& alt=&I& eeimg=&1&&表示,单位&img src=&https://www.zhihu.com/equation?tex=W+%2F+sr& alt=&W / sr& eeimg=&1&&,定义为&img src=&https://www.zhihu.com/equation?tex=I+%3D+%5Cfrac%7Bd+%5CPhi+%7D%7Bd+%5Comega+%7D+& alt=&I = \frac{d \Phi }{d \omega } & eeimg=&1&&。之所以引入辐射强度,是因为有时候要度量通过一个点的通量的密度,但因为点的面积是0,无法使用辐照度,所以引入辐射强度。辐射强度不会随距离变化而变化,不像点光源的辐照度会随距离增大而衰减,这是因为立体角不会随距离变化而变化。&/p&&p&&b&5. 辐射率&/b&&br&&/p&&p&我们常需要度量从一个微小面积表面出发,射向某个微小方向的通量(或者来自某个微小方向,照射到微小面积表面的通量),辐射率就是度量这种情况的量。&br&&/p&&p&辐射率(Radiance),指每单位面积每单位立体角的辐射通量密度。用符号&img src=&https://www.zhihu.com/equation?tex=L& alt=&L& eeimg=&1&&表示,单位&img src=&https://www.zhihu.com/equation?tex=W%2Fm%5E%7B2%7D+sr+& alt=&W/m^{2} sr & eeimg=&1&&,定义为&img src=&https://www.zhihu.com/equation?tex=L+%3D+%5Cfrac%7Bd+%5CPhi+%7D%7Bd%5Comega+d+A%5E%7B%5Cbot+%7D+%7D+& alt=&L = \frac{d \Phi }{d\omega d A^{\bot } } & eeimg=&1&&。其中&img src=&https://www.zhihu.com/equation?tex=dA%5E%7B%5Cbot%7D& alt=&dA^{\bot}& eeimg=&1&&是微分面积&img src=&https://www.zhihu.com/equation?tex=dA& alt=&dA& eeimg=&1&&在垂直于光线方向的投影,如下图所示。&/p&&figure&&img src=&https://pic4.zhimg.com/5ff8f88c297cb04e33c4_b.jpg& data-rawwidth=&1000& data-rawheight=&400& class=&origin_image zh-lightbox-thumb& width=&1000& data-original=&https://pic4.zhimg.com/5ff8f88c297cb04e33c4_r.jpg&&&/figure&&p&辐射率实际上可以看成是我们眼睛看到(或相机拍到)的物体上一点的颜色。在基于物理着色时,计算表面一点的颜色就是计算它的辐射率。&/p&&p&辐射率不会随距离变化而衰减,这和我们日常感受一致,在没有雾霾的干扰时,我们看到的物体表面上一点的颜色并不会随距离变化而变化。为什么辐照度会随距离增大而衰减,但是我们看到的颜色却不会衰减呢?这是因为随着距离变大,我们看到的物体上的一块区域到达视网膜的通量密度会变小,同时这块区域在视网膜表面上的立体角也会变小,正好抵消了通量密度的变化。&/p&&br&&h2&BRDF&/h2&&p&我们看到一个表面,实际上是周围环境的光照射到表面上,然后表面将一部分光反射到我们眼睛里。双向反射分布函数BRDF(Bidirectional Reflectance Distribution Function)就是描述表面入射光和反射光关系的。&br&&/p&&p&对于一个方向的入射光,表面会将光反射到表面上半球的各个方向,不同方向反射的比例是不同的,我们用BRDF来表示指定方向的反射光和入射光的比例关系,BRDF定义为:&/p&&img src=&https://www.zhihu.com/equation?tex=f%28l%2C+v%29+%3D+%5Cfrac%7Bd+L_%7Bo%7D+%28v%29+%7D%7Bd+E%28l%29%7D+& alt=&f(l, v) = \frac{d L_{o} (v) }{d E(l)} & eeimg=&1&&&br&&blockquote&其中&img src=&https://www.zhihu.com/equation?tex=f& alt=&f& eeimg=&1&&就是BRDF,&img src=&https://www.zhihu.com/equation?tex=l& alt=&l& eeimg=&1&&是入射光方向,&img src=&https://www.zhihu.com/equation?tex=v& alt=&v& eeimg=&1&&是观察方向,也就是我们关心的反射光方向。&br&&img src=&https://www.zhihu.com/equation?tex=d+L_o%28v%29& alt=&d L_o(v)& eeimg=&1&&是表面反射到&img src=&https://www.zhihu.com/equation?tex=v& alt=&v& eeimg=&1&&方向的反射光的微分辐射率。表面反射到&img src=&https://www.zhihu.com/equation?tex=v& alt=&v& eeimg=&1&&方向的反射光的辐射率为&img src=&https://www.zhihu.com/equation?tex=L_o%28v%29& alt=&L_o(v)& eeimg=&1&&,来自于表面上半球所有方向的入射光线的贡献,而微分辐射率&img src=&https://www.zhihu.com/equation?tex=d+L_o%28v%29& alt=&d L_o(v)& eeimg=&1&&特指来自方向&img src=&https://www.zhihu.com/equation?tex=l& alt=&l& eeimg=&1&&的入射光贡献的反射辐射率。&br&&img src=&https://www.zhihu.com/equation?tex=dE%28l%29& alt=&dE(l)& eeimg=&1&&是表面上来自入射光方向&img src=&https://www.zhihu.com/equation?tex=l& alt=&l& eeimg=&1&&的微分辐照度。表面接收到的辐照度为&img src=&https://www.zhihu.com/equation?tex=E& alt=&E& eeimg=&1&&,来自上半球所有方向的入射光线的贡献,而微分辐照度&img src=&https://www.zhihu.com/equation?tex=dE%28l%29& alt=&dE(l)& eeimg=&1&&特指来自于方向&img src=&https://www.zhihu.com/equation?tex=l& alt=&l& eeimg=&1&&的入射光。&/blockquote&&p&表面对不同频率的光反射率可能不一样,因此BRDF和光的频率有关。在图形学中,将BRDF表示为RGB向量,三个分量各有自己的&img src=&https://www.zhihu.com/equation?tex=f& alt=&f& eeimg=&1&&函数。&br&&/p&&p&BRDF需要处理表面上半球的各个方向,如下图使用&a href=&https://link.zhihu.com/?target=https%3A//en.wikipedia.org/wiki/Spherical_coordinate_system& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&球坐标系&/a&定义方向更加方便。球坐标系使用两个角度来确定一个方向:&/p&&ol&&li&方向相对法线的角度&img src=&https://www.zhihu.com/equation?tex=%5Ctheta+& alt=&\theta & eeimg=&1&&,称为极角(Polar Angle)或天顶角(Zenith Angle)&/li&&li&方向在平面上的投影相对于平面上一个坐标轴的角度&img src=&https://www.zhihu.com/equation?tex=%5Cphi+& alt=&\phi & eeimg=&1&&,称为方位角(Azimuthal Angle)&/li&&/ol&&br&所以BRDF也可以表示成&img src=&https://www.zhihu.com/equation?tex=f%28%5Ctheta_i%2C+%5Cphi_i%2C+%5Ctheta_o%2C+%5Cphi_o%29& alt=&f(\theta_i, \phi_i, \theta_o, \phi_o)& eeimg=&1&&。对于各向同性材质,当&img src=&https://www.zhihu.com/equation?tex=l& alt=&l& eeimg=&1&&和&img src=&https://www.zhihu.com/equation?tex=v& alt=&v& eeimg=&1&&同时绕法线&img src=&https://www.zhihu.com/equation?tex=n& alt=&n& eeimg=&1&&旋转时,&img src=&https://www.zhihu.com/equation?tex=f& alt=&f& eeimg=&1&&值保持不变,此时可以用&img src=&https://www.zhihu.com/equation?tex=l& alt=&l& eeimg=&1&&和&img src=&https://www.zhihu.com/equation?tex=v& alt=&v& eeimg=&1&&在平面投影的夹角&img src=&https://www.zhihu.com/equation?tex=%5Cphi+& alt=&\phi & eeimg=&1&&来代替&img src=&https://www.zhihu.com/equation?tex=%5Cphi+_i& alt=&\phi _i& eeimg=&1&&和&img src=&https://www.zhihu.com/equation?tex=%5Cphi+_o& alt=&\phi _o& eeimg=&1&&:&img src=&https://www.zhihu.com/equation?tex=f%28%5Ctheta_i%2C+%5Ctheta_o%2C+%5Cphi%29& alt=&f(\theta_i, \theta_o, \phi)& eeimg=&1&&。&figure&&img src=&https://pic3.zhimg.com/a65ae4967cfab6e5a8fff7ba3e9824ed_b.jpg& data-rawwidth=&840& data-rawheight=&422& class=&origin_image zh-lightbox-thumb& width=&840& data-original=&https://pic3.zhimg.com/a65ae4967cfab6e5a8fff7ba3e9824ed_r.jpg&&&/figure&&p&至于&b&为什么BRDF要定义成辐射率和辐照度的比值,而不是直接定义为辐射率和辐射率比值&/b&,有两种解释。&br&&/p&&p&&i&&b&第一种解释&/b&&/i&可以参看&a href=&https://www.zhihu.com/question//answer/& class=&internal&&brdf为什么要定义为一个单位是sr-1的量?&/a&&/p&&p&我们结合下面辐照度(A)和辐射率(B)测量仪的示意图来看看。辐照度测量仪(A)接受平面上半球的所有光线,可以测量一个较小面积来自于四面八方的所有光通量,光通量&img src=&https://www.zhihu.com/equation?tex=%5CPhi+& alt=&\Phi & eeimg=&1&&除以传感器面积&img src=&https://www.zhihu.com/equation?tex=A& alt=&A& eeimg=&1&&就可以得到辐照度&img src=&https://www.zhihu.com/equation?tex=E& alt=&E& eeimg=&1&&。辐射度测量仪(B)则有一个长筒控制光线只能从一个很小的立体角进入测量仪,光通量&img src=&https://www.zhihu.com/equation?tex=%5CPhi+& alt=&\Phi & eeimg=&1&&除以传感器面积&img src=&https://www.zhihu.com/equation?tex=A& alt=&A& eeimg=&1&&和立体角&img src=&https://www.zhihu.com/equation?tex=%5Comega+& alt=&\omega & eeimg=&1&&就可以得到辐射率&img src=&https://www.zhihu.com/equation?tex=L& alt=&L& eeimg=&1&&。&/p&&p&测平面上一点在某一个方向的出射辐射率很简单,只需要用仪器(B)从该方向对准该点就可以了。而测平面一点入射的辐射率则没有那么简单,必须保证光源正好覆盖测量仪开口立体角,大了该点会接受到比测量值更多的光照,导致测量值比实际值小,小了则与仪器的设计立体角不一致,可在实际中是基本做不到光源大小正好覆盖测量仪开口立体角的。而测表面的辐照度则简单得多,只要保证光源很小,而且没有来自其他方向的光干扰,这时候测到的辐照度就是平面上来自光源方向的微分辐照度&img src=&https://www.zhihu.com/equation?tex=dE& alt=&dE& eeimg=&1&&。&/p&&figure&&img src=&https://pic2.zhimg.com/77aa9a3b93bbf4d46625_b.jpg& data-rawwidth=&600& data-rawheight=&346& class=&origin_image zh-lightbox-thumb& width=&600& data-original=&https://pic2.zhimg.com/77aa9a3b93bbf4d46625_r.jpg&&&/figure&&p&&b&&i&第二种&/i&&i&解释&/i&&/b&从数学的角度出发,对于现实世界中的非光学平面,一束光线射到表面上后,被表面反射到各个方向,其中一个出射方向的光通量只是整个反射光通量极小的一部分,当出射方向立体角趋于0时,&img src=&https://www.zhihu.com/equation?tex=%5Clim_%7B%5Comega+_%7Bo%7D+++%5Crightarrow+0%7D%7B%5Cfrac%7BdL_%7Bo%7D+%7D%7BLi%7D+%7D+%3D+0& alt=&\lim_{\omega _{o}
\rightarrow 0}{\frac{dL_{o} }{Li} } = 0& eeimg=&1&&,所以在实际计算中使用辐射率和辐射率比值是没有意义的。而如果分母改成表面上接收到的来自光源方向的微分辐照度,我们知道&img src=&https://www.zhihu.com/equation?tex=dE+%3D+L_i%28l%29+d%5Comega+_%7Bi%7D+cos+%5Ctheta+_%7Bi%7D+& alt=&dE = L_i(l) d\omega _{i} cos \theta _{i} & eeimg=&1&&,由于给入射辐射率乘了一个趋于零的微分立体角,&img src=&https://www.zhihu.com/equation?tex=dE& alt=&dE& eeimg=&1&&的值会小很多,比值&img src=&https://www.zhihu.com/equation?tex=%5Cfrac%7BdL_o%7D%7BdE%7D+& alt=&\frac{dL_o}{dE} & eeimg=&1&&是有意义的,而不是0。&/p&&p&下面我们来看看&b&怎么用BRDF来计算表面辐射率&/b&。&/p&&p&我们考虑来自方向&img src=&https://www.zhihu.com/equation?tex=l& alt=&l& eeimg=&1&&的入射光辐射率&img src=&https://www.zhihu.com/equation?tex=L_i%28l%29& alt=&L_i(l)& eeimg=&1&&,由辐射率和辐照度的定义:&/p&&img src=&https://www.zhihu.com/equation?tex=L_i%28l%29+%3D+%5Cfrac%7Bd+%5CPhi+%7D%7Bd%5Comega_i+d+A%5E%7B%5Cbot+%7D+%7D++%3D++%5Cfrac%7Bd+%5CPhi+%7D%7Bd%5Comega_i+dA+cos+%5Ctheta_i+%7D+%3D+%5Cfrac%7BdE%28l%29+%7D%7Bd%5Comega_i+cos+%5Ctheta_i+%7D& alt=&L_i(l) = \frac{d \Phi }{d\omega_i d A^{\bot } }
\frac{d \Phi }{d\omega_i dA cos \theta_i } = \frac{dE(l) }{d\omega_i cos \theta_i }& eeimg=&1&&&br&&p&则照射到表面来自于方向&img src=&https://www.zhihu.com/equation?tex=l& alt=&l& eeimg=&1&&的入射光贡献的微分辐照度:&/p&&img src=&https://www.zhihu.com/equation?tex=dE%28l%29+%3D+L_i%28l%29+d%5Comega_i+cos+%5Ctheta_i& alt=&dE(l) = L_i(l) d\omega_i cos \theta_i& eeimg=&1&&&p&表面反射到&img src=&https://www.zhihu.com/equation?tex=v& alt=&v& eeimg=&1&&方向的由来自于方向&img src=&https://www.zhihu.com/equation?tex=l& alt=&l& eeimg=&1&&的入射光贡献的微分辐射率:&/p&&img src=&https://www.zhihu.com/equation?tex=dL_o%28v%29+%3D+f%28l%2C+v%29+%5Cotimes++dE%28l%29+%3D+f%28l%2C+v%29+%5Cotimes+L_i%28l%29+d%5Comega_i+cos+%5Ctheta_i& alt=&dL_o(v) = f(l, v) \otimes
dE(l) = f(l, v) \otimes L_i(l) d\omega_i cos \theta_i& eeimg=&1&&&br&&blockquote&符号&img src=&https://www.zhihu.com/equation?tex=%5Cotimes+& alt=&\otimes & eeimg=&1&&表示按向量的分量相乘,因为&img src=&https://www.zhihu.com/equation?tex=f& alt=&f& eeimg=&1&&和&img src=&https://www.zhihu.com/equation?tex=L_i& alt=&L_i& eeimg=&1&&都包含RGB三个分量。&/blockquote&&p&要计算表面反射到&img src=&https://www.zhihu.com/equation?tex=v& alt=&v& eeimg=&1&&方向的来自上半球所有方向入射光线贡献的辐射率,可以将上式对半球所有方向的光线积分:&/p&&img src=&https://www.zhihu.com/equation?tex=L_o%28v%29+%3D+%5Cint_%7B%5COmega+%7D%5E%7B%7D+f%28l%2C+v%29+%5Cotimes+L_i%28l%29+cos+%5Ctheta_i+d%5Comega_i& alt=&L_o(v) = \int_{\Omega }^{} f(l, v) \otimes L_i(l) cos \theta_i d\omega_i& eeimg=&1&&&br&&p&上式称为&b&反射方程(Reflectance Equation)&/b&,用来计算表面反射辐射率。&/p&&p&&b&对于点光源、方向光等理想化的精准光源(Punctual Light)&/b&,计算过程可以大大简化。我们考察单个精准光源照射表面,此时表面上的一点只会被来自一个方向的一条光线照射到(而面积光源照射表面时,表面上一点会被来自多个方向的多条光线照射到),则辐射率:&br&&/p&&img src=&https://www.zhihu.com/equation?tex=L_o%28v%29+%3D+f%28l%2C+v%29+%5Cotimes+E_L+cos+%5Ctheta_i& alt=&L_o(v) = f(l, v) \otimes E_L cos \theta_i& eeimg=&1&&&br&&p&对于多个精准光源,只需简单累加就可以了:&/p&&img src=&https://www.zhihu.com/equation?tex=L_o%28v%29+%3D+%5Csum_%7Bk+%3D+1%7D%5E%7Bn%7D%7Bf%28l_k%2C+v%29+%5Cotimes+E_%7BL_k%7D+cos+%5Ctheta_%7Bi_k%7D%7D+& alt=&L_o(v) = \sum_{k = 1}^{n}{f(l_k, v) \otimes E_{L_k} cos \theta_{i_k}} & eeimg=&1&&&p&这里使用光源的辐照度,对于阳光等全局方向光,可以认为整个场景的辐照度是一个常数,对于点光源,辐照度随距离的平方衰减,用公式&img src=&https://www.zhihu.com/equation?tex=E_%7BL%7D+%3D+%5Cfrac%7B%5CPhi+%7D%7B4%5Cpi+r%5E2%7D+& alt=&E_{L} = \frac{\Phi }{4\pi r^2} & eeimg=&1&&就可以求出到达表面的辐照度,&img src=&https://www.zhihu.com/equation?tex=%5CPhi+& alt=&\Phi & eeimg=&1&&是光源的功率,比如100瓦的灯泡,&img src=&https://www.zhihu.com/equation?tex=r& alt=&r& eeimg=&1&&是表面离光源的距离。&/p&&p&回头看看反射方程,是对表面上半球所有方向的入射光线积分,这里面包含了来自精准光源的光线,也包括周围环境反射的光线。处理来自周围环境的光线可以大幅提高光照的真实程度,在实时图形学中,这部分光照可以用&b&基于图像的光照(Image Based Lighting)&/b&来模拟。我们将在下篇文章讨论基于图像的光照。 &/p&&p&上面给出了BRDF的定义和使用BRDF计算表面反射辐射率的公式。但这个定义实际上是无法直接用于计算表面反射辐射率的,我们还要建立一个能模拟真实光照的模型,使得输入入射方向和出射方向,&img src=&https://www.zhihu.com/equation?tex=f%28l%2C+v%29& alt=&f(l, v)& eeimg=&1&&能输出表面反射微分辐射率和入射微分辐照度的比率。&/p&&p&1967年Torrance-Sparrow在Theory for Off-Specular Reflection From Roughened Surfaces中使用辐射度学和微表面理论建立了模拟真实光照的BRDF模型,1981年Cook-Torrance在A Reflectance Model for Computer Graphics中把这个模型引入到计算机图形学领域,现在这个模型已经成为基于物理着色的标准,被称为Cook-Torrance模型。下面我们来看看微表面理论和Cook-Torrance模型的推导过程。&br&&/p&&h2&微表面理论&/h2&微表面理论(Microfacet Theory)认为我们看到的表面上的一点是由很多朝向各异且光学平的微小表面组成。当光线从&img src=&https://www.zhihu.com/equation?tex=l& alt=&l& eeimg=&1&&方向照射到这点,而我们在&img src=&https://www.zhihu.com/equation?tex=v& alt=&v& eeimg=&1&&方向观察时,由于光学平面只会将光线&img src=&https://www.zhihu.com/equation?tex=l& alt=&l& eeimg=&1&&反射到关于法线对称的&img src=&https://www.zhihu.com/equation?tex=v& alt=&v& eeimg=&1&&方向,而&img src=&https://www.zhihu.com/equation?tex=l& alt=&l& eeimg=&1&&和&img src=&https://www.zhihu.com/equation?tex=v& alt=&v& eeimg=&1&&已经确定,所以只有法线朝向正好是&img src=&https://www.zhihu.com/equation?tex=l& alt=&l& eeimg=&1&&和&img src=&https://www.zhihu.com/equation?tex=v& alt=&v& eeimg=&1&&的半角向量&img src=&https://www.zhihu.com/equation?tex=h& alt=&h& eeimg=&1&&的微表面才会将光线发射到&img src=&https://www.zhihu.com/equation?tex=v& alt=&v& eeimg=&1&&方向(如下图),从而被我们看见。&figure&&img src=&https://pic2.zhimg.com/85ef46cc9b_b.jpg& data-rawwidth=&1500& data-rawheight=&459& class=&origin_image zh-lightbox-thumb& width=&1500& data-original=&https://pic2.zhimg.com/85ef46cc9b_r.jpg&&&/figure&&p&我们用&b&法线分布函数(Normal Distribution Function,简写为NDF)&img src=&https://www.zhihu.com/equation?tex=D%28h%29& alt=&D(h)& eeimg=&1&&&/b&来描述组成表面一点的所有微表面的法线分布概率,现在可以这样理解:向NDF输入一个朝向&img src=&https://www.zhihu.com/equation?tex=h& alt=&h& eeimg=&1&&,NDF会返回朝向是&img src=&https://www.zhihu.com/equation?tex=h& alt=&h& eeimg=&1&&的微表面数占微表面总数的比例(虽然实际并不是这样,这点我们在讲推导过程的时候再讲),比如有1%的微表面朝向是&img src=&https://www.zhihu.com/equation?tex=h& alt=&h& eeimg=&1&&,那么就有1%的微表面可能将光线反射到&img src=&https://www.zhihu.com/equation?tex=v& alt=&v& eeimg=&1&&方向。&/p&&p&但实际上并不是所有微表面都能收到接受到光线,如下面左边的图有一部分入射光线被遮挡住,这种现象称为Shadowing。也不是所有反射光线都能到达眼睛,下面中间的图,一部分反射光线被遮挡住了,这种现象称为Masking。光线在微表面之间还会互相反射,如下面右边的图,这可能也是一部分漫射光的来源,在建模高光时忽略掉这部分光线。&/p&&p&&figure&&img src=&https://pic4.zhimg.com/bf148adcdb7_b.jpg& data-rawwidth=&1483& data-rawheight=&354& class=&origin_image zh-lightbox-thumb& width=&1483& data-original=&https://pic4.zhimg.com/bf148adcdb7_r.jpg&&&/figure&Shadowing和Masking用&b&几何衰减因子(Geometrical Attenuation Factor)&/b&&img src=&https://www.zhihu.com/equation?tex=G%28l%2C+v%29& alt=&G(l, v)& eeimg=&1&&来建模,输入入射和出射光线方向,输出值表示光线未被遮蔽而能从&img src=&https://www.zhihu.com/equation?tex=l& alt=&l& eeimg=&1&&反射到&img src=&https://www.zhihu.com/equation?tex=v& alt=&v& eeimg=&1&&方向的比例。&br&&/p&&p&光学平面并不会将所有光线都反射掉,而是一部分被反射,一部分被折射,反射比例符合&b&菲涅尔方程(Fresnel Equations)&/b&&img src=&https://www.zhihu.com/equation?tex=F%28l%2C+h%29& alt=&F(l, h)& eeimg=&1&&。&br&&/p&&p&Torrance-Sparrow基于微表面理论,用上述三个函数建立了高光BRDF模型:&br&&/p&&img src=&https://www.zhihu.com/equation?tex=f%28l%2C+v%29+%3D+%5Cfrac%7BF%28l%2C+h%29+G%28l%2C+v%29+D%28h%29%7D%7B4+cos+%5Ctheta_i+cos+%5Ctheta_o%7D++%3D+%5Cfrac%7BF%28l%2C+h%29+G%28l%2C+v%29+D%28h%29%7D%7B4+%28n+%5Ccdot+l%29+%28n+%5Ccdot+v%29%7D+& alt=&f(l, v) = \frac{F(l, h) G(l, v) D(h)}{4 cos \theta_i cos \theta_o}
= \frac{F(l, h) G(l, v) D(h)}{4 (n \cdot l) (n \cdot v)} & eeimg=&1&&&br&&blockquote&其中&img src=&https://www.zhihu.com/equation?tex=n& alt=&n& eeimg=&1&&是宏观表面法线,&img src=&https://www.zhihu.com/equation?tex=h& alt=&h& eeimg=&1&&是微表面法线&/blockquote&&p&这个模型后来由Cook-Torrance引入计算机图形学,也被称为Cook-Torrance模型。不过Cook-Torrance的论文里上式分母里的系数由4改成了&img src=&https://www.zhihu.com/equation?tex=%5Cpi+& alt=&\pi & eeimg=&1&&,但现在大家公认应该用4,下面我们来看看这个公式的推导过程。&/p&&h2&Cook-Torrance模型公式推导&/h2&&p&我们考察一束光照射到一组微表面上,入射光方向&img src=&https://www.zhihu.com/equation?tex=%5Comega+_i& alt=&\omega _i& eeimg=&1&&,观察方向&img src=&https://www.zhihu.com/equation?tex=%5Comega+_o& alt=&\omega _o& eeimg=&1&&,对反射到&img src=&https://www.zhihu.com/equation?tex=%5Comega+_o& alt=&\omega _o& eeimg=&1&&方向的反射光有贡献的微表面法线为半角向量&img src=&https://www.zhihu.com/equation?tex=%5Comega+_h& alt=&\omega _h& eeimg=&1&&,则这束光的微分通量&br&&/p&&img src=&https://www.zhihu.com/equation?tex=d+%5CPhi_h+%3D+L_i%28%5Comega_i%29+d+%5Comega_i+dA%5E%7B%5Cbot%7D%28%5Comega_h%29++%3D++L_i%28%5Comega_i%29+d+%5Comega_i+cos+%5Ctheta_h+dA%28%5Comega_h%29+& alt=&d \Phi_h = L_i(\omega_i) d \omega_i dA^{\bot}(\omega_h)
L_i(\omega_i) d \omega_i cos \theta_h dA(\omega_h) & eeimg=&1&&&blockquote&其中&img src=&https://www.zhihu.com/equation?tex=dA%28%5Comega_h%29& alt=&dA(\omega_h)& eeimg=&1&&是法线为半角向量&img src=&https://www.zhihu.com/equation?tex=%5Comega_h& alt=&\omega_h& eeimg=&1&&的微分微表面面积,&img src=&https://www.zhihu.com/equation?tex=dA%5E%7B%5Cbot%7D%28%5Comega_h%29& alt=&dA^{\bot}(\omega_h)& eeimg=&1&&为&img src=&https://www.zhihu.com/equation?tex=dA%28%5Comega_h%29& alt=&dA(\omega_h)& eeimg=&1&&在入射光线方向的投影,&img src=&https://www.zhihu.com/equation?tex=%5Ctheta_h& alt=&\theta_h& eeimg=&1&&为入射光线&img src=&https://www.zhihu.com/equation?tex=%5Comega_i& alt=&\omega_i& eeimg=&1&&和微表面法线&img src=&https://www.zhihu.com/equation?tex=%5Comega_h& alt=&\omega_h& eeimg=&1&&的夹角&/blockquote&Torrance-Sparrow将微分微表面面积&img src=&https://www.zhihu.com/equation?tex=dA%28%5Comega_h%29& alt=&dA(\omega_h)& eeimg=&1&&定义为&img src=&https://www.zhihu.com/equation?tex=dA%28%5Comega_h%29+%3D+D%28%5Comega_h%29+d+%5Comega_h+dA& alt=&dA(\omega_h) = D(\omega_h) d \omega_h dA& eeimg=&1&&&br&&p&Torrance-Sparrow将前两项解释为单位面积微表面中朝向为&img src=&https://www.zhihu.com/equation?tex=%5Comega_h& alt=&\omega_h& eeimg=&1&&的微分面积。不过这里塞一个&img src=&https://www.zhihu.com/equation?tex=d+%5Comega_h& alt=&d \omega_h& eeimg=&1&&略诡异,我的理解乘以&img src=&https://www.zhihu.com/equation?tex=d+%5Comega_h& alt=&d \omega_h& eeimg=&1&&并没有明确的数学或者物理上的意义。要从一组微表面面积&img src=&https://www.zhihu.com/equation?tex=dA& alt=&dA& eeimg=&1&&中得到朝向为&img src=&https://www.zhihu.com/equation?tex=%5Comega_h& alt=&\omega_h& eeimg=&1&&的微表面面积&img src=&https://www.zhihu.com/equation?tex=dA%28%5Comega_h%29& alt=&dA(\omega_h)& eeimg=&1&&,只需要将&img src=&https://www.zhihu.com/equation?tex=D%28%5Comega_h%29& alt=&D(\omega_h)& eeimg=&1&&定义为&img src=&https://www.zhihu.com/equation?tex=dA& alt=&dA& eeimg=&1&&中朝向为&img src=&https://www.zhihu.com/equation?tex=%5Comega_h& alt=&\omega_h& eeimg=&1&&的比例,取值范围在[0, 1]就可以了。这里引入&img src=&https://www.zhihu.com/equation?tex=d+%5Comega_h& alt=&d \omega_h& eeimg=&1&&的实际用途我们稍后再讨论。&/p&&p&由上两式可得&/p&&img src=&https://www.zhihu.com/equation?tex=d+%5CPhi_h+%3D++L_i%28%5Comega_i%29+d+%5Comega_i+cos+%5Ctheta_h+D%28%5Comega_h%29+d+%5Comega_h+dA& alt=&d \Phi_h =
L_i(\omega_i) d \omega_i cos \theta_h D(\omega_h) d \omega_h dA& eeimg=&1&&&br&&p&设定微表面反射光线遵循菲涅尔定理,则反射通量&/p&&img src=&https://www.zhihu.com/equation?tex=d+%5CPhi_o+%3D+F_r%28%5Comega_o%29+d+%5CPhi_h& alt=&d \Phi_o = F_r(\omega_o) d \Phi_h& eeimg=&1&&&br&&p&由上两式可得反射辐射率&/p&&img src=&https://www.zhihu.com/equation?tex=dL_o%28%5Comega_o%29+%3D+%5Cfrac%7Bd+%5CPhi_o%7D%7Bd+%5Comega_o+cos+%5Ctheta_o+dA%7D+%3D+%5Cfrac%7BF_r%28%5Comega_o%29+L_i%28%5Comega_i%29+d+%5Comega_i+cos+%5Ctheta_h+D%28%5Comega_h%29+d+%5Comega_h+dA%7D%7Bd+%5Comega_o+cos+%5Ctheta_o+dA%7D& alt=&dL_o(\omega_o) = \frac{d \Phi_o}{d \omega_o cos \theta_o dA} = \frac{F_r(\omega_o) L_i(\omega_i) d \omega_i cos \theta_h D(\omega_h) d \omega_h dA}{d \omega_o cos \theta_o dA}& eeimg=&1&&&p&由BRDF的定义可得&/p&&img src=&https://www.zhihu.com/equation?tex=f_r%28%5Comega_i%2C+%5Comega_o%29+%3D+%5Cfrac%7Bd+L_o%28%5Comega_o%29%7D%7Bd+E_i%28%5Comega_i%29%7D+%3D+%5Cfrac%7Bd+L_o%28%5Comega_o%29%7D%7BL_i%28%5Comega_i%29+cos+%5Ctheta_i+d+%5Comega_i%7D+%3D+%5Cfrac%7BF_r%28%5Comega_o%29+cos+%5Ctheta_h+D%28%5Comega_h%29+d+%5Comega_h%7D%7Bcos+%5Ctheta_o+cos+%5Ctheta_i+d+%5Comega_o%7D& alt=&f_r(\omega_i, \omega_o) = \frac{d L_o(\omega_o)}{d E_i(\omega_i)} = \frac{d L_o(\omega_o)}{L_i(\omega_i) cos \theta_i d \omega_i} = \frac{F_r(\omega_o) cos \theta_h D(\omega_h) d \omega_h}{cos \theta_o cos \theta_i d \omega_o}& eeimg=&1&&&blockquote&这里需要特别强调几个夹角:&br&&img src=&https://www.zhihu.com/equation?tex=%5Ctheta_h& alt=&\theta_h& eeimg=&1&&是入射光线&img src=&https://www.zhihu.com/equation?tex=%5Comega_i& alt=&\omega_i& eeimg=&1&&与朝向为&img src=&https://www.zhihu.com/equation?tex=%5Comega_h& alt=&\omega_h& eeimg=&1&&的微表面法线的夹角&br&&img src=&https://www.zhihu.com/equation?tex=%5Ctheta_i& alt=&\theta_i& eeimg=&1&&是入射光线&img src=&https://www.zhihu.com/equation?tex=%5Comega_i& alt=&\omega_i& eeimg=&1&&与宏观表面法线的夹角&br&&img src=&https://www.zhihu.com/equation?tex=%5Ctheta_o& alt=&\theta_o& eeimg=&1&&是反射光线&img src=&https://www.zhihu.com/equation?tex=%5Comega_o& alt=&\omega_o& eeimg=&1&&与宏观表面法线的夹角&/blockquote&&p&回头看反射方程&img src=&https://www.zhihu.com/equation?tex=L_o%28v%29+%3D+%5Cint_%7B%5COmega+%7D%5E%7B%7D+f%28l%2C+v%29+%5Cotimes+L_i%28l%29+cos+%5Ctheta_i+d%5Comega_i& alt=&L_o(v) = \int_{\Omega }^{} f(l, v) \otimes L_i(l) cos \theta_i d\omega_i& eeimg=&1&&是对&img src=&https://www.zhihu.com/equation?tex=d+%5Comega_i& alt=&d \omega_i& eeimg=&1&&积分,而上式分母包含&img src=&https://www.zhihu.com/equation?tex=d+%5Comega_o& alt=&d \omega_o& eeimg=&1&&,需要想办法把&img src=&https://www.zhihu.com/equation?tex=d+%5Comega_o& alt=&d \omega_o& eeimg=&1&&消掉,我估计这也是为什么Torrance-Sparrow在&img src=&https://www.zhihu.com/equation?tex=dA%28%5Comega_h%29+%3D+D%28%5Comega_h%29+d+%5Comega_h+dA& alt=&dA(\omega_h) = D(\omega_h) d \omega_h dA& eeimg=&1&&中塞一个&img src=&https://www.zhihu.com/equation?tex=d+%5Comega_h& alt=&d \omega_h& eeimg=&1&&,:可以通过找到&img src=&https://www.zhihu.com/equation?tex=%5Cfrac%7Bd+%5Comega_h%7D%7Bd+%5Comega_o%7D+& alt=&\frac{d \omega_h}{d \omega_o} & eeimg=&1&&的关系,把&img src=&https://www.zhihu.com/equation?tex=d+%5Comega_o& alt=&d \omega_o& eeimg=&1&&消掉。塞入&img src=&https://www.zhihu.com/equation?tex=d+%5Comega_h& alt=&d \omega_h& eeimg=&1&&并不会影响方程的合理性,因为&img src=&https://www.zhihu.com/equation?tex=D%28%5Comega_h%29& alt=&D(\omega_h)& eeimg=&1&&是可以调整的,现在&img src=&https://www.zhihu.com/equation?tex=D%28%5Comega_h%29& alt=&D(\omega_h)& eeimg=&1&&是一个有单位的量,单位为&img src=&https://www.zhihu.com/equation?tex=1%2Fsr& alt=&1/sr& eeimg=&1&&。&/p&&br&&p&Physically Based Rendering, Second Edition里关于&img src=&https://www.zhihu.com/equation?tex=d+%5Comega_h& alt=&d \omega_h& eeimg=&1&&和&img src=&https://www.zhihu.com/equation?tex=d+%5Comega_o& alt=&d \omega_o& eeimg=&1&&关系的推导(在14.5.1节)预设了一个前提:&img src=&https://www.zhihu.com/equation?tex=%5Ctheta_i+%3D+2+%5Ctheta_h& alt=&\theta_i = 2 \theta_h& eeimg=&1&&,可这会导致&img src=&https://www.zhihu.com/equation?tex=%5Ctheta_i& alt=&\theta_i& eeimg=&1&&和&img src=&https://www.zhihu.com/equation?tex=%5Ctheta_h& alt=&\theta_h& eeimg=&1&&的定义和前面推导过程中的定义不一致。而Torrance-Sparrow论文里&img src=&https://www.zhihu.com/equation?tex=d+%5Comega_o& alt=&d \omega_o& eeimg=&1&&和&img src=&https://www.zhihu.com/equation?tex=d+%5Comega_h& alt=&d \omega_h& eeimg=&1&&的关系直接引用自一篇付费论文,没有推导。&/p&&p&不过Surface Reflection: Physical and Geometrical Perspectives给出了一个直观的非正式推导,An Illumination Model for a Skin Layer Bounded by Rough Surfaces附录B给出了详细的数学计算过程。我们来看看前者。&/p&&br&&figure&&img src=&https://pic4.zhimg.com/bc2fd1ebc6678_b.jpg& data-rawwidth=&1500& data-rawheight=&820& class=&origin_image zh-lightbox-thumb& width=&1500& data-original=&https://pic4.zhimg.com/bc2fd1ebc6678_r.jpg&&&/figure&&p&如上图,入射光线照射到一个微表面上,与微表面的单位上半球相交于点&img src=&https://www.zhihu.com/equation?tex=I& alt=&I& eeimg=&1&&,与微表面相交于点&img src=&https://www.zhihu.com/equation?tex=O& alt=&O& eeimg=&1&&,反射光线与单位上半球相交于点&img src=&https://www.zhihu.com/equation?tex=R& alt=&R& eeimg=&1&&,反射光束立体角&img src=&https://www.zhihu.com/equation?tex=d+%5Comega_o& alt=&d \omega_o& eeimg=&1&&(图中是&img src=&https://www.zhihu.com/equation?tex=d+%5Comega_r& alt=&d \omega_r& eeimg=&1&&)等于光束与单位上半球相交区域面积&img src=&https://www.zhihu.com/equation?tex=dA_r& alt=&dA_r& eeimg=&1&&,法线立体角&img src=&https://www.zhihu.com/equation?tex=d+%5Comega_h& alt=&d \omega_h& eeimg=&1&&(图中是&img src=&https://www.zhihu.com/equation?tex=d+%5Comega%5E%5Cprime& alt=&d \omega^\prime& eeimg=&1&&)等于法线立体角与单位上半球相交区域面积&img src=&https://www.zhihu.com/equation?tex=dA%5E%5Cprime& alt=&dA^\prime& eeimg=&1&&,因此求&img src=&https://www.zhihu.com/equation?tex=%5Cfrac%7Bd+%5Comega_h%7D%7Bd+%5Comega_o%7D+& alt=&\frac{d \omega_h}{d \omega_o} & eeimg=&1&&等价于求&img src=&https://www.zhihu.com/equation?tex=%5Cfrac%7BdA%5E%5Cprime%7D%7BdA_r%7D& alt=&\frac{dA^\prime}{dA_r}& eeimg=&1&&。 &/p&&p&连线&img src=&https://www.zhihu.com/equation?tex=IR& alt=&IR& eeimg=&1&&与法线&img src=&https://www.zhihu.com/equation?tex=n%5E%5Cprime+& alt=&n^\prime & eeimg=&1&&相交于点&img src=&https://www.zhihu.com/equation?tex=P& alt=&P& eeimg=&1&&,则&img src=&https://www.zhihu.com/equation?tex=IR+%3D+2IP& alt=&IR = 2IP& eeimg=&1&&,由于&img src=&https://www.zhihu.com/equation?tex=dA_r& alt=&dA_r& eeimg=&1&&与&img src=&https://www.zhihu.com/equation?tex=dA%5E%7B%5Cprime+%5Cprime+%5Cprime%7D& alt=&dA^{\prime \prime \prime}& eeimg=&1&&半径的比值等于&img src=&https://www.zhihu.com/equation?tex=%5Cfrac%7BIR%7D%7BIP%7D& alt=&\frac{IR}{IP}& eeimg=&1&&,而面积为&img src=&https://www.zhihu.com/equation?tex=%5Cpi+r%5E2& alt=&\pi r^2& eeimg=&1&&,与半径的平方成正比,所以&img src=&https://www.zhihu.com/equation?tex=dA_r+%3D+4+dA%5E%7B%5Cprime+%5Cprime+%5Cprime%7D& alt=&dA_r = 4 dA^{\prime \prime \prime}& eeimg=&1&&&/p&&p&连线&img src=&https://www.zhihu.com/equation?tex=OQ& alt=&OQ& eeimg=&1&&长度为1,&img src=&https://www.zhihu.com/equation?tex=OP& alt=&OP& eeimg=&1&&长度为&img src=&https://www.zhihu.com/equation?tex=cos+%5Ctheta_i+%5E+%5Cprime& alt=&cos \theta_i ^ \prime& eeimg=&1&&,所以&img src=&https://www.zhihu.com/equation?tex=%5Cfrac%7BdA%5E%7B%5Cprime+%5Cprime%7D%7D%7BdA%5E%7B%5Cprime+%5Cprime+%5Cprime%7D%7D+%3D+%5Cfrac%7B1%7D%7Bcos+%5E+2+%5Ctheta_i+%5E+%5Cprime%7D& alt=&\frac{dA^{\prime \prime}}{dA^{\prime \prime \prime}} = \frac{1}{cos ^ 2 \theta_i ^ \prime}& eeimg=&1&&&br&&/p&&p&而&img src=&https://www.zhihu.com/equation?tex=dA%5E%7B%5Cprime+%5Cprime%7D+%3D+%5Cfrac%7BdA%5E%7B%5Cprime%7D%7D%7Bcos+%5Ctheta_i%5E%7B%5Cprime%7D%7D& alt=&dA^{\prime \prime} = \frac{dA^{\prime}}{cos \theta_i^{\prime}}& eeimg=&1&&&br&&/p&&p&由以上几式可得&img src=&https://www.zhihu.com/equation?tex=%5Cfrac%7BdA%5E%5Cprime%7D%7BdA_r%7D+%3D+%5Cfrac%7B1%7D%7B4+cos+%5Ctheta_i+%5E+%5Cprime%7D& alt=&\frac{dA^\prime}{dA_r} = \frac{1}{4 cos \theta_i ^ \prime}& eeimg=&1&&&/p&&p&需要注意的是,上图中的&img src=&https://www.zhihu.com/equation?tex=%5Ctheta_i+%5E+%5Cprime& alt=&\theta_i ^ \prime& eeimg=&1&&实际上是微表面的半角&img src=&https://www.zhihu.com/equation?tex=%5Ctheta_h& alt=&\theta_h& eeimg=&1&&,所以&img src=&https://www.zhihu.com/equation?tex=%5Cfrac%7Bd+%5Comega_h%7D%7Bd+%5Comega_o%7D+%3D+%5Cfrac%7B1%7D%7B4+cos+%5Ctheta_h%7D& alt=&\frac{d \omega_h}{d \omega_o} = \frac{1}{4 cos \theta_h}& eeimg=&1&&&/p&&p&因此&img src=&https://www.zhihu.com/equation?tex=f_r%28%5Comega_i%2C+%5Comega_o%29+%3D+%5Cfrac%7BF_r%28%5Comega_o%29+D%28%5Comega_h%29%7D%7B4+cos+%5Ctheta_o+cos+%5Ctheta_i%7D& alt=&f_r(\omega_i, \omega_o) = \frac{F_r(\omega_o) D(\omega_h)}{4 cos \theta_o cos \theta_i}& eeimg=&1&&&/p&&p&前面讲到过并非所有朝向为&img src=&https://www.zhihu.com/equation?tex=%5Comega_h& alt=&\omega_h& eeimg=&1&&的微表面都能接受到光照(Shadowing),也并非所有反射光照都能到达观察者(Masking),考虑几何衰减因子G的影响,则&/p&&img src=&https://www.zhihu.com/equation?tex=f_r%28%5Comega_i%2C+%5Comega_o%29+%3D+%5Cfrac%7BF_r%28%5Comega_o%29+D%28%5Comega_h%29+G%28%5Comega_i%2C+%5Comega_o%29%7D%7B4+cos+%5Ctheta_o+cos+%5Ctheta_i%7D& alt=&f_r(\omega_i, \omega_o) = \frac{F_r(\omega_o) D(\omega_h) G(\omega_i, \omega_o)}{4 cos \theta_o cos \theta_i}& eeimg=&1&&&br&&p&本来想继续写F/D/G函数的约束条件和选择,不过事情太多,时间不允许了,以后有时间再填坑吧。有很多论文基于上式给出不同的F/D/G函数,从而实现不同效果。关于F/D/G函数的比较,可以参考&a href=&https://link.zhihu.com/?target=http%3A//blog.selfshadow.com/publications/s2013-shading-course/hoffman/s2013_pbs_physics_math_notes.pdf& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&Background: Physics and Math of Shading&/a&,讲得很详细。&a href=&https://link.zhihu.com/?target=http%3A//graphicrants.blogspot.com/2013/08/specular-brdf-reference.html& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&Graphic Rants: Specular BRDF Reference&/a&列出了各种常用F/D/G函数的公式。&a href=&https://link.zhihu.com/?target=http%3A//blog.selfshadow.com/publications/s2013-shading-course/karis/s2013_pbs_epic_notes_v2.pdf& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&Real Shading in Unreal Engine 4&/a&给出了Unreal 4使用的公式以及Shader代码。&/p&&h2&资源&/h2&&ol&&li&Real-Time Rendering, Third Edition。被称为绝世武功的目录,只看这本书可能无法让你真正掌握一个算法,但它给出了大量的索引,指引你去读更详细的论文。这本书是2008年出的,到现在已经8年了,这8年图形学又有了很大的发展,所以这本书内容稍显过时,但仍然是一本很好的参考书。&a href=&https://link.zhihu.com/?target=http%3A//www.realtimerendering.com& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&Real-Time Rendering&/a&的网站上也有很多有价值的资源。&br&&/li&&li&SIGGRAPH从2010年起,每年都会有Physically Based Shading in Theory and Practice课程,邀请离线渲染和游戏等工业界成功项目开发者讲解基于物理着色的最新技术。历年课程的ppt和笔记可以在 &a href=&https://link.zhihu.com/?target=http%3A//blog.selfshadow.com/publications/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&Publications&/a& 找到。&br&&/li&&li&&a href=&https://link.zhihu.com/?target=http%3A//www.disneyanimation.com/technology/brdf.html& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&Disney BRDF Explorer&/a&,Disney动画工作室出的&a href=&https://link.zhihu.com/?target=https%3A//github.com/wdas/brdf& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&开源BRDF查看器&/a&,可以读取MERL等基于测量的BRDF数据库,也可以读取使用GLSL编写的BRDF分析模型,可以实时查看着色效果,还可以从各种视图观察BRDF的特征。&/li&&/ol&&br&&h2&References&/h2&&p&[1] Tomas Akenine-M?ller, Eric Haines, Naty Hoffman, &Real-Time Rendering, Third Edition&, &i&A.K. Peters/CRC Press,&/i& 2008.&/p&&br&&p&[2] Matt Pharr, Greg Humphreys, &Physically Based Rendering, Second Edition&, &i&Morgan Kaufmann&/i&, 2010.&/p&&br&&p&[3] Naty Hoffman, &Background: Physics and Math of
Shading&, &i&SIGGRAPH&/i&&i& 2013 Course: &/i&&i&Physically Based Shading in Theory and Practice&/i&.&/p&&br&&p&[4] Brent Burley, &Physically Based Shading at Disney&, &i&SIGGRAPH&/i&&i& 2012 Course: &/i&&i&Practical Physically Based Shading in Film and Game Production&/i&.&/p&&br&&p&[5] Brian Karis, &Real Shading in Unreal Engine 4&, &i&SIGGRAPH&/i&&i& 2013 Course: &/i&&i&Physically Based Shading in Theory and Practice&/i&.&/p&&br&&p&[6] Shree K. Nayar, Katsushi Ikeuchi, Takeo Kanade, &Surface Reflection: Physical and Geometrical Perspectives&, &i&IEEE Transactions on Pattern Analysis and Machine Intelligence&/i&, 1991.&/p&&br&&p&[7] Kenneth E. Torrance, E. M. Sparrow, &Theory for Off-Specular Reflection From Roughened Surfaces&, &i&Journal of the Optical Society of America&/i&, 1967.&/p&&br&&p&[8] Robert L. Cook, Kenneth E. Torrance, &A Reflectance Model for Computer Graphics&, &i&Proceedings of SIGGRAPH 1981&/i&.&/p&
在计算机图形学领域,着色(Shading)是指根据表面或者多边形相对光源和相机的角度和距离来计算它的颜色的过程。不同的用途可以使用不同的着色算法,CAD等追求响应速度的交互式图形领域可以使用简单快速的着色算法,卡通油画等艺术效果可以使用非真实感(No…
&figure&&img src=&https://pic4.zhimg.com/v2-b215b3f8eb880ad77e081b7ffd685a9e_b.jpg& data-rawwidth=&592& data-rawheight=&332& class=&origin_image zh-lightbox-thumb& width=&592& data-original=&https://pic4.zhimg.com/v2-b215b3f8eb880ad77e081b7ffd685a9e_r.jpg&&&/figure&&h2&写在前面&/h2&&p&最近闲来无事, 因此给自己开了个新坑 - 为一款科幻风格的塔防游戏Hacker F-301(骇客F-301)编写着色器特效. 在这个过程中有了一些心得体会, 因此打算写出来分享. 希望大家多提宝贵意见, 不吝斧正.&/p&&br&&h2&Topics&/h2&&p&本文将介绍如下几种特效:&/p&&li&Inking (模型描边)&/li&&li&Hologram (模型的全息图)&/li&&li&See - Through (渲染出物体被遮挡的部分, 类似于穿墙透视效果 - 屏幕后期特效)&/li&&li&Force Field (力场护盾效果)&/li&&li&Video Glitch (模拟LCD显示屏受到电子干扰的效果 - 屏幕后期特效. &/li&&br&&h2&Inking (模型描边, Outline)&/h2&&p&何为Inking? &/p&&p&Inking是附加在&b&蒙皮网格&/b&上的模型特效, 它用比较细的灰黑色的线条&b&勾勒出网格的轮廓&/b&. 这样做的好处是能够从背景更加&b&清晰&/b&&b&地勾画&/b&出这个网格, 尤其是在&b&对比度&/b&比较低的区域中. Inking特效的应用场景特别多, 大家耳熟能详的&b&&u&LOL&/u&&/b&中就出现了它的踪影:&br&&/p&&figure&&img src=&https://pic1.zhimg.com/v2-41bc0ba2a1fc6c29d5fc4c_b.jpg& data-rawwidth=&425& data-rawheight=&407& class=&origin_image zh-lightbox-thumb& width=&425& data-original=&https://pic1.zhimg.com/v2-41bc0ba2a1fc6c29d5fc4c_r.jpg&&&/figure&&figure&&img src=&https://pic1.zhimg.com/v2-608be38de54c5bb29c9e38_b.jpg& data-rawwidth=&425& data-rawheight=&407& class=&origin_image zh-lightbox-thumb& width=&425& data-original=&https://pic1.zhimg.com/v2-608be38de54c5bb29c9e38_r.jpg&&&/figure&&p&上面的两张图来源于一篇对LOL渲染流程分析的博客[1]. 第一张图中是原图, 而第二张图是加入Inking特效后的结果. 我们看到, 加入Inking后, 所有的模型能够更容易地从背景中区分出来, 起到了&b&Bump Up&/b&的作用. 这个例子中使用了比较粗的Inking线条, 这样也增添了一分&b&漫画风格&/b&的质感.&/p&&br&&p&&b&Inking的实现方法(综述)&/b&&/p&&p&Inking的实现方法有很多种, 大体上可以分为操作点元和操作片元两大类. 视具体情况决定使用哪一种Inking:&br&&/p&&ul&&li&Fresnel(菲尼尔)方法 - 非常类似于Rim Lighting, 使用视线方向和点法线方向的点积来判断边缘, 并将边缘高亮化.&/li&&li&优点: 效率高; 不需要单独的Pass就可以实现; 几乎所有的平滑的边缘都会得到高亮效果; 甚至对透明和半透明物体也有效. 缺点: 无法控制Inking线条的粗细, 这是因为Fresnel方法是针对于模型法线和摄像机视线的, 从而导致其仅与每个表面的法线方向有关, 而与表面的深度信息无关.&/li&&/ul&&br&&figure&&img src=&https://pic1.zhimg.com/v2-79cb72d03ad_b.jpg& data-rawwidth=&236& data-rawheight=&294& class=&content_image& width=&236&&&/figure&&br&&ul&&li&Mesh Doubling (复制网格) - 非常类似于卡通Toon特效. 需要一个单独的Pass来实现. 重新绘制一个将所有表面都沿着法线方向延展过的模型, 然后将正面剪裁掉. 这也是我采用的方案&/li&&li&优点: 效率高; 平台适应性好; 可以控制Inking的线条粗细. 缺点: 线条并不连续, 在平滑表面的表现虽然很好, 但是在锐利的表面上经常会出现断层; 只能绘制最外层轮廓, 而不对内部结构做任何处理.&br&&/li&&/ul&&br&&figure&&img src=&https://pic2.zhimg.com/v2-eb29dfdfed7b5_b.png& data-rawwidth=&800& data-rawheight=&398& class=&origin_image zh-lightbox-thumb& width=&800& data-original=&https://pic2.zhimg.com/v2-eb29dfdfed7b5_r.jpg&&&/figure&&br&&ul&&li&Edge Detection (边缘检测) - Unity自带的屏幕后期处理特效[2]. 使用Sobel Filter[3]进行描边的算法, 其基本原理是检测多个相邻的像素的深度差值, 使用一个3x3的采样块来对原图求卷积, 将深度信息差值比较大的部分过滤出来. LOL中的Inking使用的就是这个方法.&/li&&li&优点: 既可以用作屏幕后期特效, 又可以作为模型特效; 描边准确; 线条粗细可控. 缺点: 比上述两种方案都要昂贵得多, 但是其性能开销恒定, 与被处理的图像没有任何关系;&br&&/li&&/ul&&figure&&img src=&https://pic2.zhimg.com/v2-faf7f219e7562bb03be1_b.jpg& data-rawwidth=&550& data-rawheight=&290& class=&origin_image zh-lightbox-thumb& width=&550& data-original=&https://pic2.zhimg.com/v2-faf7f219e7562bb03be1_r.jpg&&&/figure&&ul&&li&使用几何着色器 - 检验临近的多边形以确定邻边和夹角, 再单独构建轮廓的几何体.&/li&&li&优点: 目前为止最为精确的做法; 很容易控制线条的粗细. 缺点: 建议买一台给力点的工作站或服务器; 一般只能用于离线渲染;&/li&&/ul&&br&&p&&b&具体实现策略&/b&&/p&&p&采用了&b&Mesh Doubling (复制网格)&/b&的方法. 这里必须要解决的问题是线条的不连续性. 其思路是不严格地将表面沿着法线方向延展, 而是在标准化的&b&点元位置和法线方向之间取一个恰当的参数来做插值&/b&, 这样做的好处是表面在延展的过程中也会尽量向点元方向靠拢, 尽量地减少了新网格的&b&撕裂感&/b&.&br&&/p&&img src=&http://www.zhihu.com/equation?tex=P_%7Bnew%7D%3DP_%7Bold%7D%2B+L+%5Ctimes+W_%7Boutline%7D+%2F+D_%7Bcam%7D& alt=&P_{new}=P_{old}+ L \times W_{outline} / D_{cam}& eeimg=&1&&&br&&img src=&http://www.zhihu.com/equation?tex=L+%3D+Normalize%28MV_%7BIT%7D+%5Ctimes+lerp%28V%2C+N%2C+f%29%29& alt=&L = Normalize(MV_{IT} \times lerp(V, N, f))& eeimg=&1&&&br&&p&其中, L表示偏移向量; W表示轮廓线条粗细; D是物体和摄像机间的距离. V是标准化后的顶点坐标, 表示方向; N是顶点向量; f是插值参数.&br&&/p&&p&&figure&&img src=&https://pic2.zhimg.com/v2-3b1fd6c19fbe5e83e7cf493cac8d2709_b.png& data-rawwidth=&552& data-rawheight=&319& class=&origin_image zh-lightbox-thumb& width=&552& data-original=&https://pic2.zhimg.com/v2-3b1fd6c19fbe5e83e7cf493cac8d2709_r.jpg&&&/figure&上图更加清晰地阐述了撕裂和不连续的情况. 如果不进行插值, 那么这种方法可以适用于球形等表面变化均匀且光滑的几何体, 但是对于立方体则无能为力.&br&&/p&&figure&&img src=&https://pic2.zhimg.com/v2-f83a2cf35fa780e47de52ede51916b15_b.png& data-rawwidth=&586& data-rawheight=&438& class=&origin_image zh-lightbox-thumb& width=&586& data-original=&https://pic2.zhimg.com/v2-f83a2cf35fa780e47de52ede51916b15_r.jpg&&&/figure&&p&上图中的立方体的延展向量使用了参数0.032作为插值, 撕裂感便不复存在了.&/p&&p&这里给出Inking特效的核心程序代码(非常简短), 同时附上部分Implementation Notes:&/p&&div class=&highlight&&&pre&&code class=&language-glsl&&&span&&/span&&span class=&n&&vertexOutput&/span& &span class=&n&&vert&/span& &span class=&p&&(&/span& &span class=&n&&appdata_base&/span& &span class=&n&&v&/span& &span class=&p&&)&/span&
&span class=&p&&{&/span&
&span class=&n&&vertexOutput&/span& &span class=&n&&o&/span&&span class=&p&&;&/span&
&span class=&n&&o&/span&&span class=&p&&.&/span&&span class=&n&&pos&/span& &span class=&o&&=&/span& &span class=&n&&mul&/span& &span class=&p&&(&/span& &span class=&n&&UNITY_MATRIX_MVP&/span&&span class=&p&&,&/span& &span class=&n&&v&/span&&span class=&p&&.&/span&&span class=&n&&vertex&/span& &span class=&p&&);&/span&
&span class=&n&&float3&/span& &span class=&n&&dir&/span& &span class=&o&&=&/span& &span class=&n&&normalize&/span& &span class=&p&&(&/span& &span class=&n&&v&/span&&span class=&p&&.&/span&&span class=&n&&vertex&/span&&span class=&p&&.&/span&&span class=&n&&xyz&/span& &span class=&p&&);&/span&
&span class=&n&&float3&/span& &span class=&n&&dir2&/span& &span class=&o&&=&/span& &span class=&n&&v&/span&&span class=&p&&.&/span&&span class=&n&&normal&/span&&span class=&p&&;&/span&
&span class=&n&&dir&/span& &span class=&o&&=&/span& &span class=&n&&lerp&/span& &span class=&p&&(&/span& &span class=&n&&dir&/span&&span class=&p&&,&/span& &span class=&n&&dir2&/span&&span class=&p&&,&/span& &span class=&n&&_Factor&/span& &span class=&p&&);&/span&
&span class=&n&&dir&/span& &span class=&o&&=&/span& &span class=&n&&mul&/span& &span class=&p&&(&/span& &span class=&p&&(&/span& &span class=&n&&float3x3&/span& &span class=&p&&)&/span& &span class=&n&&UNITY_MATRIX_IT_MV&/span&&span class=&p&&,&/span& &span class=&n&&dir&/span& &span class=&p&&);&/span&
&span class=&n&&float2&/span& &span class=&n&&offset&/span& &span class=&o&&=&/span& &span class=&n&&TransformViewToProjection&/span& &span class=&p&&(&/span& &span class=&n&&dir&/span&&span class=&p&&.&/span&&span class=&n&&xy&/span& &span class=&p&&);&/span&
&span class=&n&&offset&/span& &span class=&o&&=&/span& &span class=&n&&normalize&/span& &span class=&p&&(&/span& &span class=&n&&offset&/span& &span class=&p&&);&/span&
&span class=&k&&float&/span& &span class=&n&&dist&/span& &span class=&o&&=&/span& &span class=&n&&distance&/span& &span class=&p&&(&/span& &span class=&n&&mul&/span& &span class=&p&&(&/span& &span class=&n&&UNITY_MATRIX_M&/span&&span class=&p&&,&/span& &span class=&n&&v&/span&&span class=&p&&.&/span&&span class=&n&&vertex&/span& &span class=&p&&),&/span& &span class=&n&&_WorldSpaceCameraPos&/span& &span class=&p&&);&/span&
&span class=&n&&o&/span&&span class=&p&&.&/span&&span class=&n&&pos&/span&&span class=&p&&.&/span&&span class=&n&&xy&/span& &span class=&o&&+=&/span& &span class=&n&&offset&/span& &span class=&o&&*&/span& &span class=&n&&o&/span&&span class=&p&&.&/span&&span class=&n&&pos&/span&&span class=&p&&.&/span&&span class=&n&&z&/span& &span class=&o&&*&/span& &span class=&n&&_OutlineWidth&/span& &span class=&o&&/&/span& &span class=&n&&dist&/span&&span class=&p&&;&/span&
&span class=&k&&return&/span& &span class=&n&&o&/span&&span class=&p&&;&/span&
&span class=&p&&}&/span&
&/code&&/pre&&/div&&p&_Factor即为插值参数. 变换法向量要注意使用Model View矩阵的转置逆矩阵. 为了保证最终的线条粗细维持世界坐标上的恒定, 而不随摄像机的移动发生改变, 因此延展的像素位置要除以摄像机距离. 最终片元着色器函数只需要一句return _C即可. 最后必须注意剪裁掉正面, 否则绘制出的不会是轮廓, 而是将模型包裹起来的保鲜膜
...&br&&/p&&figure&&img src=&https://pic1.zhimg.com/v2-004b561a1fdfeec2a482bd8b33c95804_b.png& data-rawwidth=&1366& data-rawheight=&853& class=&origin_image zh-lightbox-thumb& width=&1366& data-original=&https://pic1.zhimg.com/v2-004b561a1fdfeec2a482bd8b33c95804_r.jpg&&&/figure&&figure&&img src=&https://pic1.zhimg.com/v2-1a8c4e105d9303abdc1918_b.png& data-rawwidth=&1366& data-rawheight=&853& class=&origin_image zh-lightbox-thumb& width=&1366& data-original=&https://pic1.zhimg.com/v2-1a8c4e105d9303abdc1918_r.jpg&&&/figure&&br&&p&上面两张图是加入特效的前后对比. 我们看到使用Inking后炮塔能够更加&犀利&地从背景中呈现出来.&/p&&p&一定程度上, Inking有点类似于SSAO. 两者都是尝试在几何体的交界处加入更深层次的阴影以让画面更有对比度. 关于SSAO我的&a href=&https://zhuanlan.zhihu.com/p/?refer=MeowShader& class=&internal&&知乎专栏第四篇&/a&有过介绍.&/p&&h2&Hologram (模型的全息图)&/h2&&p&何为Hologram? &/p&&p&全息图是一般以激光为光源, 将被摄物体记录为3D光场(Light Field)所构成的三维图像. 一般以干涉条纹的形式存在.&/p&&figure&&img src=&https://pic2.zhimg.com/v2-9f6ba038b041_b.jpg& data-rawwidth=&1276& data-rawheight=&1024& class=&origin_image zh-lightbox-thumb& width=&1276& data-original=&https://pic2.zhimg.com/v2-9f6ba038b041_r.jpg&&&/figure&&figure&&img src=&https://pic3.zhimg.com/v2-9be6e19d1bb0e8ad15d49b3dff971a4e_b.jpg& data-rawwidth=&610& data-rawheight=&343& class=&origin_image zh-lightbox-thumb& width=&610& data-original=&https://pic3.zhimg.com/v2-9be6e19d1bb0e8ad15d49b3dff971a4e_r.jpg&&&/figure&&p&上图中第一张图是全息投影仪的概念效果, 第二张图是质量效应(Mass Effect)中的特效.&/p&&p&Hologram一般可以用作单位建造的&b&预览效果&/b&&b&和&/b&&b&呈现结构&/b&的效果.&/p&&figure&&img src=&https://pic3.zhimg.com/v2-b215b3f8eb880ad77e081b7ffd685a9e_b.jpg& data-rawwidth=&592& data-rawheight=&332& class=&origin_image zh-lightbox-thumb& width=&592& data-original=&https://pic3.zhimg.com/v2-b215b3f8eb880ad77e081b7ffd685a9e_r.jpg&&&/figure&&figure&&img src=&https://pic2.zhimg.com/v2-5f90e48e0f3d62dd0dac5_b.jpg& data-rawwidth=&785& data-rawheight=&393& class=&origin_image zh-lightbox-thumb& width=&785& data-original=&https://pic2.zhimg.com/v2-5f90e48e0f3d62dd0dac5_r.jpg&&&/figure&&h4&第一次尝试(Naive 方法)&/h4&&p&计算模型的每个片元的屏幕坐标, 然后对一个条纹状纹理采样即可. 为了防止单一的条纹过于无聊, 同时还引入了一个Noise Map来进行干扰. 代码如下:&/p&&div class=&highlight&&&pre&&code class=&language-glsl&&&span&&/span&&span class=&n&&v2f&/span& &span class=&n&&vert&/span& &span class=&p&&(&/span& &span class=&n&&appdata_base&/span& &span class=&n&&v&/span& &span class=&p&&)&/span&
&span class=&p&&{&/span&
&span class=&n&&v2f&/span& &span class=&n&&o&/span&&span class=&p&&;&/span&
&span class=&n&&o&/span&&span class=&p&&.&/span&&span class=&n&&pos&/span& &span class=&o&&=&/span& &span class=&n&&UnityObjectToClipPos&/span& &span class=&p&&(&/span& &span class=&n&&v&/span&&span class=&p&&.&/span&&span class=&n&&vertex&/span& &span class=&p&&);&/span&
&span class=&n&&o&/span&&span class=&p&&.&/span&&span

我要回帖

更多关于 shield 的文章

 

随机推荐