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 可以使用NameTags命令。

 

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 参考另外的

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值