Unity3d Shader(三) Pass(GrabPass)捕获物体所在位置的屏幕的内容

GrabPass 是一种特殊的通道类型 - 捕获物体所在位置的屏幕的内容并写入到一个纹理中。这个纹理能被用于后续的通道中完成一些高级图像特效。

 

Syntax 语法

 

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

有两种方式将GrabPass放入一个 subshader 中:

  • 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" } 能捕获屏幕内容到一个纹理中,但只会在每帧中处理第一个使用给定纹理名的纹理的对象的渲染过程中产生捕获操作。纹理在未来的通道中可以通过给定的纹理名访问。当你在一个场景中拥有多个使用GrabPass的对象时将提高性能。

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.

这个着色器有两个通道:第一个通道捕获在渲染时刻对象背后的所有图像,然后执行第二次通道。当然,在现在,实现同样的效果,使用反相 混合模式将更加廉价。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值