SlideShare ist ein Scribd-Unternehmen logo
1 von 29
Downloaden Sie, um offline zu lesen
電子工程系應 用 電 子 組
電 腦 遊 戲 設 計 組
Unity遊戲程式設計(09)
3D物件與光源設定
吳錫修
March 7, 2017
shapethefuture
 選單命令GameObject>3D Object內可找到內建3D物件
 Cube 立方體
 Sphere 球體
 Capsule 膠囊
 Cylinder 圓柱體
 Plane 平面
 Quad 四邊形
內建3D物件
2 Wu, ShyiShiou Dept. of E.E., NKUT
Plane
Quad
Cylinder
Capsule
Cube Sphere
shapethefuture
 選單命令Assets> Import Package> Effects
 勾選LightCookies
 勾選LightFlares
滙入光源素材
3 Wu, ShyiShiou Dept. of E.E., NKUT
shapethefuture
 由Transform屬性調整物件位置 (Position)、角度 (Rotation)、及大
小 (Scale)
場景3D座標系統
4 Wu, ShyiShiou Dept. of E.E., NKUT
shapethefuture
 光源決定遊戲場景明暗與氛圍,使場景中的物體呈現出正確的顏色,
及產生陰影效果
 選單命令GameObject>Light內可找到光源物件
 Directional Light 方向光
 Point Light 點光源
 Spotlight 聚光燈
 Area Light 區域光
 場景預設會加入方向光
設置光源 1/5
5 Wu, ShyiShiou Dept. of E.E., NKUT
shapethefuture
 Directional Light (方向光)
 ⼀個在無限遠處的光源,平行的照射在場景中,會影響場景中的所有物
件,類似自然界中日光的照明效果
 最不耗費圖形處理器資源的光源
 因為是無限遠處的光源,Position屬性不會影響照射效果
設置光源 2/5
6 Wu, ShyiShiou Dept. of E.E., NKUT
shapethefuture
 Point Light (點光源)
 ⼀個向四面八方發出光線,影響其範圍內的所有物件,類似燈泡的照明
效果
 點光源較耗用圖形處理器資源
設置光源 3/5
7 Wu, ShyiShiou Dept. of E.E., NKUT
shapethefuture
 Spotlight (聚光燈)
 朝某⼀方向在錐形範圍照射光線,位於錐形範圍內的物件會受到光線照
射,類似舞台上的探照燈
 聚光燈較耗用運算資源
設置光源 4/5
8 Wu, ShyiShiou Dept. of E.E., NKUT
shapethefuture
 Area Light (區域光)
 Area Light,俗稱面燈。由矩形單⼀面射出光線
 不能產生即時光照的效果,僅能用於光影貼圖烘焙 (Light baking)
設置光源 5/5
9 Wu, ShyiShiou Dept. of E.E., NKUT
shapethefuture
 Type 選擇光源類型
 Spot 聚光燈
 Directional 方向光
 Point 點光源
 Area (baked only) 區域光
 Baking 光照計算方式
 Realtime 即時計算光照效果
 Baked 執行光影貼圖時計算光照效果
 Mixed 混用
 Range 光線照射距離,適用點光源與聚光燈
 Spot Angle 聚光燈角度 (1~179),控制光源錐形範圍,適用聚光燈
光源屬性 1/5
10 Wu, ShyiShiou Dept. of E.E., NKUT
shapethefuture
 Color 燈光顏色,預設為白光
 Intensity 光源強度,聚光燈與點光源預設
值為1,方向光預設值為0.5
 Cookie 光源加上⼀個有 Alpha 通道的紋
理光罩
 Cookie Size 縮放Cookie光罩,適用方向光
光源屬性 2/5
11 Wu, ShyiShiou Dept. of E.E., NKUT
shapethefuture
 Shadow Type 陰影類型
 No Shadow 關閉陰影
 Hard Shadow 輪廓清晰的影子
 Soft Shadow 柔邊輪廓的影子,較耗運算資源
 Strength 陰影強度,1最明顯,0消失
 Resolution 陰影解析度
 Use Quality Settings 套用Edit>Project Settings>Quality設定
 Low Resolution 低解析度
 Medium Resolution 中解析度
 High Resolution 高解析度
 Very High Resolution 超高解析度
光源屬性 3/5
12 Wu, ShyiShiou Dept. of E.E., NKUT
shapethefuture
 Bias 微調陰影的位置與陰影定義點,避免產生shadow acne情
形。太大的Bias值可能導致GameObject附近的陰影區域
被錯誤地點亮,而造成⼀個斷開的陰影,使GameObject
看起来好像是離開地面
 Normal Bias 微調陰影的位置與陰影定義點
 Shadow Near Plane 設定渲染陰影光源距離,光距離GameObjects
小於設定值時不會投射陰影
光源屬性 4/5
13 Wu, ShyiShiou Dept. of E.E., NKUT
shadow acne bias值太大
shapethefuture
 Draw Halo 開啟光源之光暈效果
 Flare 設定光源眩光效果
 Render Mode 光源渲染模式
 Auto 根據附近燈光的亮度和專案Quality設定,在運行時
決定渲染方式
 Important 逐像素進行渲染,可以得到最明顯的視覺效果
 Not Important 快速渲染
 Culling Mask 設定光源影響的圖層
光源屬性 5/5
14 Wu, ShyiShiou Dept. of E.E., NKUT
shapethefuture
 新增場景,檔名Lighting
 Directional Light
 Intensity = 0.3
 Main Camera
 Position (x, y ,z) = (0, 2, -9)
 Rotation (x, y, z) = (5, 0, 0)
 選單命令GameObject>3D Object>Plane
 Position (x, y, z) = (0, -1, 0)
 選單命令GameObject>3D Object>Sphere
 Position (x, y, z) = (0, 0, 0)
 Scale (x, y, z) = (2, 2, 2)
光源設定練習 1/3
15 Wu, ShyiShiou Dept. of E.E., NKUT
shapethefuture
 選單命令GameObject>Light>Point Light
 Position (x, y, z) = (4, 3, 0)
 Color = red
 選單命令GameObject>Light>Spotlight
 Position (x, y, z) = (4, 4, 0)
 Rotation (x, y, z) = (125, -90, 0)
 Spot Angle = 50
 Intensity = 2
 Shadow Type = Soft Shadows
光源設定練習2/3
16 Wu, ShyiShiou Dept. of E.E., NKUT
shapethefuture
 測試結果
光源設定練習3/3
17 Wu, ShyiShiou Dept. of E.E., NKUT
shapethefuture
 新增場景,檔名Flare
 Directional Light
 Intensity = 0.3
 Flare = Sun
 Main Camera
 Position (x, y ,z) = (0, 2, -9)
 Rotation (x, y, z) = (5, 0, 0)
 選單命令GameObject>3D Object>Plane
 Position (x, y, z) = (0, -1, 0)
 選單命令GameObject>3D Object>Sphere
 Position (x, y, z) = (0, 0, 0)
 Scale (x, y, z) = (2, 2, 2)
眩光效果練習 1/4
18 Wu, ShyiShiou Dept. of E.E., NKUT
shapethefuture
 選單命令GameObject>Light>Point Light
 Position (x, y, z) = (4, 3, 0)
 Color = red
 Flare = 50mmZoom
 選單命令GameObject>Light>Spotlight
 Position (x, y, z) = (4, 4, 0)
 Rotation (x, y, z) = (125, -90, 0)
 Spot Angle = 50
 Intensity = 2
 Shadow Type = Soft Shadows
 Flare = FlareSmall
眩光效果練習 2/4
19 Wu, ShyiShiou Dept. of E.E., NKUT
shapethefuture
 Main Camera加入腳本程式
public class CameraControl : MonoBehaviour {
public float x;
public float y;
public float xSpeed = 1;
public float ySpeed = 1;
private Quaternion rotationEuler;
void LateUpdate()
{
x += Input.GetAxis ("Mouse X") * xSpeed ;
y -= Input.GetAxis ("Mouse Y") * xSpeed ;
rotationEuler = Quaternion.Euler (y, x, 0);
transform.rotation = rotationEuler;
}
}
眩光效果練習 3/4
20 Wu, ShyiShiou Dept. of E.E., NKUT
shapethefuture
 測試結果
眩光效果練習 4/4
21 Wu, ShyiShiou Dept. of E.E., NKUT
shapethefuture
 光影貼圖是⼀種增加靜態場景光照效果的技術
 事先將光影效果經由計算產生貼圖,渲染到場景中的靜態物件,減
少遊戲執行階段的燈光照明計算,在遊戲執行時以較少的處理器資
源就能使靜態場景看起來更真實
光影貼圖
22 Wu, ShyiShiou Dept. of E.E., NKUT
shapethefuture
 場景物件
光影貼圖練習 1/7
23 Wu, ShyiShiou Dept. of E.E., NKUT
Sphere
Plane
Area Light - Left
Area Light - Middle
Area Light - Right
Directional Light
shapethefuture
光影貼圖練習 2/7
24 Wu, ShyiShiou Dept. of E.E., NKUT
光影貼圖前
光影貼圖後
光影貼圖後(關閉方向光源)
shapethefuture
 新增場景,檔名Light baking
 Directional Light
 Rotation (x, y, z) = (50, -30, 0)
 Intensity = 0.4
 Main Camera
 Position (x, y ,z) = (0, 4, -10)
 Rotation (x, y, z) = (12, 0, 0)
光影貼圖練習 3/7
25 Wu, ShyiShiou Dept. of E.E., NKUT
shapethefuture
 選單命令GameObject>3D Object>Sphere
 Position (x, y, z) = (0, 1.5, 0)
 Scale (x, y, z) = (3, 3, 3)
 選單命令GameObject>3D Object>Plane
 Position (x, y, z) = (0, 0, 0)
 Scale (x, y, z) = (1, 1, 1)
 選單命令GameObject>Light>Area Light
 Position (x, y, z) = (5, 2, -3)
 Rotation (x, y, z) = (0, 0, 0)
 Width=5, Height=5
 Color = Red
光影貼圖練習 4/7
26 Wu, ShyiShiou Dept. of E.E., NKUT
shapethefuture
 選單命令GameObject>Light>Area Light
 Position (x, y, z) = (0, 2, -3)
 Rotation (x, y, z) = (0, 0, 0)
 Width=5, Height=5
 Color = Green
 選單命令GameObject>Light>Area Light
 Position (x, y, z) = (-5, 2, -3)
 Rotation (x, y, z) = (0, 0, 0)
 Width=5, Height=5
 Color = Blue
光影貼圖練習 5/7
27 Wu, ShyiShiou Dept. of E.E., NKUT
shapethefuture
 將要烘焙的物件 (Shpere及Plane) 設定為Static
 將要加入光影貼圖運算的光源Baking屬性設定為Baked
光影貼圖練習 6/7
28 Wu, ShyiShiou Dept. of E.E., NKUT
shapethefuture
 選單命令Window>Lighting
 取消勾選Auto
 點擊Build按鈕
光影貼圖練習 7/7
29 Wu, ShyiShiou Dept. of E.E., NKUT

Weitere ähnliche Inhalte

Was ist angesagt?

Unity遊戲程式設計 - 2D移動與碰撞處理II
Unity遊戲程式設計 - 2D移動與碰撞處理IIUnity遊戲程式設計 - 2D移動與碰撞處理II
Unity遊戲程式設計 - 2D移動與碰撞處理II吳錫修 (ShyiShiou Wu)
 
Unity遊戲設計- 2D動畫製作及應用
Unity遊戲設計-  2D動畫製作及應用Unity遊戲設計-  2D動畫製作及應用
Unity遊戲設計- 2D動畫製作及應用吳錫修 (ShyiShiou Wu)
 
Unity遊戲程式設計(12)第三人稱角色控制器
Unity遊戲程式設計(12)第三人稱角色控制器Unity遊戲程式設計(12)第三人稱角色控制器
Unity遊戲程式設計(12)第三人稱角色控制器吳錫修 (ShyiShiou Wu)
 
Unity遊戲程式設計 - 3D物件與光源設定
Unity遊戲程式設計 - 3D物件與光源設定 Unity遊戲程式設計 - 3D物件與光源設定
Unity遊戲程式設計 - 3D物件與光源設定 吳錫修 (ShyiShiou Wu)
 
Unity遊戲程式設計 - 應用Sprite物件
Unity遊戲程式設計 - 應用Sprite物件Unity遊戲程式設計 - 應用Sprite物件
Unity遊戲程式設計 - 應用Sprite物件吳錫修 (ShyiShiou Wu)
 
Unity遊戲程式設計 - 2D 物理關節應用
Unity遊戲程式設計 - 2D 物理關節應用Unity遊戲程式設計 - 2D 物理關節應用
Unity遊戲程式設計 - 2D 物理關節應用吳錫修 (ShyiShiou Wu)
 
Unity遊戲程式設計 - 2D粒子特效應用
Unity遊戲程式設計 - 2D粒子特效應用Unity遊戲程式設計 - 2D粒子特效應用
Unity遊戲程式設計 - 2D粒子特效應用吳錫修 (ShyiShiou Wu)
 
Neural Turing Machine Tutorial
Neural Turing Machine TutorialNeural Turing Machine Tutorial
Neural Turing Machine TutorialMark Chang
 
NTC_Tensor flow 深度學習快速上手班_Part2 -深度學習
NTC_Tensor flow 深度學習快速上手班_Part2 -深度學習NTC_Tensor flow 深度學習快速上手班_Part2 -深度學習
NTC_Tensor flow 深度學習快速上手班_Part2 -深度學習NTC.im(Notch Training Center)
 
component based html5 game engine
component based html5 game enginecomponent based html5 game engine
component based html5 game enginehbbalfred
 
Unity遊戲程式設計 - 2D移動與碰撞處理II
Unity遊戲程式設計 - 2D移動與碰撞處理IIUnity遊戲程式設計 - 2D移動與碰撞處理II
Unity遊戲程式設計 - 2D移動與碰撞處理II吳錫修 (ShyiShiou Wu)
 
Game development and unity practice
Game development and unity practiceGame development and unity practice
Game development and unity practicegltop
 
TensorFlow 深度學習講座
TensorFlow 深度學習講座TensorFlow 深度學習講座
TensorFlow 深度學習講座Mark Chang
 
TensorFlow 深度學習快速上手班--深度學習
 TensorFlow 深度學習快速上手班--深度學習 TensorFlow 深度學習快速上手班--深度學習
TensorFlow 深度學習快速上手班--深度學習Mark Chang
 

Was ist angesagt? (20)

Unity遊戲程式設計 - 2D移動與碰撞處理II
Unity遊戲程式設計 - 2D移動與碰撞處理IIUnity遊戲程式設計 - 2D移動與碰撞處理II
Unity遊戲程式設計 - 2D移動與碰撞處理II
 
Unity遊戲設計- 應用Sprite物件
Unity遊戲設計- 應用Sprite物件Unity遊戲設計- 應用Sprite物件
Unity遊戲設計- 應用Sprite物件
 
Unity遊戲設計- 2D動畫製作及應用
Unity遊戲設計-  2D動畫製作及應用Unity遊戲設計-  2D動畫製作及應用
Unity遊戲設計- 2D動畫製作及應用
 
Unity遊戲程式設計(12)第三人稱角色控制器
Unity遊戲程式設計(12)第三人稱角色控制器Unity遊戲程式設計(12)第三人稱角色控制器
Unity遊戲程式設計(12)第三人稱角色控制器
 
Unity遊戲程式設計 - 3D物件與光源設定
Unity遊戲程式設計 - 3D物件與光源設定 Unity遊戲程式設計 - 3D物件與光源設定
Unity遊戲程式設計 - 3D物件與光源設定
 
mBot教學(2)-mBlock積木式程式設計
mBot教學(2)-mBlock積木式程式設計mBot教學(2)-mBlock積木式程式設計
mBot教學(2)-mBlock積木式程式設計
 
Vuforia AR影片程式設計
Vuforia AR影片程式設計 Vuforia AR影片程式設計
Vuforia AR影片程式設計
 
Vuforia AR 同時追踨多張辨識圖
Vuforia AR同時追踨多張辨識圖Vuforia AR同時追踨多張辨識圖
Vuforia AR 同時追踨多張辨識圖
 
Unity遊戲程式設計 - 應用Sprite物件
Unity遊戲程式設計 - 應用Sprite物件Unity遊戲程式設計 - 應用Sprite物件
Unity遊戲程式設計 - 應用Sprite物件
 
mBot 教學2 mBlock積木式設計程式
mBot 教學2 mBlock積木式設計程式mBot 教學2 mBlock積木式設計程式
mBot 教學2 mBlock積木式設計程式
 
Unity遊戲程式設計 - Roll a ball遊戲
Unity遊戲程式設計 - Roll a ball遊戲Unity遊戲程式設計 - Roll a ball遊戲
Unity遊戲程式設計 - Roll a ball遊戲
 
Unity遊戲程式設計 - 2D 物理關節應用
Unity遊戲程式設計 - 2D 物理關節應用Unity遊戲程式設計 - 2D 物理關節應用
Unity遊戲程式設計 - 2D 物理關節應用
 
Unity遊戲程式設計 - 2D粒子特效應用
Unity遊戲程式設計 - 2D粒子特效應用Unity遊戲程式設計 - 2D粒子特效應用
Unity遊戲程式設計 - 2D粒子特效應用
 
Neural Turing Machine Tutorial
Neural Turing Machine TutorialNeural Turing Machine Tutorial
Neural Turing Machine Tutorial
 
NTC_Tensor flow 深度學習快速上手班_Part2 -深度學習
NTC_Tensor flow 深度學習快速上手班_Part2 -深度學習NTC_Tensor flow 深度學習快速上手班_Part2 -深度學習
NTC_Tensor flow 深度學習快速上手班_Part2 -深度學習
 
component based html5 game engine
component based html5 game enginecomponent based html5 game engine
component based html5 game engine
 
Unity遊戲程式設計 - 2D移動與碰撞處理II
Unity遊戲程式設計 - 2D移動與碰撞處理IIUnity遊戲程式設計 - 2D移動與碰撞處理II
Unity遊戲程式設計 - 2D移動與碰撞處理II
 
Game development and unity practice
Game development and unity practiceGame development and unity practice
Game development and unity practice
 
TensorFlow 深度學習講座
TensorFlow 深度學習講座TensorFlow 深度學習講座
TensorFlow 深度學習講座
 
TensorFlow 深度學習快速上手班--深度學習
 TensorFlow 深度學習快速上手班--深度學習 TensorFlow 深度學習快速上手班--深度學習
TensorFlow 深度學習快速上手班--深度學習
 

Ähnlich wie Unity遊戲程式設計(09) 3D物件與光源設定

Ähnlich wie Unity遊戲程式設計(09) 3D物件與光源設定 (6)

Unity遊戲程式設計 - 2D運動與碰撞處理I
Unity遊戲程式設計 - 2D運動與碰撞處理IUnity遊戲程式設計 - 2D運動與碰撞處理I
Unity遊戲程式設計 - 2D運動與碰撞處理I
 
Solitaire with Greenfoot #1
Solitaire with Greenfoot #1Solitaire with Greenfoot #1
Solitaire with Greenfoot #1
 
Object-Oriented Programming Design with Greenfoot 01
Object-Oriented Programming Design with Greenfoot 01Object-Oriented Programming Design with Greenfoot 01
Object-Oriented Programming Design with Greenfoot 01
 
Chinese hans
Chinese hansChinese hans
Chinese hans
 
Chinese hans
Chinese hansChinese hans
Chinese hans
 
testing leads fix for ppt2
testing leads fix for ppt2testing leads fix for ppt2
testing leads fix for ppt2
 

Mehr von 吳錫修 (ShyiShiou Wu)

Unity遊戲程式設計 - 2D Platformer遊戲
Unity遊戲程式設計 - 2D Platformer遊戲Unity遊戲程式設計 - 2D Platformer遊戲
Unity遊戲程式設計 - 2D Platformer遊戲吳錫修 (ShyiShiou Wu)
 

Mehr von 吳錫修 (ShyiShiou Wu) (20)

Vuforia AR影片程式設計
Vuforia AR影片程式設計Vuforia AR影片程式設計
Vuforia AR影片程式設計
 
micro:bit亮度感測應用
micro:bit亮度感測應用micro:bit亮度感測應用
micro:bit亮度感測應用
 
Vuforia AR 同時追踨多張辨識圖
Vuforia AR同時追踨多張辨識圖Vuforia AR同時追踨多張辨識圖
Vuforia AR 同時追踨多張辨識圖
 
micro:bit開關控制應用
micro:bit開關控制應用micro:bit開關控制應用
micro:bit開關控制應用
 
Vuforia AR 應用程式設計入門
Vuforia AR應用程式設計入門Vuforia AR應用程式設計入門
Vuforia AR 應用程式設計入門
 
Vuforia AR 應用程式準備作業
Vuforia AR應用程式準備作業Vuforia AR應用程式準備作業
Vuforia AR 應用程式準備作業
 
micro:bit LED顯示控制
micro:bit LED顯示控制micro:bit LED顯示控制
micro:bit LED顯示控制
 
IDE for micro:bit
IDE for micro:bitIDE for micro:bit
IDE for micro:bit
 
Microbit 1 introduction
Microbit 1 introductionMicrobit 1 introduction
Microbit 1 introduction
 
Arduino overview
Arduino overviewArduino overview
Arduino overview
 
使用Makeblock App學習mBot程式設計
使用Makeblock App學習mBot程式設計使用Makeblock App學習mBot程式設計
使用Makeblock App學習mBot程式設計
 
使用M部落App學習mBot程式設計
使用M部落App學習mBot程式設計使用M部落App學習mBot程式設計
使用M部落App學習mBot程式設計
 
nodeMCU IOT教學03 - NodeMCU導論
nodeMCU IOT教學03 - NodeMCU導論nodeMCU IOT教學03 - NodeMCU導論
nodeMCU IOT教學03 - NodeMCU導論
 
nodeMCU IOT教學02 - Lua語言
nodeMCU IOT教學02 - Lua語言nodeMCU IOT教學02 - Lua語言
nodeMCU IOT教學02 - Lua語言
 
Unity遊戲程式設計 - 2D Platformer遊戲
Unity遊戲程式設計 - 2D Platformer遊戲Unity遊戲程式設計 - 2D Platformer遊戲
Unity遊戲程式設計 - 2D Platformer遊戲
 
Python與Ardinio整合應用
Python與Ardinio整合應用Python與Ardinio整合應用
Python與Ardinio整合應用
 
mBlock積木式設計程式
mBlock積木式設計程式mBlock積木式設計程式
mBlock積木式設計程式
 
Arduino程式除錯
Arduino程式除錯Arduino程式除錯
Arduino程式除錯
 
Arduino程式開發工具
Arduino程式開發工具Arduino程式開發工具
Arduino程式開發工具
 
Arduino程式快速入門
Arduino程式快速入門Arduino程式快速入門
Arduino程式快速入門
 

Unity遊戲程式設計(09) 3D物件與光源設定