BindChannels
BindChannels命令 允許你指定頂點數據如何映射到顯卡中。
可編程頂點着色器使用時,BindChannels將沒有效果。在這種情況下,綁定受頂點着色器輸入控制。
默認情況下,Unity3D 會爲你計算並綁定,但在某些情況下,你要使用自定義綁定。
例如:你可以在第1個紋理處理階段映射主UV 然後在第2個紋理處理階段使用次要UV。或者告訴硬件需要考慮頂點顏色
Syntax 語法
BindChannels { Bind “source”, target }
例如:指定頂點數據源映射到目標硬件。
Source 可以是下面其中一個:
- Vertex頂點:頂點的位置
- Normal法線:頂點的法線
- Tangent切線:頂點的切線
- Texcoord: 主要的UV座標
- Texcoord1: 次要的UV座標
- Color: 顏色:每個頂點顏色
Target可以是下面其中的一個:
- Vertex: vertex position 頂點:頂點的位置
- Normal: vertex normal 法線:頂點的法線
- Tangent: vertex tangent 切線:頂點的切線
- Texcoord0, Texcoord1, …: texture coordinates for corresponding
texture stage 各個紋理處理階段的紋理座標 - Texcoord: texture coordinates for all texture stages 所有紋理處理階段的紋理座標
Color: vertex color 顏色:頂點顏色
Details 細節
Unity在源和目標的映射上加了一些限制。源和目標必須匹配頂點,法線,切線和顏色。從網格中獲取的紋理座標(Texcoord和Texcoord1)可以映射到紋理座標的目標(所有紋理處理階段可以使用Texcoord ,或者在一個特定階段使用TexcoordN )。
這裏有2個典型的情況可以使用BindChannels。
// Maps the first UV set to the first texture stage
//在紋理處理第1階段映射第1個UV
// and the second UV set to the second texture stage
//在紋理處理第2階段映射第2個UV
//需要考慮頂點顏色的着色器。
BindChannels {
Bind "Vertex", vertex
Bind "texcoord", texcoord0
Bind "texcoord1", texcoord1
}
// Maps the first UV set to all texture stages
// and uses vertex colors
//將第1個UV映射到所有紋理處理階段並使用頂點顏色
//使用兩個UV組的着色器。
BindChannels {
Bind "Vertex", vertex
Bind "texcoord", texcoord
Bind "Color", color
}