» cn.Tutorial Effects - Multiple Passes
This site relies heavily on Javascript. You should enable it if you want the full experience. Learn more.

cn.Tutorial Effects - Multiple Passes

English | Italian | Japanese

TOC: Of Effects and Shaders
Back: Multiple Textures
Next: Vertexshader Preparations

正如在EX9.Effect.File中描述的那样,effects能够在每个technique中有多个通道,但(在vvvv中)通道2没有办法收到在像素着色的通道1中返回的颜色值。对于这种多通道的effects我们需要通过Renderer (EX9)绕一圈,通过DXTexture (EX9.Texture)使用它的输出作为材质,在输入到另外一个effect中。


正如在Neighbouring Pixels我说过的下面是是如何连接垂直和水平模糊的方法,从在两个方向上而达到很平滑的模糊。




这样应用的一个例子如下Cellular Automata 最广泛流行的一个例子是John Horton Conway's "Game of Life".

Rather than a game it is actually more a simulation based on a grid of cells (much like pixels of a texture) that can either be dead (black) or alive (white). The simulations result is essentially a black texture with some white pixels. Using the result as a starting point for the next generation of the simulation creats a feedback and lets the simulation run forever. Of course this needs an initial state to start from which is realized in this example using the mouse to add living cells, see the according patch in of-effects-and-shaders除了是一个游戏他实际上更多的是一个模拟的细胞网格(很像材质中的像素)既可以死(黑色)也可以生(白色)。这个模拟的结果根本上是一个黑色的材质上有很多白色的像素。使用这个结果作为下一代模拟的开始点创建一个反馈从而让这个模拟永远循环。当然这需要一个初始状态以此为开始实现,在下面这个例子中使用鼠标去添加活着的细胞,在of-effects-and-shaders中看相应的例子。


  • 当前细胞为死亡状态时,当周围有3个存活细胞时,该细胞变成存活状态。 (模拟繁殖)
  • 当前细胞为存活状态时,当周围有2个或3个存活细胞时, 该细胞保持原样。
  • 所有其它的状况,一个细胞死亡或保持死亡的状态(模拟人口稀少或模拟过度拥挤)。


float2 PixelSize;
float4 PS(vs2ps In): COLOR
    //sample the current pixel
    float4 center = tex2D(Samp, In.TexCd);
    //prepare pixel offsets for x and y
    float2 offX = float2 (PixelSize.x, 0);
    float2 offY = float2 (0, PixelSize.y);
    //sample neighbours and add up their states
    float alive = 0;
    alive += tex2D(Samp, In.TexCd - offY).r;
    alive += tex2D(Samp, In.TexCd - offY - offX).r;
    alive += tex2D(Samp, In.TexCd - offY + offX).r;
    alive += tex2D(Samp, In.TexCd + offY).r;
    alive += tex2D(Samp, In.TexCd + offY - offX).r;
    alive += tex2D(Samp, In.TexCd + offY + offX).r;
    alive += tex2D(Samp, In.TexCd - offX).r;
    alive += tex2D(Samp, In.TexCd + offX).r;
    //a dead cell with exactly three live neighbors becomes a live cell (birth).
    if (center.r == 0 && alive == 3) 
      center.rgb = 1;
    //a live cell with two or three live neighbors stays alive (survival).  
    else if (center.r == 1 && (alive == 3 || alive == 2)) 
      center.rgb = 1;
    //in all other cases, a cell dies or remains dead (overcrowding or loneliness).
      center.rgb = 0;
    return center;


sampler Samp = sampler_state    //sampler for doing the texture-lookup
    Texture   = (Tex);          //apply a texture to the sampler
    MipFilter = NONE;         //sampler states
    MinFilter = POINT;
    MagFilter = POINT;


Next: Vertexshader Preparations
Back: Multiple Textures
TOC: Of Effects and Shaders

anonymous user login


~9h ago

matka: Massive thanks to developers for the latest release.

~19h ago

joreg: in case you missed the news so far: vvvv 50beta36 is out now: vvvv50beta36 #vvvv

~1d ago

stulloyd: 19/announcing-microsoft-directx-raytracing/

~3d ago

colorsound: @nsynk team. I sent you email about the optitrack at the store. Did you receive it? Thanks.

~4d ago

dominikKoller: vvvv Academy is going on Tour - and looking for partners to host a course! vvvv-academy-on-tour

~6d ago

joreg: another release candidate is out for the weekend: beta36-release-candidate #vvvv please test and report!

~7d ago

microdee: I realized that I will just do those updates on separate branches, Still stay tuned...