unity 全局照明烘焙_Unity 5中的全局照明
unity 全局照明烘焙
Unity 5 is receiving a major make-over in terms of graphical fidelity and lighting in particular. Unity has been limited to baked lightmaps since Unity 3.0, but since then a lot of progress has been made in the global illumination field. Now is the time to provide some of that goodness out-of-the box in Unity. One of the new graphics features in Unity 5 is real-time in-game global illumination combined with new and vastly improved lighting workflows and these are the focus of this post. But first some background.
Unity 5在图形保真度和照明方面正在接受重大改造。 自Unity 3.0以来,Unity仅限于烘焙的光照贴图,但是自那时以来,在全局照明领域已经取得了很多进展。 现在是时候在Unity中立即提供一些好处了。 Unity 5中的新图形功能之一是实时游戏内全局照明,并结合了经过改进的全新照明工作流程,这些是本文的重点。 但是首先要有一些背景。
Doll model rendered with path tracing in Unity. Courtesy of Paul Tham, Unity Singapore.
在Unity中使用路径跟踪渲染的玩偶模型。 由新加坡Unity的Paul Tham提供。
全球照明到底是什么? (What is this global illumination all about?)
Global illumination (GI) is the simulation of physically based light transport. It is a means to simulate how light is transferred between surfaces in your 3D scene and it will greatly increase the realism of your game. Not only that, it is also a means to convey mood and with clever use can be used to improve the gameplay. GI algorithms take into account not only the light which comes directly from a light source (the direct illumination), but also subsequent cases in which this light is reflected by surfaces in the scene using different materials (indirect illumination). Traditionally, indirect illumination has been too expensive to compute within the real-time constraint of a game.
全局照明(GI)是基于物理的光传输的模拟。 这是一种模拟光在3D场景中的表面之间传输方式的方法,它将大大提高游戏的真实感。 不仅如此,它还是一种传达情绪的手段,并且可以巧妙地使用它来改善游戏玩法。 GI算法不仅考虑到直接来自光源的光(直接照明),而且考虑了随后的情况,这些光被场景中的表面使用不同的材质反射(间接照明)。 传统上,间接照明过于昂贵,无法在游戏的实时约束范围内进行计算。
It is all down to this innocent looking equation:
这完全取决于这个天真无邪的方程式:
It is really rather simple. The lighting visible from some point in your scene is the sum of light emitted from that surface point (Le) and the incident lighting from the hemisphere above the point reflected into the viewing direction towards the viewer. Li describes incoming light from some direction w’ on the hemisphere towards the point x. The reflectance term p then describes how light is reflected towards the viewer and is dependent on the incident angle w’ and the exitant angle w.
这真的很简单。 从场景中某个点可见的照明是从该表面点( Le )发出的光与该点上方半球的入射光的总和,反射到观察方向并朝向观察者。 Li描述了从半球上某个方向w'指向点x的入射光。 然后,反射率项p描述光如何朝着观看者反射,并取决于入射角w'和出射角w 。
As the observant reader might have spotted L(x,w) is on both sides of the equation and inside an integral to boot. Now if that hadn’t been the case we would have had global illumination in Elite. Since the laws of physics are hard to alter, the research community set about to come up with a solution.
细心的读者可能已经发现, L(x,w)在等式的两边且在引导的积分内。 现在如果不是这样的话,我们将会在Elite中拥有全球视野 。 由于物理定律很难改变,因此研究界开始提出解决方案。
One of the most popular (and oldest) algorithms is path tracing, which basically attacks this algorithm head on, with some tricks added to spend the most time on areas known to be difficult. Path tracing is used a lot in CGI for film and television. Even though a massive amount of research has been poured into this, an image takes in the order of seconds to render (even with a beefy GPU).
路径跟踪是最流行(也是最古老)的算法之一,它基本上可以直接攻击该算法,并增加了一些技巧,可以将大部分时间花费在已知困难的区域上。 电影和电视的CGI中经常使用路径跟踪。 即使对此进行了大量研究,但图像渲染仍需要几秒钟的时间(即使使用强大的GPU)。
Path tracing is typically used in screen-space, so the image needs to be re-rendered from scratch in every frame. This means that it supports fully dynamic scenes: lighting, materials, geometry can be freely animated. This is also a drawback as a new image has to be rendered when the camera is moved, and, since it takes on the order of seconds for the image to fully converge, it will not be appropriate for games.
路径跟踪通常在屏幕空间中使用,因此需要在每帧中从头开始重新渲染图像。 这意味着它支持完全动态的场景:可以*设置动画的照明,材质,几何形状。 这也是一个缺点,因为在移动相机时必须渲染新图像,并且由于图像完全收敛需要几秒钟的时间,因此不适用于游戏。
A not fully converged image has disturbing noise in it and it is also not temporally coherent either so the image will flicker badly as it reaches convergence. Filtering can help limit this effect, but it cannot be completely removed. Below are a few shots taken at various levels of convergence:
未完全收敛的图像中会有令人不安的噪声,并且在时间上也没有相干性,因此图像在达到收敛时会严重闪烁。 过滤可以帮助限制这种影响,但是不能完全消除。 以下是在不同融合程度下拍摄的一些照片:
Path traced images at various stages of convergence.
在收敛的各个阶段的路径跟踪图像。
Lately a number of hybrid approaches have been developed, many running on the GPU, such as voxel cone tracing. Most of them require a desktop GPU with a fair amount of memory and are appropriate for high-end desktop systems only. In order to provide global illumination that will work well on a wide swath of supported platforms (including mobile) some compromise has to be made.
最近,已经开发了许多混合方法,其中许多方法都在GPU上运行,例如体素圆锥跟踪。 它们中的大多数需要具有大量内存的台式机GPU,并且仅适用于高端台式机系统。 为了提供全局照明,该照明将在广泛的受支持平台(包括移动设备)上正常工作 必须做出一些妥协。
输入启发 (Enter Enlighten)
Enlighten provides an excellent solution to this problem. It very elegantly scales from mobile through consoles up to high-end systems because it constrains the problem it is solving. It has also been battle-tested as it was shipped in AAA titles such as Battlefield 4, MoH Warfighter, and others.
Enlighten提供了一个很好的解决方案。 它从移动设备到控制台,再到高端系统,都非常优雅地扩展,因为它约束了所要解决的问题。 它也以AAA级标题(如《 战地风云4》 ,《 MoH Warfighter》等)进行了战斗测试。
The basic idea is that if some of the visibility is precomputed (i.e. the integral on the right in the rendering equation above) it is possible to modify the lighting in real-time even on mobile platforms.
基本思想是,如果预先计算了一些可见性(即,上面的渲染方程式右侧的积分),则即使在移动平台上,也可以实时修改照明。
Enlighten allows dynamically changing:
Enlighten允许动态更改:
- Light sources. 光源。
- Environment lighting. 环境照明。
- Material properties (diffuse reflectivity and surface emission). 材料特性(漫反射率和表面发射)。
The geometry that is part of the GI simulation has to be static, but dynamic geometry can be relit using light probes that are updated in real-time with the GI generated from the static geometry. In order to do this Enlighten precomputes the data needed for simulating GI at run-time. This data is consumed by a run-time module which is available for many platforms: OSX, Windows, Linux, iOS, Android, PS Vita, PS3, PS4, Windows Phone, Xbox360 and XboxOne. WebGL is in the works, but no definite timeline for this.
GI仿真的一部分几何必须是静态的,但是可以使用由静态几何生成的GI实时更新的光探头来调整动态几何。 为此,Enlighten会在运行时预先计算仿真GI所需的数据。 此数据由运行时模块消耗,该运行时模块可用于许多平台:OSX,Windows,Linux,iOS,Android,PS Vita,PS3,PS4,Windows Phone,Xbox360和XboxOne。 WebGL正在开发中,但尚无明确的时间表。
Enlighten outputs the following data:
Enlighten输出以下数据:
- Real-time lightmaps. 实时光照贴图。
- Real-time lightprobes. 实时光探针。
- Real-time cubemaps. 实时立方体贴图。
Enlighten is limited to computing GI for diffuse transport. This is the most important mode of transport as it conveys the overall illumination of the scene. Since diffuse transport is generally low-frequency the real-time lightmaps can be quite low-res and updateable in real-time. Support for specular/glossy transport is added by providing dynamically updated cubemaps. In Heckbert notation Enlighten accounts for the following light path subset: L(D)*(S|G)?E. This means that most GI effects are covered. The main missing effect will be specular bounces via diffuse surfaces – commonly known as caustics. To get this effect you will need to cheat.
Enlighten仅限于计算GI进行扩散运输。 这是最重要的运输方式,因为它可以传达场景的整体照度。 由于扩散传输通常是低频的,因此实时光照贴图的分辨率可能非常低,并且可以实时更新。 通过提供动态更新的立方体贴图,添加了对镜面/光泽传输的支持。 Enlighten用Heckbert表示法解释以下光路子集:L(D)*(S | G)?E。 这意味着涵盖了大多数GI效果。 主要的缺失效应将是通过漫反射表面产生的镜面反射-通常被称为焦散。 为了获得这种效果,您将需要作弊。
Below is an example of two lighting setups rendered with Enlighten. These lighting setups were fully dynamic and switching between them is instantaneous.
以下是使用Enlighten渲染的两种照明设置的示例。 这些照明设置是完全动态的,并且它们之间的切换是瞬时的。
Viking Village – dawn
维京村-黎明
In this next shot a brighter blue sky was used the sun is higher and more intense:
在下一个镜头中,使用了更明亮的蓝天,太阳更高且更强烈:
Viking Village – sunny day
维京村–晴天
Environment lighting is grey and desaturated and the sun intensity is lower. Mainly ambient lighting:
环境照明为灰色且不饱和,并且阳光强度较低。 主要环境照明:
Viking Village – overcast day
维京村–阴天
Lastly a sunset shot with warm reds for a sunset mood:
最后用温暖的红色拍摄日落,以营造日落气氛:
Viking Village – sunset
维京村–日落
Using this technique enables games with very realistic looking time-of-day cycles.
使用此技术可以使游戏具有非常逼真的日时钟周期。
启发预计算 (Enlighten precompute)
The compromise is that most of the geometry has to be static, effectively all the large scale geometry that will participate in the GI solution. During the precomputation phase Enlighten will automatically break up the scene into systems. It is also possible to affect how these systems are generated. The systems serve to make the precompute a massively parallel pipeline. The pipeline is relatively deep and solves per system tasks. Here is an example of how the Viking Village level was automatically broken up into systems:
折衷方案是,大多数几何图形必须是静态的,实际上是将要参与GI解决方案的所有大型几何图形。 在预计算阶段,Enlighten将自动将场景分解为多个系统 。 也可能会影响这些系统的生成方式。 该系统用于使预计算成为大规模并行管道。 管道相对较深,可以解决每个系统的任务。 这是一个如何将“维京村”级别自动分解为系统的示例:
Editor visualization of the automatically generated Enlighten systems.
自动生成的Enlighten系统的编辑器可视化。
After the precompute has finished the relationship between the systems is known and this can be used in the run-time to partially alleviate the limitation of static geometry. At run-time the amount of indirect light transferred between systems can be controlled. This allows you to fade in bounce between systems and this can be used to achieve effects such as destruction or opening doors.
在预计算完成之后,系统之间的关系就已知了,可以在运行时使用它来部分缓解静态几何的限制。 在运行时,可以控制系统之间传递的间接光量。 这使您可以淡入系统之间的跳动,并且可以用于实现破坏或打开门等效果。
启发运行时间 (Enlighten run-time)
The Enlighten run-time is efficient enough to run on higher end mobile devices. It runs asynchronously on a CPU thread (or more threads if the platform allows it). The most prominent issue for mobile platforms will be that the direct lighting and shadow maps for dynamic lights needs to be computed on the GPU. So on mobile platforms only a few dynamic lights will be feasible. However, the emissive properties of geometry can be adjusted in real-time almost for free. The emissive lighting computed by Enlighten encodes visibility too. This means that the emissive light is effectively shadow mapped for free, albeit at a low resolution.
Enlighten运行时的效率足以在高端移动设备上运行。 它在CPU线程(或平台允许的话,更多线程)上异步运行。 移动平台最突出的问题是动态光照的直接光照和阴影贴图需要在GPU上计算。 因此,在移动平台上,只有少量动态照明是可行的。 但是,几乎可以免费实时调整几何结构的发射特性。 Enlighten计算的发光照明也对可见性进行编码。 这意味着,尽管是低分辨率的,但有效地免费对发射光进行了阴影贴图。
Enlighten scales well onto desktop systems and next-gen consoles that could support games using exclusively dynamic lights since more GPU power is available for direct lighting and shadow mapping.
Enlighten可以很好地扩展到台式机系统和下一代游戏机上,这些游戏机可以仅使用动态灯光来支持游戏,因为更多的GPU功能可用于直接照明和阴影贴图。
Here is an example of a mobile demo using Enlighten running on an ARM powered tablet:
这是使用在基于ARM的平板电脑上运行的Enlighten进行移动演示的示例:
那烘烤呢 (What about baking)
For some titles baking will be the appropriate choice, so this workflow will be supported and developed well into the future. In Unity 5 the lighting inputs: light sources, emissive materials and environment lighting can be tagged as using baked or real-time GI. Baked lighting inputs are baked into lightmaps in the same way as in previous versions of Unity and dynamic lights are handled by the Enlighten run-time. The baked and real-time GI merges seamlessly.
对于某些标题,烘焙将是适当的选择,因此,此工作流程将得到支持并在未来得到很好的发展。 在Unity 5中,可以将照明输入: 光源 , 发光材料和环境照明标记为使用烘焙或实时GI。 烘焙的照明输入以与Unity早期版本相同的方式烘焙到光照贴图中,动态光照由Enlighten运行时处理。 烘焙后的实时GI无缝融合。
There are also new baking features already in Unity 5. One of those is that now the lightmaps are broken up into components. For each atlas there are five lightmaps containing direct lighting, indirect lighting, direct directionality, indirect directionality and AO respectively. After a bake these will be composited into lightmaps used in the game. In the Editor there are controls that specify how these lightmaps are composited. You can tweak these settings to adjust the look of the final output. For example the indirect lighting can be boosted easily. This only requires a compositing job, which takes seconds whereas before a rebake would be needed to do this.
Unity 5中已经有了新的烘焙功能,其中之一就是现在将光照贴图分解为多个组件。 对于每个地图集,都有五个光照图,分别包含直接照明 , 间接照明,直接方向性 , 间接方向性和AO 。 烘烤后,这些将被合成为游戏中使用的光照贴图。 在编辑器中,有一些控件可以指定如何组合这些光照贴图。 您可以调整这些设置以调整最终输出的外观。 例如,可以容易地增强间接照明。 这仅需要一个合成工作,这需要几秒钟,而需要重新烘烤才能完成。
照明工作流程 (Lighting workflow)
Enlighten doesn’t just provide in-game real-time GI. One of the most important improvements that Enlighten provides is a vastly improved lighting workflow for artists. It allows for faster iteration on lighting, which in turn yields better looking content. An iterative mode has been added, which removes the need for explicitly baking the scene. The scene will instead precompute and bake in the background without any user intervention. The Editor will automatically track changes made to the scene and execute the tasks needed to fix up the lighting. In many cases when iterating on the lighting these tasks will be nearly instantaneous.
Enlighten不仅提供游戏中的实时GI。 Enlighten提供的最重要的改进之一是为艺术家大大改善了照明工作流程。 它可以加快照明的迭代速度,从而产生更好看的内容。 添加了迭代 模式 ,从而无需显式烘焙场景。 场景将在没有任何用户干预的情况下预计算并在后台烘焙。 编辑器将自动跟踪对场景所做的更改,并执行修复照明所需的任务。 在许多情况下,在照明上迭代时,这些任务几乎是瞬时的。
The following video shows a live session using the new lighting workflow:
以下视频显示了使用新照明工作流程的实时会话:
哪些类型的游戏可以与Enlighten一起使用? (What types of games will work with Enlighten?)
As already discussed the limitation of real-time GI is that the large scale scene setup must be known in advance. We had to choose either to pursue a fully dynamic solution that would only work on high-end systems or a solution that covers many use-cases but also works on mobile hardware, thus reaching a wider part of the market. And we chose the latter for 5.0. Below is a list of types of games that may prove difficult with real-time GI:
正如已经讨论过的,实时GI的局限性在于必须事先知道大规模场景设置。 我们必须选择追求仅在高端系统上可以使用的完全动态解决方案,或者选择既可以覆盖许多用例又可以在移动硬件上运行的解决方案,从而占领更广阔的市场。 我们选择后者为5.0。 以下列出了使用实时GI可能会遇到困难的游戏类型:
-
Q: Can I do opening of doors and gates?
问:我可以开门吗?
A:
A:
As discussed above authoring systems and scripting the exchange of bounce between systems depending on the door or gate will solve this in some cases. (The scripting extensions needed for this are expected to arrive in 5.x.)
如上所述,在某些情况下,根据门或门编写系统和编写系统之间的反弹交换脚本可解决此问题。 (为此所需的脚本扩展预计将在5.x中到达。)
-
Q: Can I support destruction?
问:我可以支持销毁吗?
A:
A:
Support for making objects transparent dynamically exists in Enlighten. This means that objects that may be destroyed in the game must be marked as such in advance. While this is not ideal it should support many use-cases. ( This feature should arrive in 5.x.)
Enlighten中支持动态地使对象透明。 这意味着必须在游戏中预先标记可能在游戏中销毁的对象。 虽然这不是理想的选择,但它应该支持许多用例。 (此功能应在5.x中提供。)
-
Q: Can I download (stream) chunks of level additively?
问:我可以附加下载(流式)关卡块吗?
A:
A:
Yes, systems can be streamed in additively. The systems can be made so that they do not straddle your streaming chunks. This can be done manually or with scripting. (This feature should be available in 5.0.)
是的,系统可以流式传输。 可以将系统做成不会跨越您的流媒体块的地方。 这可以手动完成或通过脚本完成。 (此功能应在5.0中可用。)
-
Q: Can I create a game world semi-procedurally with premade chunks (endless runner type)?
问:我可以半预制地用预制块(无尽的亚军类型)来创建游戏世界吗?
A:
A:
Yes, bounce between consecutive chunks would be possible if the various combinations that premade chunks are arranged in are precomputed separately. This is similar to how you would bake lightmaps (without seams) for an endless runner. (The precompute API needed for this should be available in 5.x.)
是的,如果预先安排了预制块所在的各种组合,则可能会在连续块之间反弹。 这类似于您为无尽的跑步者烘烤光照贴图(无接缝)的方式。 (为此所需的预计算API应该在5.x中可用。)
-
Q: Can I create game world fully procedurally, Minecraft style?
问:我可以按照程序完全按照Minecraft的风格创建游戏世界吗?
A:
A:
Short answer, no. However, we are doing multiple projects with Imagination Technologies using their PowerVR Ray Tracing technology for GI previews and hybrid rendering. This could potentially yield a solution to procedural or user generated scenes. The PowerVR Ray Tracing technology supports interactive GI for fully dynamic scenes. It is not yet fully real-time and the first few frames will have visible noise as the solution converges, but it is a very promising direction. It will certainly be able to light user generated scenes assuming some delay is acceptable. (There is no ETA for this as it is still an R&D project.)
简短的回答,不。 但是,我们正在使用Imagination Technologies的PowerVR射线追踪技术进行GI预览和混合渲染的多个项目。 这可能会为程序或用户生成的场景提供解决方案。 PowerVR光线跟踪技术支持用于完全动态场景的交互式GI。 它尚未完全实时,随着解决方案的收敛,前几帧将具有可见噪声,但这是一个非常有希望的方向。 假设可以接受一些延迟,那么它一定能够点亮用户生成的场景。 (对此尚无ETA,因为它仍是一个研发项目。)
免费版将包含什么? (What will be in Free what will be in Pro?)
The feature split between Unity Free and Unity Pro has not yet been decided. We will announce this in a future blog post.
Unity Free和Unity Pro之间的功能划分尚未确定。 我们将在以后的博客文章中宣布这一点。
5.0中有什么 (What is in 5.0)
These are the main features shipping in Unity 5.0:
这些是Unity 5.0中提供的主要功能:
- Enlighten run-time for in game real-time GI. 启发游戏实时GI中的运行时。
- Iterative workflow (for both real-time GI and baking). 迭代工作流程(用于实时GI和烘焙)。
- Reflection probes. 反射探头。
超越5.0 (Beyond 5.0)
As we are doing a lot of changes to the lighting workflows and lighting in general some features will slip 5.0 as they need more polish. These are some of the features that will surface during the Unity 5 cycle:
由于我们正在对照明工作流程和照明进行大量更改,因此某些功能会因为需要更完善而滑到5.0。 这些是Unity 5周期中将浮现的一些功能:
-
PowerVR path traced previews for real-time and baked lightmaps (details here).
实时和烘焙光照贴图的PowerVR路径跟踪预览( 此处有详细信息)。
- API for controlling the real-time GI contribution between systems. 用于控制系统之间实时GI贡献的API。
- Enlighten real-time cubemaps. 启发实时立方体贴图。
- Support for real-time GI transparency. 支持实时GI透明度。
- Cloud/cluster precompute/bake. 云/集群预计算/烘焙。
Some more material is available on this subject: slides for the Unite 2014 talk on GI, video of the Unite 2014 talk on GI, Unite 2014 keynote (graphics part).
关于此主题的更多材料可用: Unite 2014地理演讲的幻灯片,Unite 2014地理演讲的 视频 , Unite 2014主题演讲(图形部分) 。
Let us know what you think!
让我们知道您的想法!
The Graphics Team.
图形团队。
翻译自: https://blogs.unity3d.com/2014/09/18/global-illumination-in-unity-5/
unity 全局照明烘焙