Unity3D Shader官方教程翻譯(四)----Shader語法:SubShader

xy849288321發表於2013-02-21
ShaderLab syntax: SubShader
ShaderLab語法:SubShader




Each shader in Unity consists of a list of subshaders. When Unity has to display a mesh, it will find the shader to use, and pick the first subshader that runs on the user's graphics card.

每個在Unity3D的shader都是由一系列的的subshaders組成的。當Unity3D顯示一個網格的時候,它會使用第一個被使用者顯示卡支援的subshader。
Syntax

語法
Subshader { [Tags] [CommonState] Passdef [Passdef ...] }
Defines the subshader as optional tags, common state and a list of pass definitions.
定義subshade包含了可選的標籤,常見的狀態和通道定義列表。
Details

詳情

A subshader defines a list of rendering passes and optionally setup any state that is common to all passes. Additionally, subshader specific Tags can be set up.

一個subshader定義了1個渲染通道列表,並有選擇地設定了這些通道的通常狀態。此外,subshade也可以設定特定的標籤。

When Unity chooses which subshader to render with, it renders an object once for each Pass defined (and possibly more due to light interactions). As each render of the object is an expensive operation, you want to define the shader in minimum amount of passes possible. Of course, sometimes on some graphics hardware the needed effect can't be done in a single pass; then you have no choice but to use multiple passes.

當Unity3D選擇1個subshader進行渲染的時候,他將優先渲染1個被每個通道所定義的物件(這個物件很可能是由光線互動決定的)。由於渲染每1個物體是個十分昂貴的操作,你得定義Shader可能操作的渲染通道數目儘可能的少。當然有時候某些華麗的效果在顯示卡上不可能只使用單通道,你就必須得使用多通道了。

Each pass definition can be a regular Pass, a Use Pass or a Grab Pass.

每個通道的定義可以是1個regular Pass, 或 Use Pass 或 Grab Pass.

Any statements that are allowed in a Pass definition can also appear in Subshader block. This will make all passes use this "shared" state.

在一個通道定義中的任何宣告,也可以出現在Subshader塊。這樣做能使所有的通道都能共享這些宣告。
Example
// ...
SubShader {
Pass {
Lighting Off
SetTexture [_MainTex] {}
}
}
// ...

This subshader defines a single Pass that turns off any lighting and just displays a mesh with texture named _MainTex.

這個subshader定義了1個單通道,這個單通道關閉了所有的燈光然後顯示了1個名字叫_MainTex的紋理網格。


由www.J2meGame.com原創,轉載請說明。

相關文章