1. 程式人生 > >Unity Lighting - Lighting overview 照明概述

Unity Lighting - Lighting overview 照明概述

default pen can 發生 bsp 並且 更改 forms roc

Lighting overview

照明概述


In order to calculate the shading of a 3D object, Unity needs to know the intensity, direction and color of the light that falls on it.

為了計算3D物體的陰影,Unity需要知道落在它上面的光的強度,方向和顏色。

技術分享圖片

These properties are provided by Light objects in the scene. Different types of light emit their assigned color in different ways; some lights may diminish with distance from the source, and have different rules about the angle of light received from the source. The different types of light source available in Unity are detailed in

Types of light.

這些屬性由場景中的Light對象提供。不同類型的光以不同的方式發出其指定的顏色;有些燈可能會隨距離光源的距離而減少,並且對從光源接收到的光的角度有不同的規則。 Unity中提供的不同類型的光源詳見光源類型。

Unity can calculate complex, advanced lighting effects in various different ways, each suited to different use cases.

Unity可以以各種不同的方式計算復雜的高級照明效果,每種方法都適合不同的使用情況。

Choosing a lighting technique

選擇照明技術

Broadly speaking, lighting in Unity can be considered as either ‘realtime’ or ‘precomputed’ in some way and both techniques can be used in combination to create immersive scene lighting.

一般來說,Unity中的燈光可以被認為是“實時”或“預先計算”的,並且兩種技術都可以結合使用來創建逼真的場景照明。

In this section we will give a brief overview of what opportunities the different techniques offer, their relative advantages and individual performance characteristics.

在本節中,我們將簡要概述不同技術提供的機會,其相對優勢和個人性能特征。

Realtime lighting

實時照明

By default, lights in Unity - directional, spot and point, are realtime. This means that they contribute direct light to the scene and update every frame. As lights and GameObjects are moved within the scene, lighting will be updated immediately. This can be observed in both the scene and game views.

默認情況下,Unity中的燈光 - 方向,光點和點是實時的。這意味著他們為場景提供直接照明並更新每一幀。當燈光和GameObjects在場景內移動時,照明將立即更新。這可以在場景和遊戲視圖中觀察到。

Realtime LightsThe effect of realtime light alone. Note that shadows are completely black as there is no bounced light. Only surfaces falling within the cone of the Spotlight are affected.

實時燈單獨實時光的效果。請註意,陰影是完全黑色的,因為沒有反射光。只有聚光燈錐體內的表面受到影響。

Realtime lighting is the most basic way of lighting objects within the scene and is useful for illuminating characters or other movable geometry.

實時照明是在場景內對物體進行照明的最基本方式,對於照亮角色或其他可移動幾何圖形非常有用。

Unfortunately, the light rays from Unity’s realtime lights do not bounce when they are used by themselves. In order to create more realistic scenes using techniques such as global illumination we need to enable Unity’s precomputed lighting solutions.

很遺憾的是,來自Unity實時燈的光線在被自己使用時不會反彈。為了使用全局照明等技術創建更逼真的場景,我們需要啟用Unity的預計算照明解決方案。

Baked lightmaps

烘焙光照貼圖

Unity can calculate complex static lighting effects (using a technique called global illumination, or GI) and store them in a reference texture map called a lightmap. This calculation process is referred to as baking.

Unity可以計算復雜的靜態光照效果(使用稱為全局照明或GI的技術),並將它們存儲在名為光照貼圖的參考紋理貼圖中。這個計算過程被稱為烘焙。

When baking a lightmap, the effects of light sources on static objects in the scene are calculated and the results are written to textures which are overlaid on top of scene geometry to create the effect of lighting.

烘焙光照貼圖時,會計算場景中靜態對象的光源效果,並將結果寫入覆蓋在場景幾何圖形之上的紋理以創建照明效果。

技術分享圖片
Left: A simple lightmapped scene. Right: The lightmap texture generated by Unity. Note how both shadow and light information is captured.
左:簡單的光照貼圖場景。 右圖:由Unity生成的光照貼圖紋理。請註意如何捕獲陰影和光照信息。

These lightmaps can include both the direct light which strikes a surface and also the indirect light that bounces from other objects or surfaces within the scene. This lighting texture can be used together with surface information like color (albedo) and relief (normals) by the Shader associated with an object’s material.

這些光照貼圖既可以包含撞擊表面的直射光,也可以包含場景內其他物體或表面反射的間接光。這種照明紋理可以與表面信息一起使用,例如與物體材質關聯的著色器的顏色(反照率)和浮雕(法線)。

With baked lighting, these lightmaps cannot change during gameplay and so are referred to as ‘static’. Realtime lights can be overlaid and used additively on top of a lightmapped scene but cannot interactively change the lightmaps themselves.

隨著烘焙照明,這些光照貼圖在遊戲過程中不能改變,因此被稱為“靜態”。實時燈可以重疊並在光照貼圖場景上疊加使用,但不能交互式更改光照貼圖本身。

With this approach, we trade the ability to move our lights at gameplay for a potential increase in performance, suiting less powerful hardware such as mobile platforms.

通過這種方法,我們可以在遊戲中交換燈光,以提高性能,適合移動平臺等功能較弱的硬件。

See the Lighting window reference and Using precomputed lighting for more information.

Precomputed realtime global illumination

預先計算的實時全局照明

Whilst static lightmaps are unable to react to changes in lighting conditions within the scene, precomputed realtime GI does offer us a technique for updating complex scene lighting interactively.

雖然靜態光照貼圖無法對場景內照明條件的變化作出反應,但預先計算的實時GI確實為我們提供了一種交互式更新復雜場景照明的技術。

With this approach it is possible to create lit environments featuring rich global illumination with bounced light which responds, in realtime, to lighting changes. A good example of this would be a time of day system - where the position and color of the light source changes over time. With traditional baked lighting, this is not possible.

通過這種方法,可以創建具有豐富全局照明的照明環境,並帶有反射光,實時響應照明變化。一個很好的例子就是一天的時間系統 - 光源的位置和顏色隨著時間而變化。用傳統的烘烤照明,這是不可能的。

技術分享圖片
A simple example of time of day using Precomputed Realtime GI.
使用預先計算的實時GI的時間的簡單示例。

In order to deliver these effects at playable framerates, we need to shift some of the lengthy number-crunching from being a realtime process to one which is precomputed.

為了以可播放的幀速率傳遞這些效果,我們需要將一些冗長的數字從實時過程轉移到預先計算的過程。

Precomputing shifts the burden of calculating complex light behaviour from something that happens during gameplay, to something which can be calculated when time is no longer so critical. We refer to this as an ‘offline’ process.

預先計算將計算復雜光照行為的負擔從遊戲過程中發生的事情轉移到可以在時間不再那麽關鍵時計算出來的事情上。我們稱之為“離線”過程。

For further information, please see the lighting and rendering tutorial.

欲了解更多信息,請參閱照明和渲染教程。

Benefits and costs

好處和成本

Although it is possible to simultaneously use Baked GI lighting and Precomputed Realtime GI, be wary that the performance cost of rendering both systems simultaneously is exactly the sum of them both. Not only do we have to store both sets of lightmaps in video memory, but we also pay the processing cost of decoding both in shaders.\

雖然可以同時使用烘焙GI照明和預計算實時GI,但要小心同時渲染兩個系統的性能成本恰好是它們的總和。我們不僅需要將兩組光照貼圖存儲在視頻內存中,還要支付在著色器中解碼的處理成本。

The cases in which you may wish to choose one lighting method over another depend on the nature of your project and the performance capabilities of your intended hardware. For example, on mobile where video memory and processing power is more limited, it is likely that a Baked GI lighting approach would be more performant. On standalone computers with dedicated graphics hardware, or recent games consoles, it is quite possible to use Precomputed Realtime GI or even to use both systems simultaneously.

您可能希望選擇一種照明方法而不是另一種照明方法的情況取決於項目的性質以及預期硬件的性能。例如,在視頻內存和處理能力更加有限的移動設備上,烘焙GI照明方法可能更具性能。在具有專用圖形硬件的獨立計算機或最近的遊戲控制臺上,可以使用預計算實時GI,甚至可以同時使用這兩種系統。

The decision on which approach to take will have to be evaluated based on the nature of your particular project and desired target platform. Remember that when targeting a range of different hardware, that often it is the least performant which will determine which approach is needed.

必須根據您的特定項目的性質和期望的目標平臺來評估采取哪種方法。請記住,當瞄準一系列不同的硬件時,通常這是決定哪種方法是需要的性能最差的。

See also: Light Troubleshooting and Performance

來源: https://docs.unity3d.com/560/Documentation/Manual/LightingInUnity.html

Unity Lighting - Lighting overview 照明概述