纳金网

标题: [Unity 组件参考手册]着色器参考之着色器语法:SubShader [打印本页]

作者: .    时间: 2013-2-24 09:54
标题: [Unity 组件参考手册]着色器参考之着色器语法: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***ns on the user's graphics card.
Unity中的每一个着色器都包含一个subshader的列表,当Unity需要显示一个网格时,它能发现使用的着色器,并提取第一个能运行在当前用户的显示卡上的子着色器。

Syntax 语法
Subshader { [Tags] [CommonState] Passdef [Passdef ...] }

    Defines the subshader as optional tags, common state and a list of pass definitions.

    通过可选标签,通用状态 和 一个Pass 定义的列表构成了子着色器。
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.
子着色器定义了一个渲染通道的列表,并可选是否为所有通道初始化所需要的通用状态。
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.
当Unity选择用于渲染的子着色器时,它为每一个被定义的通道渲染一次对象(可能会更多,这取决于光线的交互作用)。当对象的每一次渲染都是一次昂贵的操作时,你能选择使用最小数目的通道来定义着色器。当然,有时在一些显示硬件上需要的效果不能通过单次通道来完成。除了使用多次通道你别无选择。
Each pass definition can be a regular Pass, a Use Pass or a Grab Pass.
通道定义的类型包括a regular Pass, a Use Pass or a 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.
任何出现在通道定义的状态同时也能整个子着色器块中可见。这将使得所有通道共享状态。

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.
这个着色器定义了一个单一的通道用来关闭任何光照,并只使用一个名叫_MainTex的纹理来显示网格。


【来源:互联网】

更多精彩教程,尽在web3D纳金网http://www.narkii.com/college/




欢迎光临 纳金网 (http://c-www.narkii.com/club/) Powered by Discuz! X2.5