现在的位置: 首页 > 综合 > 正文

Unity3D Shader官方教程翻译(四)—-Shader语法:SubShader

2013年09月03日 ⁄ 综合 ⁄ 共 1677字 ⁄ 字号 评论关闭

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] [CommonStatePassdef [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
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原创,转载请说明。

抱歉!评论已关闭.