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

来源:互联网 发布:淘宝专营店是什么意思 编辑:程序博客网 时间:2024/05/24 06:35

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
原创粉丝点击