Unity3D Shader官方教程翻译(十六)----Shader语法 GrabPass

ShaderLab syntax: GrabPass


GrabPass is a special passtype - it grabs the contents of the screen where the object is about to be drawn into a texture. This texture can be used in subsequent passes to do advanced image based effects.

GrabPass 是一种特殊的通道类型 -它捕获对象所在的屏幕的内容(理解为截图好了)并写入到一个纹理中。这个纹理将用于在后续的通道中完成一些高级图像特效。
Syntax 语法

The GrabPass belongs inside a subshader. It can take two forms:

在一个subshader中有2种形式使用GrabPass :
Just GrabPass { } will grab current screen contents into a texture. The texture can be accessed in further passes by @@_GrabTexture@ name. Note: this form of grab pass will do the expensive screen grabbing operation for each object that uses it!
GrabPass捕捉当前屏幕内容到一个纹理里面。在后续的通道中可以使用_GrabTexture引用这个纹理。请注意这种形式在截屏时候的操作是相当昂贵的。
GrabPass { "TextureName" } will grab screen contents into a texture, but will only do that once per frame for the first object that uses the given texture name. The texture can be accessed in further passes by the given texture name. This is a more performant way when you have multiple objects using grab pass in the scene.
GrabPass { "TextureName" } 捕捉当前屏幕内容到一个纹理里面。但是只会对每帧中第一个使用给定纹理名字的对象进行捕捉操作。在后续的通道中可以使用给定的名字来引用这个纹理。当你在1个场景中有多个对象使用grab pass 时候,这样做会提高效率。

Additionally, GrabPass can use Name and Tags commands.

另外,GrabPass 可以使用Name和Tags命令。


Example 例子

Here is an expensive way to invert the colors of what was rendered before:

反相颜色的操作对于系统来说是十分昂贵的。
Shader "GrabPassInvert" {
SubShader {
// Draw ourselves after all opaque geometry 在所有不透明的几何对象之后绘制自己,
Tags { "Queue" = "Transparent" }
// Grab the screen behind the object into _GrabTexture 捕捉对象之后的屏幕内容并放到_GrabTexture 纹理中
GrabPass { }
// Render the object with the texture generated above, and invert it's colors 使用上面产生的纹理,进行颜色反相
Pass {
SetTexture [_GrabTexture] { combine one-texture }
}
}
}

This shader has two passes: First pass grabs whatever is behind the object at the time of rendering, then applies that in the second pass. Now of course, the same effect could be achieved much cheaper using an invert blend mode.

这个shader 含有2个通道:第1个通道捕捉了在渲染时,对象之后的所有内容并放到一个纹理(_GrabTexture)中。然后应用第2个通道。实现同样的效果有效率更高的方法,比如使用反相混合效果。
See Also 参考另外的
Regular Pass command

由www.J2meGame.com原创,转载请说明。

你可能感兴趣的:(Unity3D Shader官方教程翻译(十六)----Shader语法 GrabPass)