1.基本參數與使用
1.1 常規介紹
使用預計算光照需要在Window/Lighting面板下找到預計算光照選項,保持勾選預計算光照並保證場景中有一個光照靜態的物體
此時在編輯器內構建后,預計算光照開始生效。
相關的文章有很多,unity官方有一系列文章不錯:
https://unity3d.com/cn/learn/tutorials/topics/graphics/introduction-precomputed-realtime-gi
在Lighting面板的Scene頁簽下可以設置全局光照的整體參數,這個是疊加在基本值上的屬性
並且你也可以設置統一的光照參數LightmapParameters。這里不多說了
唯一需要注意是分辨率設置
在1單位=1米的情況下,室內場景是2-3,室外場景是0.5-1。
texels是PRGI里的單位,具體unity這篇文章有講解:https://unity3d.com/cn/learn/tutorials/topics/graphics/understanding-charts?playlist=17102
在Lighting面板的Object頁簽下,可以對單獨對象設置光照屬性,這個比較重要
這里說一下光照參數:
Scale In Lightmap - 由於預計算光照使用的不是Lightmap,所以這個選項在PRGI中似乎是無效的(測了下,似乎是)
Important GI - 用於標識是否是重要物體,對於自發光物體可以增加它的亮度,確保一些物體可以被其照亮。(Make all other objects dependent upon this object.Useful for objects that will be strongly emissive to make sure that other objects will be illuminated by)
Advanced Parameters - 對光照進行單獨的高級設置,會鏈接到LightmapParameters文件.一會單獨說
Preserve UVs - 勾選后可以保持原有UV,不夠選uv則會受到改變。
但需要注意自動UV只有在一些特殊情況下才會改變原有uv的形態,如果原有uv本身沒有問題,還會保持原狀
Ignore Normals - 和手動配置的uv有關,如果出現一些錯誤情況可以勾選該選項重新烘培。(Do not compare normals when detecting charts for realtime gi.
this can be necessary when using hand authored uvs to avoid unnecessary chart splits.)
Min Chart Size - 有兩個選項,2和4,4(Stitchable)是默認狀態,如果為了速度可以選擇2(Minimumu),但會有效果缺失。
1.2 LightmapParameters
使用LightmapParameters可以將光照參數對單個對象進行單獨覆寫
創建一個LightmapParameters在Assets->Create->Lightmap Parameters
然后在Lighting的Object頁簽下選擇相應的LightmapParameters進行設置
來看一下LightmapParameters
這里只看預計算GI的相關選項
Resolution
Realtime lightmap resolution in texels per world unit.this value is multiplied by the realtime resolution in the
lighting window to give the output lightmap resolution.this should generally be an order of magnitude less than what is
common for baked lightmaps to keep the precompute timemanageable and the performance at runtime acceptable.
Note that if this is made more fine-grained,then the irradiance budget will often need to be increased too,
to fully take advantage of this increased detail.
這個分辨率是每世界單位的texels值,他乘以原始分辨率的值,如上圖的測試,值越高則分辨率越高
注意如果需要更多的粒度,irradiance輻照度也需要適當增加才行。
經過實際測試,這個值是數值越大越精確,烘培速度也越慢
並且這個參數也其他的參數是互相影響的,這相當於一個整體調節吧。
Cluster Resolution
the ratio between the resolution of the clusters with which light bounce is calculated and the resolution of the output lightmaps that sample from these.
可以叫做光照集群,或者叢集?
具體看unity這篇文章
https://unity3d.com/cn/learn/tutorials/topics/graphics/understanding-clusters
具體大意是,每一個Cluster塊都是儲存光照信息的具體單元,通過這些單元所存放信息的插值,得到最終效果
所以Cluster塊越大越不精確,速度也就越快,反之精確度也就越高。
這個應該和Resolution一樣,是乘以的這個值,也是值越大越精確
Irradiance Budget
The amount of data used by each texel in the output lightmap.specifies how fine-grained a view of the scene an output texel has. small values mean more averaged out lighting,since the light contributions from more clusters are treated as one.affects runtime memory usage and to a lesseer degree runtime cpu usage
輻照度預算,會被應用到texel當中,小的值可以得到更平均的光照,並且這個值會影響到運行時內存的占用和cpu占用
在Lighting Optimisation Tutorial這個demo當中,該值被設置的非常低。
Irradiance Quality
the number of rays to cast to compute which clusters affect a given output lightmap texel - the granularity of how this is saved is defined by the irradiance budget. affects the speed of the precomputation but has no influence on runtime performance.
輻照度品質,這個值只影響預計算光照的構建速度,對於運行時並無影響。
Backface Tolerance
the percentage of rays shot from an output texel that must hit front faces to be considered usable.
allows a texel it hit back faces(the texel is inside some geometry). in that case artfacts are avoided by cloning valid values from surrounding texels.for example,if backface tolerance is 0.0,the texel is rejected only if it sees nothing but backfaces. if it is 1.0, the ray origin is rejected if it has even one ray that hits a backface.
背面容差,允許射線穿過一些多邊形的內部采樣到背面,對於遮蔽處,給遮蔽物提高這個值可以得到更明亮的效果。
Modeling Tolerance
Maximum size of gaps that can be ignored for gi
模型容差,最大尺寸的間距能被GI忽略掉
這個值不能設置為0,不然會出錯,理論上值越小越不會被GI忽略,最終效果也就越好
這個值在光照不充足的情況下表現的尤為明顯,下面就因為這個參數太高而導致'壞面'問題:
Edge Stitching
If enabled,ensures hat uv charts(aka uv island) in the generated lighmaps blend together where they meet so there is no visible seam between them.
邊縫合。開啟后UV接縫會變得不明顯,如果想要故意留有接縫效果就關閉它
Is Transparent
If enabled,the object appears transparent during GlobalIllumination lighting calculations.Backfaces are not contributing to and light travels through the surface.This is useful for emissive invible surfaces.
這個參數好像只對自發光的物體有效,當勾選這個值這個物體會被當作透明的。自發光會穿透它。默認是不勾選。
System Tag
System are groups of objects whose lightmaps are in the same atlas.it is also the granularity at which dependencies are calculated.multiple systems are created automatically if the scene is big enough,but it can be helpful to be able to split them up manually for e.g. streaming in sections of a level. the system tag lets you force an object into a different realtime systrem even though all the other parameters are the same.
這個似乎是圖集ID,一般不需要設置。(我個人覺得,如果設置到一個全新的ID上,似乎可以解決某些UV問題)。
2.光照深入
官方有3個demo演示了unity5光照系統。
The Courtyard https://www.assetstore.unity3d.com/en/#!/content/49377
Corridor Lighting Example https://www.assetstore.unity3d.com/en/#!/content/33630
Lighting Optimisation Tutorial https://www.assetstore.unity3d.com/en/#!/content/73563
前兩個demo可以看作是光照參數的使用演示,第三個是真正指導如何對烘培速度進行優化
2.1 光照優化
以unity5.4版本為例,有兩個查看GI的重要指標
一個叫做UV Charts(https://unity3d.com/cn/learn/tutorials/topics/graphics/understanding-charts)
一個叫做Clustering(https://unity3d.com/cn/learn/tutorials/topics/graphics/understanding-clusters)
他們分別是不同的網格,在構建預計算光照的時候你可以看見構建中的這些信息。
UV Charts是光照uv自身的大小,包括Albedo,Emissive,Irradiance...之類的通道,都依據這個的大小
而Clustering可以翻譯成叢集,這里面每一塊包含了一些該區域的光照信息,最后通過這些塊與塊進行插值,得到具體的光照。
在修改參數的同時,不斷的比對這兩個通道,才能找到問題。一般遠處不可接近的物體分辨率會設置的低一些
在Lighting Optimisation Tutorial這個案例中,unity對遠山近處的房屋等用了不同的光照配置
經過優化,將7.5個小時的構建時間變為了2.25分鍾
這篇文章翻譯版的鏈接:http://forum.china.unity3d.com/thread-22730-1-4.html
2.2 Light Probe Group
光照探頭算不上新功能,但不管是烘培光照還是預計算光照都需要它
關於它的實現是一個叫做'球諧光照'的技術,這里不深入。
烘培光照因為無法儲存光照信息,通過光照探頭才能獲取到烘培光照。
而預計算光照中,則通過光照探頭儲存自發光信息和間接光照信息。
過於平均分布的光照探頭是不科學的,實際上應該在光源變化處的地方放置多的光照探頭
在沒有采樣需求的地方,放置少的探頭。
事實上光照探頭的效果提升是非常有限的,除了染色比較明顯。如果位置設置不好反而會得到奇怪的光照效果
穩妥起見建議平均分布或者代碼生成比較好。
說一下如何編輯光照探頭
選中光照探頭,點擊編輯圖標即進入編輯模式
選中光照點,按Ctrl+D復制,拖拽,即可操作
雖然unity不支持動態的自發光物體,但通過光照探頭烘培保存的信息,動態的物體也可以受到自發光物體的影響
你也可以在場景中設置多組光照探頭,以方便編輯,最后他們都會生效
另外如果需要進一步提升光照構建速度,可以對橡木桶,石塊之類的小塊物件設置為非光照靜態物體
用光照探頭來處理其光照,減少烘培負擔,加快預計算光照構建時間。
2.3 LPPV - Light Prober Proxy Volume
這是unity5.4新加入的功能,對於大的物體和粒子對象,應當考慮使用LPPV
unity關於LPPV的文章:https://blogs.unity3d.com/cn/2016/02/03/light-probe-proxy-volume-5-4-feature-showcase/
你可以設置成手動指定LPPV的大小,也可以設為自動大小,自動大小將會自動匹配。
和反射探頭一樣,可以設置更新模式,比如每一幀都更新或是由腳本控制
LPPV必須在有光照探頭的情況下放置
這里演示如何給粒子添加LPPV
1.首先保證場景中分布有光照探頭
2.粒子需要使用自定義shader,並且通過ShadeSHPerPixel拿到一些特殊光照信息
具體看那篇unity的文章,這里列出關鍵部分
fixed4 frag(v2f i) : SV_Target { half3 currentAmbient = half3(0, 0, 0); half3 ambient = ShadeSHPerPixel(i.worldNormal, currentAmbient, i.worldPos); fixed4 col = _TintColor * i.color * tex2D(_MainTex, i.texcoord); col.xyz = ambient; UNITY_APPLY_FOG_COLOR(i.fogCoord, col, fixed4(0,0,0,0)); // fog towards black due to our blend mode return col; }
然后配置好粒子,並為其指定LPPV,然后設置好采樣密度信息
完成:
暫時寫到這里,主要以學習和整理為主。Enlighten畢竟是使用廣泛的技術,相信unity會不斷完善這一塊。