1. 程式人生 > >Unity Graphics (Unity 圖形渲染 ) 官方教程文件筆記系列之十

Unity Graphics (Unity 圖形渲染 ) 官方教程文件筆記系列之十

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

本文件主要是對Unity官方教程的個人理解與總結(其實以翻譯記錄為主:>) 僅作為個人學習使用,不得作為商業用途,歡迎轉載,並請註明出處。 文章中涉及到的操作都是基於 Unity2017.3版本 參考連結:https://unity3d.com/cn/learn/tutorials/s/graphics

下面是將要介紹的章節,黑體是本次內容:

  • Introduction to Lighting and Rendering 介紹光照和渲染
  • Precomputed Realtime GI (Realtime Global Illumination)(10) 預處理實時全域性光照(10)
  • Rendering and Shading 渲染與著色
  • Cameras and Effects 相機與效果
  • Geometry in Unity 幾何體

瞭解叢集

Up to this point we have discussed Precomputed Realtime GI in terms of Charts. Reducing or otherwise optimizing the number of Charts in our Scene limits the number of operations such as lightmap compositing and packing required during the precompute. This benefits precompute performance and is a broad approach to reducing the size of the data set required by Unity’s Precomputed Realtime GI solution. 到目前為止,我們已經討論了基於圖表的預計算實時GI。減少或優化圖表的數量可減少在預計算期間所需的光照圖合成和打包等操作的數量。這有利於預計算效能,並且可以減少Unity預計算實時GI解決方案所需的資料集大小,是一種廣泛的方法。

Modifying Clusters is a finer-grained approach which will allow us to reduce the number of operations needed during later tasks in Unity’s precompute process. An additional benefit of reducing the number of Clusters is that run time performance will also be improved. 修改叢集是一種更細粒度的方法,它將允許我們在Unity的預計算過程中減少後面任務所需的操作量。減少叢集數量的另一個好處是,執行時效能也將得到改善。

When generating the Scene’s lighting solution using Precomputed Realtime GI, Unity simplifies the calculations required by working on a voxelized ‘proxy’ of the Static Scene. These voxels are called Clusters. Clusters are effectively surface patches (small tiles) mapped onto Static geometry which we use for lighting. Clusters are stored in a hierarchical relationships and are used for the complex irradiance calculations needed when precomputing Unity’s diffuse global illumination solution. Note that although Clusters are mapped in a similar way to Charts, the two are actually independent. 當使用預計算實時GI生成場景光照解決方案時,Unity使用靜態場景的體素化“代理”簡化了所需要的計算。這些體素被稱為叢集。叢集實際上是對映到我們用於照明的靜態幾何體的有效表面塊(小塊)。叢集被儲存在層次關係中,用於預計算Unity的漫反射全域性光照解決方案所需要的複雜輻照度計算。請注意,儘管叢集以類似於圖表的方式對映,但兩者實際上是獨立的。

這裡寫圖片描述 The Clustering Scene draw mode can be used to visualize the size of clusters generated by Unity’s Precomputed Realtime GI. 場景繪製模式:叢集 被用於視覺化叢集的大小,這是由Unity預計算實時GI生成的。

Clusters sample the albedo of the Static geometry to which they are mapped. Then, during the Light Transport stage of the precompute, the relationship between these Clusters is calculated so that light can be propagated throughout the Cluster network. Unity generates this low resolution approximation of the Static Scene in order to simplify the amount of lighting data which needs to be updated during run time in order to deliver global illumination at interactive frame rates with the limitations of current hardware. 叢集對它們對映的靜態幾何體的反射率進行取樣。然後,在預計算的光照傳輸階段,計算了這些叢集之間的關係,以便在整個叢集網路中傳播光照。Unity生成了近似靜態場景的低解析度,以簡化在執行時需要更新的光照資料量,以便在合適的幀率和限制在當前硬體水平的情況下提供全域性光照。 這裡寫圖片描述 Illustration showing how the lighting value of Cluster X is related to the value of nearby Clusters (Image courtesy of Geomerics). 插圖顯示了叢集X與附近叢集的值相關的照明值(圖片由Geomerics提供)。

Once the precompute has been completed, ambient (skybox) lighting along with light positions, intensities and colors can then be modified without needing to restart the precompute process. These lighting changes will bounce and permeate throughout the Cluster network, taking into consideration the underlying albedo and emission of the Scene’s materials in the eventual output. 一旦預計算完成,環境光(天空盒)伴隨光的位置、強度和顏色就可以被修改,而且不需要重新啟動預計算過程。這些光照變化將在整個叢集網路中反射和透射,在最終輸出時,還要考慮到場景材質本來的漫反射和自發光。

Following this initial bounce, updated lighting results can then be applied to the Clusters themselves. Following each iteration, lit Clusters will be sampled into the corresponding lightmap texture before finally being used by shaders within the Scene. 在最初的反射之後,更新的光照結果可以應用到叢集本身。隨著每次迭代,在最終被場景中的著色器使用之前,叢集將被取樣到相應的光照紋理中。

As this process is performed asynchronously on the CPU, the time it takes to refresh the global illumination solution is bound by the number of available worker threads. If needed, the amount of worker threads can be controlled using the ‘CPU Usage` setting found in the Lighting window. 由於這個過程是在CPU上非同步執行的,更新全域性光照解決方案所需的時間是由可用的工作執行緒的數量有關的。如果需要,可以使用在光照視窗中找到的“CPU使用”設定來控制工作執行緒的數量(未發現設定項)。

這裡寫圖片描述 The Lit Clustering Scene draw mode shows the Clusters once light has been bounced throughout the Cluster network. 場景繪製模式:光照叢集 顯示了一旦光照在整個叢集網路中被反射時的叢集。

Clusters can be visualized using the Clustering or Lit Clustering Scene draw mode. Using Clustering, the Scene will be overlaid with a diagnostic pattern made up of multicolored squares. The size of each square represents the size of a Cluster when mapped on to the corresponding Static geometry. Each unique color represents a different Cluster within the Scene. Similarly, the Lit Clustering Scene draw mode shows these Clusters once lighting has been bounced throughout the Cluster network and the results written back to the Clusters. 叢集可以使用叢集或光照叢集場景繪製模式進行視覺化。使用叢集化,場景將被由彩色方塊組成的特徵模式覆蓋。當對映到相應的靜態幾何體時,每個正方形的大小表示一個叢集的大小。每一種獨立的顏色代表著場景中不同的叢集。類似地,光照叢集場景繪製模式顯示,一旦光照在整個叢集網路中被反射,結果會被寫入到叢集中。

Reducing the number of Clusters largely determines how quickly this update occurs and, as a consequence, how interactive Unity’s Precomputed Realtime GI appears on your target platform. More importantly, for the purposes of this tutorial, reducing the number of clusters will improve the time it takes to precompute your lighting. As a result, iteration speeds when lighting your Scene will also improve. We will move onto techniques for reducing the number of Clusters in the following section of the tutorial. 減少叢集數量在很大程度上決定了更新生成的速度,從而決定了互動式Unity的實時GI在目標平臺上的顯示速度。更重要的是,對於本教程的目的,減少叢集的數量將減少預計算光照所需的時間。因此,當光照場景時,迭代速度也會提高。在本教程的下一節中,我們將討論減少叢集數量的技術。