Unity Graphics (Unity 图形渲染 ) 官方教程文档笔记系列之九

Unity Graphics (Unity 图形渲染 )
- Everything for Lighting and Rendering in Unity
- 主要涉及到光照与渲染方面的知识

本文档主要是对Unity官方教程的个人理解与总结(其实以翻译记录为主:>)
仅作为个人学习使用,不得作为商业用途,欢迎转载,并请注明出处。
文章中涉及到的操作都是基于 Unity2018.3版本
参考链接:https://unity3d.com/cn/learn/tutorials/s/graphics


下面是将要介绍的章节,黑体是本次内容:

  • Introduction to Lighting and Rendering
    介绍光照和渲染
  • Precomputed Realtime GI (Realtime Global Illumination)(9)
    预处理实时全局光照(9)
  • Rendering and Shading
    渲染与着色
  • Cameras and Effects
    相机与效果
  • Geometry in Unity
    几何体

7.Optimizing Unity’s auto unwrapping

7.优化Unity的自动展开

When configuring unwrap parameters, the ideal outcome is to find a combination of values that results in the lowest number of Charts while having the least lightmap distortion. Remember that distortion is visualized as stretching of the checkerboard texture applied to objects in the Scene view when UV Charts draw mode is enabled.
在配置展开参数时,理想的结果是找到一组值的组合,这些值在最少的光照图失真的情况下,图表的数量最少。请记住,当UV图表绘制模式开启时,在场景视图中扭曲将可视化,比如对象的棋盘纹理拉伸。

The checkerboard pattern can be used to visualize lightmap texel distribution. Notice here that the checkerboard is relatively consistent across our model - meaning there is little lightmap distortion.
棋盘图可以用来表示可视化光照图纹素的分布。注意这里的棋盘和我们的模型是相对一致的-这意味着更少的光照图扭曲。

Stretching and warping of the checkerboard indicates that there is some inconsistency in the distribution of lightmap texels.
棋盘格的拉伸和变形表明,光照图纹素的分布有一些不一致的地方。

In this example, we will apply what we have learned about UV unwrapping to optimize precompute times on an object in our tutorial project.
在本例中,我们将应用我们所学到的关于UV展开的知识,以优化我们的教程项目中的对象的预计算时间。

• Open the LightingTutorialStart Scene included in the example project.
打开示例项目中包含的 LightingTutorialStart 场景
• Select one of the objects called HouseBig02 in the Hierarchy window.These are grouped under Environment > Structures > Houses.
在层次结构窗口中选择名为HouseBig02的对象。这些在Environment > Structures > Houses 分组下。
• Open the Lighting window (Window > Lighting) and select the Object tab.
打开光照窗口(窗口-灯光)并选择Object选项卡。
• Select Charting from the drop-down menu in the top left of the tab.
从选项卡左上角的下拉菜单中选择图表。
• Expand the Preview area at the bottom of the tab. Note how many UV shells are displayed here and the number of corresponding colored Charts.
在选项卡的底部展开预览区域。请注意这里显示了多少个UV组,以及相应的彩色图表的数量。


Image showing the Charting preview for the HouseBig02 object with default unwrap settings. This number of Charts can be easily reduced.
图像显示了带有默认展开设置的 HouseBig02 对象的图表预览。可以很容易地减少这一图表的数量。

HouseBig02 is a fairly complex object within our Scene, which may justify the use of multiple Charts. However, we may still be able to reduce this number by modifying our unwrap settings.
在我们的场景中,HouseBig02 是一个相当复杂的对象,这可能会证明使用多个图表是合理的。但是,我们仍然可以通过修改我们的展开设置来减少此数量。

The Object unwrap settings panel
对象展开设置面板

There is no one-size fits all solution for unwrapping objects. Unity’s unwrapping algorithms attempt to make sensible decisions based on appropriate defaults, but with some user guidance, we may be able to achieve a more optimal result.
没有一种适合所有展开对象的解决方案。Unity的展开算法试图基于适当的默认值做出明智的决定,但是在一些用户导则下,我们可能会得到一个更优的结果。

  • Select HouseBig02 in the Hierarchy window.
    Hierarchy 窗口下选择HouseBig02
  • Open the Lighting window (Window > Lighting) and select the Object tab.
    打开光照窗口,选择 Object 页签
  • Lower the Auto UV Max Distance to its minimum value of 0.1.
    把自动UV最大距离调低到最小于0.1

The precompute process will begin. Following a brief calculation, we can see in the Preview area of the Lighting window that number of Charts has noticeably increased. Checking the Scene view there seems to be little distortion, which is good. Unfortunately, however, this many Charts for an object of this complexity is unacceptable. Remember that more Charts means longer precompute times and reduced performance at run time.
预计算过程将开始。经过简单的计算,我们可以看到在灯光窗口的预览区域,图表的数量明显增加了。检查场景视图似乎没有什么失真,这很好。然而,不幸的是,这个复杂的对象的图表数量是不可接受的。请记住,更多的图表意味着更长的预计算时间和运行时性能的降低。

  • If HouseBig02 is not selected in the Hierarchy window, select it.
    Hierarchy 窗口下选择HouseBig02
  • Navigate to the Lighting window (Window > Lighting) and select the Object tab.
    打开光照窗口,选择 Object 页签
  • Set the value of Auto UV Max Distance to 10.
    把自动UV最大距离调到最10

We now have the opposite problem. The number of Charts has decreased, but at the cost of introducing unacceptable distortion to our lightmaps. We can observe this distortion in the UV Charts Scene draw mode. The distortion appears as streaking or stretching of the checkerboard overlay.
我们现在面临着相反的问题。图表的数量减少了,但代价是在我们的光照图呈现出不可接受的失真。我们可以在UV图表绘制模式中观察到这种变形。表现为覆盖的条纹扭曲或棋盘格拉伸。

Selecting an Auto UV Max Distance which is too high can result in distortion of our lightmap UVs.
选择一个太高的自动UV最大值距离可能会导致我们的光照图UVs的变形。

We know that Unity’s unwrapping algorithm attempts to minimise the number of Charts by merging UV shells together. The Auto UV Max Distance setting specifies the maximum distance, in worldspace, permitted between UV shells when they are considered for merging. If the shells are further apart than this value, they will not be combined.
我们知道,Unity的展开算法试图通过合并UV组来最小化图表的数量。自动UV最大距离设置指定:世界空间中在UV组之间允许的最大距离之内才会被考虑合并。如果这些UV组大于这个值,它们就不会被合并。

When we decreased our Auto UV Max Distance, fewer UV shells were eligible for merging. This meant that more individual Charts remained at the end of the process. When we increased our Auto UV Max Distance, UV shells that were very far apart in worldspace were then able to be merged. This resulted in fewer Charts, but this aggressive merging also caused warped lightmap UVs and therefore more distortion in our lightmap output.
当我们减少我们的自动UV最大距离时,更少的UV可以合并。这意味着在这个过程的最后,会有更多的单独的图表。当我们增加我们的自动UV最大距离时,在世界空间中相距很远的UV 组就能被合并。这导致了更少的图表,但是这种侵略性的合并也导致了扭曲的光照图UVs,因此在我们的光照图输出中会有更多的失真。

Note that with large objects it can sometimes be necessary to increase the Auto UV Max Distance in order to accommodate the size of faces within the mesh. Conversely, with smaller objects decreasing the Auto UV Max Distance might yield better results.
请注意,对于大的对象,有时为了适应网格内的面数大小,有时需要增加自动UV的最大距离。相反地,小的物体减少了自动UV最大距离可能产生更好的结果。

With the example of our object, HouseBig02, an Auto UV Max Distance value of 0.8 gives a good compromise between Chart count and distortion.
以我们的对象,HouseBig02的例子,一个自动UV最大距离值为0.8,在图表计数和失真之间提供了一个很好的折衷。

  • If HouseBig02 is not selected in the Hierarchy window, select it.
    Hierarchy 窗口下选择HouseBig02
  • Navigate to the Lighting window (Window > Lighting) and select the Object tab.
    打开光照窗口,选择 Object 页签
  • Set the value of Auto UV Max Distance to 0.8.
    把自动UV最大距离调到最0.8

    Using a Auto UV Max Distance of 0.8 gives a good result with our example object. However, we can still improve this further.
    使用一个自动UV最大距离为0.8的例子,可以得到一个好的结果。然而,我们仍然可以进一步改进。

Now we will look at the Auto UV Max Angle parameter. Like Auto UV Max Distance, this value affects the UV merging step of Unity’s unwrapping algorithms. In addition to being tested for distance before UV shells are combined, the unwrapper also tests the angle between adjacent mesh faces. Only edges with an angle below this value will be considered for merging.
现在我们来看一下自动UV最大角度参数。就像自动UV最大距离一样,这个值会影响Unity的展开算法的UV合并的其中步骤。除了在UV 组合并之前进行距离测试外,展开器还测试相邻网格面之间的夹角。只有边沿的角小于这个值才会考虑合并。

A smaller Auto UV Max Angle means that fewer edges will pass the test. As a result, fewer UV shells will be merged and the number of Charts will increase. Conversely, a larger Auto UV Max Angle means that the merging algorithm will be more tolerant of angles between faces. More UV shells are likely to be merged, the result of which will likely be fewer UV shells and therefore fewer Charts. As with the Auto UV Max Distance, if unsuitable edges are combined due to overly wide tolerances, distortion may occur in the final lightmaps UVs.
更小的自动UV最大角度意味着更少的边会通过测试。因此,将会有更少的UV shells被合并,图表的数量将会增加。相反,一个较大的自动UV最大角度意味着合并算法将更能容忍面与面之间的角度。更多的UV shells可能会被合并,其结果可能是更少的UV 组,因此更少的图表。与自动UV最大距离一样,如果不合适的边由于过大的容差而组合在一起,则在最终的光照图UVs中可能出现失真。

  • If HouseBig02 is not selected in the Hierarchy window, select it.
    Hierarchy 窗口下选择HouseBig02
  • Navigate to the Lighting window (Window > Lighting) and select the Object tab.
    打开光照窗口,选择 Object 页签
  • Set the value of Auto UV Max Angle to 0.
    把自动UV最大角度调到最0

When we look at the Preview area of the Lighting window, we can see that the number of Charts created is unacceptably high. This is because we are only allowing a deviation of 0 degrees or less between faces before they are considered for merging. This almost certainly means that no UV shells will pass the test and therefore many Charts will remain following this merging process.
当我们查看光照窗口的预览区域时,我们可以看到创建的图表的数量是不可接受的高。这是因为在考虑合并条件是,我们只允许在不同的面之间有0度或更低的偏差。这几乎肯定意味着,没有UV shells会通过测试,因此许多图表将在这个合并过程中继续存在。

Without some tolerance, a low Auto UV Max Angle will result in an excessive number of Charts.
如果没有一些容忍公差,低的自动UV最大角度将导致大量的图表。

Next we will try increasing the Auto UV Max angle.
接下来我们将尝试增加自动UV的最大角度。

  • If HouseBig02 is not selected in the Hierarchy window, select it.
    如果不在Hierarchy 窗口中选中HouseBig02 ,请选择它。
  • Navigate to the Lighting window (Window > Lighting) and select the Object tab.
    导航到Lighting 窗口(Window > Lighting)并选择Object选项卡。
  • Slowly increase the value of Auto UV Max Angle, observing effects of each change in the Preview area of the Lighting window.
    慢慢增加自动UV最大角度的值,观察每个变化在Lighting 窗口的预览区域的效果。

We can see that the number of Charts decreases as the value goes up. This is because the angle permitted between mesh faces considered for merging is more tolerant. More UV shells pass the test and will be merged. Consequently, the number of lightmap UV shells is reduced and the number of corresponding Charts decreases.
我们可以看到,随着值的增加,图表的数量会减少。这是因为在考虑合并的网格面之间允许的角度更加宽容。更多的UV组通过测试,并将被合并。因此,光照图UV组的数量减少了,相应的图表数量也减少了。

Increasing the Auto UV Max Angle can help reduce Charts - particularly on objects with rounded surfaces.
增加自动 UV最大角度可以帮助减少图表——特别是在有圆形表面的物体上。

An Auto UV Max Angle of 93 yields good results with our example object, HouseBig02.
自动 UV最大角度设为 93,与我们的示例对象HouseBig02有良好的结果。

  • If HouseBig02 is not selected in the Hierarchy window, select it.
    如果在Hierarchy 窗口中没有选择HouseBig02 ,请选择它。
  • Navigate to the Lighting window (Window > Lighting) and select the Object tab.
    导航到Lighting 窗口(Window > Lighting)并选择 对象选项卡。
  • Set the value of Auto UV Max Angle to 93
    将自动UV最大角的值设置为93

Notice how the number of Charts is reduced in the Preview area of the Lighting window following a brief precompute.
请注意,在一个简单的预计算之后,在照明窗口的预览区域中,图表的数量是如何减少的。

The Charting preview for HouseBig02 following some optimisation of its unwrap settings.
在对其展开的设置进行一些优化之后,HouseBig02 的图表预览

At this stage, our optimized unwrap settings can be taken back into the working Scene.
在这个阶段,我们的优化的打开的设置可以被带回到工作场景中。

  • If HouseBig02 is not selected in the Hierarchy window, select it.
    如果在Hierarchy 窗口中没有选择HouseBig02 ,请选择它。
  • In the Inspector panel, locate the MeshRenderer component and click the cog icon in the top right of its display.
    在Inspector 面板中,定位MeshRenderer组件,并单击其显示在右上方的齿轮图标。
  • Click Copy Component.
    点击复制组件。
  • Open the LightingTutorialStart Scene.
    打开LightingTutorialStart场景。
  • Find all the objects in the Hierarchy named HouseBig02.
    在Hierarchy中找出名字为HouseBig02的所有对象。
  • Hold down Ctrl (Cmd on the Mac) and click each of the HouseBig02 GameObjects in the Hierarchy window to select them all.
    按住Ctrl(Mac上的Cmd),然后点击Hierarchy 窗口中的每个HouseBig02 游戏对象 来选择它们。
  • Navigate to the Lighting window (Window > Lighting) and select the Object tab.
    导航到Lighting 窗口((Window > Lighting)并选择Object选项卡。
  • Select the the cog icon in the top right.
    选择右上方的齿轮图标。
  • Choose Paste Component Values to apply the settings you previously copied.
    选择Paste 组件值来应用您之前复制的设置。

    Copy Component is an easy way to take your unwrap settings back to the main Scene.
    复制组件是一种简单的方法,可以将展开的设置返回到主场景。

The modest savings these settings give us can add up to much more significant optimisations when applied across a Scene of several hundred objects.
这些设置所带来的适度节省,可以在几百个对象的场景中应用到更重要的优化中。

Unwrap settings: per-instance or per-Prefab?

展开设置:每个实例还是预制体?

Unwrap settings can be stored in a Prefab by applying them to any Static MeshRenderer component that lives within that Prefab’s hierarchy. Alternatively, unwrap settings can also be applied to individual GameObjects within the Scene. Unwrap settings applied to an instance of a Prefab in a Scene will override the settings stored within the Prefab. This way of working offers us some useful approaches to setting up Scene lighting.
展开的设置可以存储在一个预制体中,将它们应用到任何静态的MeshRenderer组件中,这些组件位于Prefab的hierarchy结构中。另外,展开的设置也可以应用于场景中的单个GameObjects 。在场景中应用于一个预制体的实例的展开设置将覆盖存储在预制件中的设置。这种工作方式为我们提供了一些为设置场景光照有用的方法。

It is often useful to configure a default unwrapping and lighting setup for your Prefabs. If the Prefabs are to be instantiated numerous times, it can save effort to have the unwrapping for that object preconfigured rather than having to specify this repeatedly throughout the Scene.
为您的预制体配置默认的展开和光照设置通常是很有用的。如果要多次实例化Prefabs,它可以节省大量的工作,以便预先配置该对象的展开,而不必在整个场景中重复指定这一点。

On the other hand, it is frequently desirable to configure lighting settings based on the context in which an object is used within the overall Scene. For example, if an instance of a Prefab will be seen up close within the playable area then it makes sense to use higher fidelity setting on that instance. If the instance of the Prefab is far away, then it would not make sense to use our lighting budget maintaining the same settings. Here, we would likely want to lower the quality of our lightmaps and use more aggressive stitching parameters in our unwrap.
另一方面,通常需要根据在整个场景中使用对象的上下文来配置光照设置。例如,如果一个预制件的实例在可玩区域内被发现,那么在该实例上使用更高的保真度是有意义的。如果预制件的实例离得很远,那么使用我们的照明预算来维护相同的设置是没有意义的。在这里,我们可能想要降低我们的lightmaps的质量,并在我们的展开中使用更激进的拼接参数。

The ability to configure default settings that suitable for most use cases and then override these settings in special cases can be very useful. In the case of this lighting tutorial, we will be applying our settings per-instance, in the Scene.
能够配置适合大多数实例的默认设置,然后在特殊情况下覆盖这些设置,这是非常有用的。在这个光照教程的例子中,我们将在场景中应用我们的设置在每个实例中。

Applying unwrap settings throughout the Scene

在整个场景中应用展开设置

It is time to start applying what we have learned about Unity’s automatic unwrapping algorithm to the remaining Static geometry within the LightingTutorialStart Scene. Working systematically, it should not take long to set up the Scene for significantly improved precompute times.
现在是时候开始将我们所学到的关于Unity的自动展开算法应用到LightingTutorialStart场景中剩下的静态几何体中。系统地工作,不需要花很长时间就可以建立一个显著提高预计算时间的场景。

  • Open the LightingTutorialStart Scene included in the example project.
    打开示例项目中包含的LightingTutorialStart场景。
  • In the Hierarchy window, select the top GameObject found under Environment > Structures.
    在Hierarchy 结构窗口中,选择在Environment>Structures 结构下找到顶部的游戏对象。
  • Copy the GameObject to an empty Scene.
    把游戏对象复制到一个空的场景中。

At this point we should apply what we have learned about the unwrap parameters and feel free to experiment with different values. Remember to use the UV Charts Scene draw mode in combination with the Charting mode of the Preview area of the Lighting window. This will enable us to find the right balance between lightmap distortion and the number of Charts required.
在这一点上,我们应该应用我们已经学过的关于展开参数的知识,并且可以自由地尝试不同的值。请记住使用场景UV图表绘制模式与光照窗口的预览区域的图表模式相结合。这将使我们能够在光照图扭曲和所需的图表数量之间找到正确的平衡。

The LightingTutorialOptimal Scene can be used as a reference in cases where we are unsure. Note that in some cases it may even be unnecessary to change the default unwrap values at all. The default values may actually provide the best outcome.
在我们不确定的情况下,LightingTutorialOptimal 场景可以作为参考。注意,在某些情况下,甚至没有必要更改默认的展开值。默认值实际上可能提供最好的结果。

  • Experiment with different values for the unwrap parameters until a balance is reached between number of Charts and lightmap distortion.
    对展开参数的不同值进行试验,直到在图表数量和光照图扭曲之间达到平衡。
  • Copy the settings, return to the LightingTutorialStart Scene and paste them into all other instances of the same GameObject. Multi-selecting all the corresponding objects in the hierarchy will enable you to use Paste Component Values to quickly apply the settings across multiple objects.
    复制设置,返回到LightingTutorialStart场景,并将它们粘贴到同一个GameObject的所有其他实例中。在层次结构中多选所有对应的对象将使您能够使用粘贴组件值快速地在多个对象上应用这些设置。
  • Repeat this process for every uniquely named GameObject in the Hierarchy view.
    在Hierarchy 视图中为每一个唯一命名的GameObject重复这个过程。

Once all of the GameObjects under the Structures group have been optimized, move onto the remaining Static geometry under the Rocks group. Working methodically in this way, it should take no longer than a few minutes to set the unwrap values for all of the Static geometry within your Scene. The outcome of this manual preparation will be faster iteration when lighting the Scene and better performance at run time.
一旦Structures 组下的所有游戏对象都经过了优化,就移到Rocks 组下面的静态几何图形中。以这种方式有条不紊地工作,不需要花费几分钟的时间来设置场景中所有静态几何体的展开值。这个手动准备的结果将是在光照时更快速的迭代,在运行时更好的性能。

你可能感兴趣的:(Tutorials,Graphics,Unity,Graphics,图形渲染,教程,文档,笔记,Unity,Graphics,图形渲染,教程文档)