ShaderLab syntax: Pass
ShaderLab 语法:Pass(通道编程)
The Pass block causes the geometry of an object to be rendered once.
1个Pass块可以使一个几何物体被一次渲染。
Syntax
语法
Pass { [Name and Tags] [RenderSetup] [TextureSetup] }
-
The basic pass command contains an optional list of render setup commands, optionally followed by a list of textures to use.
-
最基础的pass命令包含有1个可选的渲染设置命令列表,及1个可选的可用纹理列表。
Name and tags
A Pass can define its Name and arbitrary number of Tags - name/value strings that communicate Pass' intent to the rendering engine.
一个Pass 可以定义它的名字和任意数量的标签-name/value 字符串 将Pass的含义告诉给渲染引擎。
Render Setup 渲染设置
A pass sets up various states of the graphics hardware, for example should alpha blending be turned on, should fog be used, and so on. The commands are these:
Pass设置了一系列的显卡状态,比如说alpha混合是否开启,是否允许雾化等等。 这些命令有:
Material { Material Block } 材质
-
Defines a material to use in a vertex lighting pipeline. See material page for details.
-
定义了1个顶点光照管道使用的材质。
-
-
Lighting On | Off 开启关闭灯光
-
Turn vertex lighting on or off. See material page for details.
-
关闭或开启顶点光照。
-
-
Cull Back | Front | Off 裁剪背面|前面|关闭
-
Set polygon culling mode.
-
设置多边形的裁剪模式。
-
-
ZTest (Less | Greater | LEqual | GEqual | Equal | NotEqual | Always)
-
Set depth testing mode.
-
设置深度测试模式
-
OpenGL 深度其实就是该象素点在3d世界中距离摄象机的距离,深度缓存中存储着每个象素点(绘制在屏幕上的)的深度值!深度测试决定了是否绘制较远的象素点(或较近的象素点),通常选用较近的,而较远优先能实现透视的效果!!!
-
基础参考资料: http://www.cx2012.com/Article/ArText129558687429211250ID133.html。
-
-
ZWrite On | Off
-
Set depth writing mode.
-
设置深度写模式类型
-
-
Fog {
Fog Block
}
-
Set fog parameters.
-
设置雾化参数
-
-
AlphaTest (Less | Greater | LEqual | GEqual | Equal | NotEqual | Always)
CutoffValue
-
Turns on alpha testing.
-
开启Alpha测试
-
-
Blend
SourceBlendMode DestBlendMode
-
Sets alpha blending mode.
设置Alpha混合模式
-
Color
Color value
-
Sets color to use if vertex lighting is turned off.
-
设置颜色,当顶点光照关闭时候有效。
-
-
ColorMask RGB | A | 0 | any combination of R, G, B, A
-
Set color writing mask. Writing
ColorMask 0 turns off rendering to all color channels.
-
设置颜色遮罩模式。将ColorMask设置为0表示关闭所有渲染的颜色管道。
-
-
Offset
OffsetFactor
,
OffsetUnits
-
Set depth offset. Note that this command intentionally only accepts constants (i.e., not shader parameters) as of Unity 3.0.
-
设置深度偏移。提示:这个命令仅接受Unity3 3D的常数参数(不是Shader的参数)。
-
用于为图形设置深度的偏移
这个函数一般用于当两图形刚上处于同坐标或两个面在同一坐标重叠时。可以通过这个函数让其中一个图形或面的坐标自动偏移。
-
在许多实现方法中为了节省重绘深度图所花费的时间,可以只对场景中的一部分物体进行渲染来生成阴影图。另外,为了解决当前深度值与下一步绘制的表面深度太接近产生的深度冲突问题(Z-fighting),也可能在阴影图渲染过程中对物体的照明深度添加一个偏移。实现这种效果的另外一种可选方法是裁剪掉前面的物体,仅对后面的物体进行渲染生成阴影图。
-
SeparateSpecular On | Off
-
Turns separate specular color for vertex lighting on or off. See material page for details.
-
关闭或打开顶点照明单独的镜面反射光的颜色。
-
-
ColorMaterial AmbientAndDiffuse | Emission 环境和漫反射|放射
-
Uses per-vertex color when computing vertex lighting. See material page for details.
-
计算顶点照明时使用的每个顶点颜色
-
Texture Setup 纹理设置
After the render state setup, you can specify a number of textures and their combining modes to apply using SetTexture commands:
当渲染状态设置以后,你可以用SetTexture命令指定这些纹理和他们的结合方式。
SetTexture
texture property {
[Combine options] } 设置纹理
The texture setup configures fixed function multitexturing pipeline, and is ignored if custom fragment shaders are used.
纹理设置固定功能的多纹理管线,如果使用定制的片断着色器将被忽略。
Details 细节
Per-pixel Lighting 逐像素光照
The per-pixel lighting pipeline works by rendering objects in multiple passes. Unity renders the object once to get ambient and any vertex lights in. Then it renders each pixel light affecting the object in a separate additive pass. See Render Pipeline for details.
逐像素光照管道的工作依赖于渲染对象在多个pass中。Unity3D一旦获得环境光和任何顶点的光照就开始渲染物体。然后,它在一个单独添加的pass中影响渲染的物体每1个光照的像素。
Per-vertex Lighting 逐顶点光照
Per-vertex lighting is the standard Direct3D/OpenGL lighting model that is computed for each vertex. Lighting on turns it on. Lighting is affected by Materialblock, ColorMaterial and SeparateSpecular commands. See material page for details.
逐顶点光照是Direct3d/OpenGl的标准光照模式,它的计算依赖于每一个顶点。打开光照后才能启动逐顶点光照。光照受Materialblock, ColorMaterial 和 SeparateSpecular命令影响。
See Also
There are several special passes available for reusing common functionality or implementing various high-end effects:
有几个特殊的pass可以重用公共的功能或实现一些高级效果。
- UsePass includes named passes from another shader. 包含从另外的Shader中已被命名的pass
- GrabPass grabs the contents of the screen into a texture, for use in a later pass.抓取屏幕内容并转换成纹理,可以给之后的pass使用,用来做特效最好了。
Subsections 子模块介绍,慢慢看本站翻译的Shader教程都有。
- ShaderLab syntax: Color, Material, Lighting
- ShaderLab syntax: Culling & Depth Testing
- ShaderLab syntax: Texturing
- ShaderLab syntax: Fog
- ShaderLab syntax: Alpha testing
- ShaderLab syntax: Blending
- ShaderLab syntax: Pass Tags
- ShaderLab syntax: Name
- ShaderLab syntax: BindChannels
-
由www.J2meGame.com原创,转载请说明。