- 最后登录
- 2014-10-23
- 注册时间
- 2011-7-19
- 阅读权限
- 90
- 积分
- 81303
- 纳金币
- -1
- 精华
- 11
|
此系统提供unity可以支援现有所有的硬体并取得最佳的品质。它作到了,然而,结果是必须撰写很长的shaders语法
Inside each SubShader block you set the rendering state shared by all passes; and define rendering passes themselves. A complete list of available commands can be found in the SubShader Reference.
在每一个SubShader block,你可以设定彩现途径的状态;并定义彩现途径本身。完整的SubShader语法请参照SubShader Reference章节
Passes
Each subshader is a collection of passes. For each pass, the object geometry is rendered, so there must be at least one pass. Our VertexLit shader has just one pass:
每个subshader等于是一个途径集。要对几何物件进行彩现,至少一定要有一个途径,内定的VertexLit shader里面仅有一个途径:
view plaincopy to clipboardprint?
// ...snip...
Pass {
Material {
Diffuse [_Color]
Ambient [_Color]
Shininess [_Shininess]
Specular [_SpecColor]
Emission [_Emission]
}
Lighting On
SeperateSpecular On
SetTexture [_MainTex] {
constantColor [_Color]
Combine texture * primary DOUBLE, texture * constant
}
}
// ...snip...
// ...snip...
Pass {
Material {
Diffuse [_Color]
Ambient [_Color]
Shininess [_Shininess]
Specular [_SpecColor]
Emission [_Emission]
}
Lighting On
SeperateSpecular On
SetTexture [_MainTex] {
constantColor [_Color]
Combine texture * primary DOUBLE, texture * constant
}
}
// ...snip...
Any commands defined in a pass configures the graphics hardware to render the geometry in a specific way.
通过指令可以定义一个特殊的方法,用来驱动绘图硬体彩现指定的几何物件
In the example above we have a Material block that binds our property values to the fixed function lighting material settings. The command Lighting On turns on the standard vertex lighting, and SeperateSpecular On enables the use of a separate color for the specular highlight.
例如:上方语法中有一个Material block,定义了照明时所需要几项固定参数。而指令Lighting On用来开启该照明设备,而SeperateSpecular On则是启用Seperate作为特殊镜射效果
All of these command so far map very directly to the fixed function OpenGL/Direct3D hardware model. Consult OpenGL red book for more information on this.
到目前为止的所有命令,皆属于支援OpenGL/Direct3D技术硬体本身可使用的固定功能,您可以参考OpenGL红皮书,可以找到更多相关资料
The next command, SetTexture, is very important. These commands define the textures we want to use and how to mix, combine and apply them in our rendering. SetTexture command is followed by the property name of the texture we would like to use (_MainTex here) This is followed by a combiner block that defines how the texture is applied. The commands in the combiner block are executed for each pixel that is rendered on screen.
下一个命令是SetTexture,这是个非常重要的命令,这个命令可以定义影像纹理如何混合、组合以及如何运用于我们的彩现环境里,SetTexture通常跟随于纹理的属性名称之后(我们在这里使用_MainTex ),接下来的combiner block也是定义纹理的应用方式,这个combiner block的命令会在萤幕显示每一个被执行的动作
Within this block we set a constant color value, namely the Color of the Material, _Color. We'll use this constant color below.
在这个block内我们设定了一个颜色值,并命名为_Color,我们会在后面使用这个颜色
In the next command we specify how to mix the texture with the color values. We do this with the Combine command that specifies how to blend the texture with another one or with a color. Generally it looks like this:
在下个命令,我们指定如何混合纹理以及颜色值。我们用Combine命令来混合其他纹理或颜色,看起来像下面这样:
Combine ColorPart, AlphaPart
Here ColorPart and AlphaPart define blending of color (RGB) and alpha components respectively. If AlphaPart is omitted, then it uses the same blending as ColorPart.
在这里ColorPart与AlphaPart定义了混合的颜色(RGB)以及alpha值(A)个别的资料,假如AlphaPart被省略了,那它将与ColorPart的资料作混合
In our VertexLit example:
在我们的VertexLit范例中:
Combine texture * primary DOUBLE, texture * constant
Here texture is the color coming from the current texture (here _MainTex). It is multiplied (*) with the primary vertex color. Primary color is the vertex lighting color, calculated from the Material values above. Finally, the result is multiplied by two to increase lighting intensity (DOUBLE).
这里的texture来源是当前的纹理(_MainTex),它将与主要的颜色互相搭配(*),主色为照明设备的颜色,它是由Material计算出来的结果。最终是这两个倍增后的结果会增加照明强度
The alpha value (after the comma) is texture multiplied by constant value (set with constantColor above). Another often used combiner mode is called previous (not used in this shader). This is the result of any previous SetTexture step, and can be used to combine several textures and/or colors with each other.
aplha值(在逗号以后)是由constantColor倍增而得的结果。另一个常用的混合模式称为previous(在这个shader未使用),这是所有previous SetTexture的结果,并且可以用来混合多种纹理和颜色。
由 uke 发表
本文来自CSDN博客 |
|