Wed, Sep 30, 2009

PV3D depth buffer source

Clicking the example above will switch between viewing output and the depth buffer.

Using the same Pixel Bender kernel as my previous depth of field experiment it is possible to achieve depth based fog. Since the kernel controls alpha based on depth we just have to fill the filter target with the desired fog color. To make it a little more visually interesting I have added some animated perlin noise as well.

The trick to creating the depth buffer was rather simple. First a texture is created with each pixel set to it's Y value, then when rendering, each vertex has it's V texture coordinate set based on it's Z position. From here a Pixel Bender kernel can decode the depth... and then the fun begins!

I have updated my experiments repository with the above example. It's still in the early proof of concept stage but should provide you with a starting point for your own depth aware Pixel Bender effects.