字幕列表 影片播放 列印所有字幕 列印翻譯字幕 列印英文字幕 Lights. 本章介紹光源 Just like the real world, in Unity 就像在真實世界一樣,在Unity裡 我們用光來照亮我們的場景 we use lights to illuminate our scenes. 沒有光源就甚麼都看不到 Without lights nothing would be visible 廣義來說,Unity有動態光源(Dynamic) 和烘焙光源(Baked lighting)兩種類型光源 to the cameras in our scene. 動態光源是在遊戲裡即時運算的光源 只要增加光源物件到場景即可使用 Broadly there are two types of lighting in Unity 烘焙光源預先運算好光照並存在貼圖裡 dynamic and baked lighting. 將處理好的光照貼圖 貼在場景上物件可以提升效能 Dynamic lighting is calculated in 更多關於烘焙和動態光源的內容 請參考官方文件 real time while our game is running. 我們利用燈光元件在場景裡打光 This can be achieved simply by adding lights to our scene. 相同於Unity其他元件 燈光元件也是依附在物件上 Baked lighting is calculated offline 我們可利用Transform工具 在場景內移動光源 and saved to a texture. 燈光元件有四種不同的類型 These lighting texture maps are then applied 點光源(Point)、定向光源(Directional) 投射燈(Spot Light)和區域光源(烘焙限定) to the baked objects in the scene 每一種光源在遊戲裡的效果都截然不同 for improved performance. 點光源效果就像燈泡 For more information on baked and dynamic 點光源從他的位置投射光源到場景物件上 lighting see the lesson linked below. 這種光源平均投射到所有的方向 所以旋轉角度對它沒有影響 To light our scene we use the Light component. 定向光源效果像是太陽 Like all components in Unity 根據定向光源的方向與角度 投射到所有場景物件 the light component is attached to a game object. 它在場景的位置是無關緊要的 We can move the light within our scene 投射光效果像是手電筒或車頭燈 using the game objects transform. 投射光源根據它們的方向和角度 投射出一個圓錐並照亮裡面的物件 The light component has four different types of lights. 所以光的位置和角度對投射光都有影響 The Point Light, the Directional Light, 區域光源(Area light)只在烘焙光照貼圖時有作用 the Spot Light and for baked 區域光源從一個矩平面的一面 投射並反射到四面八方的靜態物件 lighting only, the Area Light. 除了這四種主要光源以外 Each of these types behave completely differently 還有另外兩種可以影響照明的物件 環境光(Ambient light)和發光材質(Emissive material) in the way they effect the look of our game. 環境光控制場景的整體照明 The point light behaves like a bare light bulb. 環境光會和動態光源及烘焙光源一起運算 The point light illuminates objects in the scene 建議把環境光設為黑色,只用場景內 的照明工具比較好全面控制照明 based on the light's position in the scene. 發光材質可從材質的Shader裡選self-illumin 並調整Emission大小來控制 Rotation has no influence on the light 發光材質只會被烘焙貼圖運算 as this light shines equally 更多資訊請參考官方教學 in all directions. 光源有幾個屬性供我們設置 The directional light behaves like the sun. 範圍(Range)讓我們定義光源 從物件的中心可以照多遠 Directional lights effect all the objects in the scene 範圍屬性只對點光源和投射燈有作用 lighting them based on the direction of the light 如果類別是投射燈 我們也可以設定Spot Angle屬性 set by the game object's rotation. 投射角度(Spot Angle)影響投射光源錐體的斜度 Position in the scene is irrelevant. 顏色(Color)控制光源的顏色 Spot lights behave like a flashlight 場景內表示光源的圖示也會跟著同步改顏色 or headlamps on a car. 強度(Intensity)控制光的亮度 這和範圍所影響的不同 They point in a direction based 當想要對一個場景打光時,組合這些 屬性建立一個有效的光源是必要的 on their transform's rotation 燈光會因為調高強度和範圍而顯得更亮 因為它們是用不同的原理來照亮場景 and illuminate all objects within a cone. 燈光除了照明功能之外也可以製作一些效果 So spot lights respond to both 陰影、閃光、光暈和叫做投影遮罩的東西 rotation and position. 投影遮罩(Cookie)的功能 就像是一個虛擬的遮罩或標示 Area lights only work when baking a light map. 擋在光源前面用來建立陰影圖案 Area lights shine in all directions to 投影遮罩使用有Alpha的貼圖 來產生投射用的陰影圖案 one side of a rectangular plane. 當使用定向光和投射光時 投影遮罩必須是一張2D貼圖 In addition to these four main types of lights 當使用點光源時 投影遮罩必須是一個方塊貼圖(Cube Map) there are two other items that can 這是有它的道理 influence the lighting in the scene. 因為定向光和投射光是有方向性的 但點光源是沒有方向性的 Ambient light and emissive materials. 當使用定向光源時 可以縮放場景裡投影的遮罩圖案大小 Ambient light controls global 投影遮罩無法應用在區域光源裡 non directional lighting in the scene. 當用烘焙製作光照貼圖時 Ambient light works with both dynamic 烘焙只會運算投射光的投影遮罩 點光源和定向光的投影遮罩會被忽略 and baked lighting. 接下來介紹陰影 For complete control set the 當燈光裡的陰影啟用時 有兩種陰影可以選擇 ambient light to black 硬式陰影(Hard)和軟式陰影(Soft) and use only the lighting in the scene. 硬式陰影效能比較好 Emissive materials are created by 軟式陰影在真實感比較有說服力 但比較耗效能 setting the emission property in an 陰影有幾個屬性供我們設置 appropriate self-illuminating shader. 強度(Strength)設定陰影的黑暗度 Emissive materials work only with baked lighting. 調整這個值符合場景要的感覺 For more information see the lessons link below. 最大強度 1 一般來說是太多了 There are several properties that let us 解析(Resolution)就是陰影品質設定 customise the light. 預設情況下,燈光會使用Use Quality Settings設定 每盞燈光都可以單獨調整這個設定 Range determines how far a light is 更多關於品質的設定(Quality Setting) 請參閱相關章節 emitted from the centre of the game object 偏移(Bias)控制陰影的偏移量來最佳化陰影 holding the light component. 偏移用來設定物件開始顯示陰影的距離 Range only works with point and spot lights. 數值太低會讓作品假假的 但數值太高又會讓物件有懸浮的感覺 When we have spot selected as our light type 當定向光源加上軟式陰影時會多兩個額外設定 we also have access to the 柔軟度(Softness)和柔軟淡出(Softness fade) spot angle property. 柔軟度控制陰影的柔邊 柔軟淡出控制陰影柔邊的淡化 Spot angle determines the angle of the cone 更多關於燈光的內容請參閱官方文件 used by the spot light in degrees. Draw Halo會在燈光周圍繪製光暈 燈光的範圍和強度都會影響光暈呈現 Colour will control the colour of the light. 預設光暈設定可以在Rander setting找到 Note the scene gizmo colour will change 要改變預設光暈設定要先取消Draw Halo 並增加一個Halo元件來取代 to match the colour property. 閃光很像光暈但是 它是模擬光通過光學玻璃產生的反射光暈 Intensity controls the brightness of the light 當有鏡頭光暈(Lens Flare)指定到欄位時 光源就會呈現鏡頭光暈 and this is independent of range. 光源設定裡只有強度對閃光有影響 When trying to light a scene, a combination 鏡頭光暈的元件可以指定在物件上 of all of these properties are needed 那樣的話光源上的Flare設定應該清除 否則鏡頭光暈就會被處裡兩次 to create effective lighting. 相機也必須指定一個 閃光層(Flare Layer)元件才會呈現閃光 Our lights may appear brighter as we 接下來是著色模式 increase both intensity and range. 有兩個不同的動態光源著色方法 But they both have different behaviours 頂點照明(Vertex lighting) 和像素照明(Per pixel lighting) in the way that they light our scene. 頂點照明通常是最快的 它會算出多少光要投射在物件的網格點上 As well as simple illumination 然後把光投射到網格表面 lights can also use a number of effects. 像素照明會計算螢幕上每個像素 因此較耗效能 Shadows, flares, halos 雖然像素照明比較慢 但它可以做到一些頂點照明無法達到的效果 and something called a Cookie. 法線貼圖、投影遮罩和即時陰影 只能用像素照明呈現 A cookie acts like a virtual mask 投射形狀處理和鏡面高光處理 在像素照明表現也比較好 or flag in front of the light 燈光對於著色速度有很大的影響 to create a patterned shadow. 像素照明的燈光數量 可以從Quality Settings裡面來設定 Cookies use the alpha channel of a texture 當PlayerSetting裡的Rendering path指定Forward時 to give the light a projected shadow pattern. Render mode這個參數可以明確的指定 Cookies must be a 2D texture 燈光是要用頂點照明還是像素照明來處理 when working with spot and directional lights. 重要(Important)會強制使用像素照明 Cookies must be a cube map 不重要(Not Important)會強制使用快速的頂點照明 when using a point light. 或球諧函數運算 This makes sense when you think about 更多關於著色模式和著色路徑的內容 請參閱官方文件說明 the fact that both spot and directional lights are shining in one direction and point lights are shining in all directions. When using directional lights there is an option to change the cookie's size, scaling the pattern in the scene. Cookies do not work with area lights. When using baked lighting cookies only work with spot lights and are ignored for baked point lights and baked directional lights. Shadows. There are two types of shadows available when casting shadows from a light. Hard and Soft shadows. Hard shadows are the most efficient. Soft shadows are often more convincing. But they're most expensive to render. When rendering shadows there are several options. Strength sets the value of the darkness of the shadow. Adjust this value until the shadow seems correct in the scene. Full strength, or the value of 1 is often too strong. Resolution is simply a quality setting. By default a light will use the value you set in quality settings. These values can be overridden here on a per light basis. For more information see the lesson on quality settings. Bias controls an offset value to optimise shadow rendering from any given light. Bias is a setting that effects how far from objects the shadows will start. Values that are too low will produce artefacts, but values that are too high will mean that the objects appear to be hovering. When using directional lights with soft shadows there are two additional settings. Softness and softness fade. The softness is how harsh the lines of the shadow will be and the softness fade is a measure of how far from the camera the soft shadows are drawn. For more information please see the documentation on lights linked below. Draw Halo will draw the default scene halo around the light. Halos respond to both the range and intensity of the light. Details for the default halo can be set in the scene's render settings. To override the default halo this setting should be left off and an individual halo component should be used instead. A flare is similar to a halo but imitates a bright light source seen through optical glass. When a flare asset is loaded in to the flare slot the light will render using a lens flare. Flares only respond to the intensity of the light. A lens flare component can be attached directly to the game object but then the flare property on the light should remain empty or there will be two flares rendered on the light. A flare layer component must be attached to a camera for that camera to render a flare element. Render Mode. There are two different methods of rendering dynamic lights using vertex lighting and using per pixel lighting. Vertex lighting is usually the fastest and calculates the scene's lighting at the vertices of an objects mesh. The lighting is then interpolated over the surface of the mesh. Per pixel lighting is calculated at every screen pixel which is more expensive. While pixel lighting is slower to render it does allow for some effects that are not possible with vertex lighting. Normal mapping, light cookies and real time shadows are only rendered for pixel lights. Spot light shapes and specular highlights are much better when rendered in pixel mode as well. Lights have a big impact on rendering speed. The number of pixel lights can be limited in the quality settings by using the pixel light count property. When you are in the forward rendering path render mode gives explicit control over whether a light should be rendered as a vertex or pixel light. Important will force the light to be rendered per pixel and not important will force the light to be rendered in a faster mode using per vertex or spherical harmonics. For more information on render mode and render path see the documentation link below.
B1 中級 中文 英國腔 燈光 物件 場景 投影 設定 像素 燈光 - Unity官方教程 (Lights - Unity Official Tutorials) 96 8 朱瑛 發佈於 2021 年 01 月 14 日 更多分享 分享 收藏 回報 影片單字