2017年3月28日 星期二

Unity 筆記

前陣子大概花了3個多月的時間,
把官方說明網站的內容看了個大半,
因為有與同事間分享的關係,
有一部份有整理成筆記,

現在放到 slideshare,
也當留個紀念吧(?

我自己有整理的部份主要是針對 Animation, Physics, Navigation 這3個章節,
其他的不是不夠熟, 不懂, 不然就是沒時間(Graphics),
其中 Graphics 內容實在太多了,
直到現在我才想起來我跟本跳過這一節了 XD

這次先分享已上傳的部份,
Graphics 雖然是我最熟的,
但要不要整理的話.....看未來緣份吧


Working in Unity



Animation

2017年3月13日 星期一

Shader Forge環境設定



最近因為公司同仁需求,所以看了一下Shader Forge環境。
這個超強大的 node based shader editing tool 真的是佛心來的。
讓一般開發者不用具備 shader programming 背景知識也能做到 AAA層級效果的 shader。

不過因為也很難找到詳細的官方說明文件,
所以我就花時間自己補充了一下,
文件已上傳到我的 slideshare,
詳細內容我這裡再列出一份,
大家可以參考一下,
如果我有寫錯也可以指正一下,順便幫我勘誤 XD

1. Shader Settings
-         Path: 對應Shader選單的名字路徑。
-         FallBack: 預設取代shader。由Pick按鈕選取。
-         LOD: Level of details設定,當物件佔螢幕面積超過設定數字(200)允許使用此shader
-         Allow using atlased sprites: 允許使用合成大圖(packed atlas)
-         Draw call batching: 是否允許batching
-         Inspector preview mode: Material inspector檢視的預覽物體類型。
-         Target renderers: shader指定支援的硬體環境對象。
n   Direct3D 9: windows DirectX環境。
n   Direct3D 11: windows DirectX硬體環境,在windows環境使用Unity Editor編輯時Direct3D 9Direct3D 11要選取才會正常顯示,不支援PC game環境時,最終版本shader不需要選取Direct3D 9Direct3D 11
n   OpenGL Core: 泛指OpenGL 1.x/2.x/3.x/4.x環境。沒有支援PC game環境時最終版本shader不需要選取OpenGL Core
n   OpenGL ES 2.0: 移動裝置環境,OpenGL ES2版本。
n   OpenGL ES 3.0: 移動裝置環境,OpenGL ES3版本。
n   iOS Metal: 移動裝置環境,新的iOS繪圖環境(建議選取支援)
n   Direct3D 11 for Windows RT/Phone: Windows Phone(移動裝置版本)支援的Direct3D 11環境。
n   Xbox One | PlayStation 4 | PlayStation Vita: 各類家用主機情況。
               Nintendo 3DS | Nintendo Wii U: 任天堂裝置的支援。

3. Lighting
-         Render Path: Unity光照繪圖流程方案(LightMode)Forward(預設,傳統直接進行繪圖流程))Deferred(分離式繪圖流程)
n   Forward模式下可設定Light CountSingle Directional(預設)只允許單一方向光;Multi-light允許場中多個光源(注意每多一個光源會多跑一次ForwardAdd pass)
-         LightMode: 已支援的打光方案。Unlit/Custom(未打光)Blinn-Phone ; Phone ; PBL(Physically Based Lighting)
n   (PBL) Specular Mode分為SpecularMetallic兩種反光方案實作。
-         Gloss Mode: Gloss(光澤感)Roughness(粗糙感)
n   Remap gloss from [0-1] to [1-2048]: 更精確地gloss彩度分布計算,效能代價較高。
-         Transparency Mode: 透明打光實作方案。Fade(傳統漸透明效果)Reflective(保持有真實反光表現)
-         Energy Consering: 數入與輸出結果的光能量是否守恆(PBL很重要)
-         Lightmap & light probes: 允許支援Unity5內建的global illumination光照方案。
-         Per-pixel light probe sampling: Light probe環景光照偵測計算是否允許在per-pixel階段。
-         Reflection probe support: 是否支援即時反光光照計算。
-         Receive Ambient Light: 是否能接收基本模糊光源顏色。

-         Mask directional light specular by shadows: 由方向光產生的影子資訊來當作反光(specular)之遮罩資訊

4. Geometry
-         Face Culling: 排除正面或背面或雙面繪圖選項。
-         Normal Quality: Interpolated(直接使用內插結果,較省效能但較不準)Normalized(精確計算)
-         Vertex Positioning: 頂點位置座標計算模式。World space(一般幾何頂點)Clip space(螢幕空間頂點,應用在全螢幕後處理時)Billboard(視為面向鏡頭的Billboard對象)
-         Normal space: 實做normal mapping(bump mapping)時,normal計算要採用哪種空間。Tangent(幾何表面空間)Object(物體空間)World(世界空間)
-         Vertex offset mode: 頂點位移方式。Relative(相對偏移)Absolute(頂點座標直接被新的輸入值取代)
-         Tessellation Mode: 三角形tessellate方法。分為RegularEdge length based
-         Outline Extrude Direction: 邊緣幾何突出方向選擇。有From origin(由原點向頂點座標分量展開)Vertex normals(延著頂點法向量延伸)Vertex colors(由頂點顏色決定偏移量)
-         Per-pixel screen coordinates: 是否在每個pixel上計算螢幕對應座標。
-      Show 2D sprite pixel snap option in material: 精確計算2D sprite對應螢幕座標,實現精準的sprite based game繪圖結果。

5. Blending
-         Blend Mode: 透明混合方式。Opaque(不透明)Alpha Blended(透明,由alpha決定不透明度)Alpha Blended Premultipied(透明,自身RGBA不變累加上去)Additive(透明,新舊顏色RGBA相加)Screen(透明,舊顏色依新顏色比例衰減)Multiplicative(透明;新顏色與舊顏色相乘做合成)
n   透明混合公式係數: Source(fragment shader產生顏色)Destination(目標frame buffer已存在顏色)
-         Color Mask: shader寫入color buffer時的顏色通道mask
-         Dithered alpha clip: 使用Opacity Clip功能時,可支援的dithered alpha clip matrix(2x23x34x4)
-         Offset Factor, Offset Units: Polygon offset偏移設定。
-         Per-object refraction/scene color(expensive): 每個物件使用此shader時都重新更新refractive texture內容(截取當前螢幕),效能代價很高。
n   Texture name/group: 共用的refractive texture名字。
-         Receive Fog: 是否支援Fog運算。
-         Auto Sort: 自動設定rendering sort相關參數。
n   Order: Shader tagQueue設定值。
n   Render Type: Shader tagRenderType設定值。
n   Depth Test: Depth buffer的深度值比較規則。
n   Ignore Projectors: 是否呼略projector運算效果。
n   Write to Depth buffer: shader的深度結果是否要寫入depth buffer
-         Stencil Buffer: shader是否進行stencil buffer操作。
n   可設定Reference ValueComparison比較規則,Masks for Read MaskWrite Mask
-      Pass(stencil buffer pass情空下的動作)Fail(stencil buffer fail to pass情況下的動作)Fail Z(depth buffer fail to pass情況下的動作)

6. Experimental
-         Force Shader Model 2.0: 強迫此shader支援shader model 2(#pragma target 2.0)
-         Force no custom shadow pass: 關閉自動產生的shadow pass
-         Force no fallback: 強迫在shader中不設定fallback shader