Per pixel depth clipping

This movie requires Flash Player 9

In the example above, mouse X controls the cubes X position, mouse Y controls the cubes Z position and clicking switches between viewing the output and the depth buffer.

The primary purpose of a depth buffer is to enable per pixel depth checking. Before a pixel can be drawn its depth is compared with the current depth at that point in the depth buffer. If the new depth is greater than the current depth then the new pixel is obviously occluded and thus shouldn’t be drawn. Doing this prevents depth sorting issues and allows objects to intersect without the need for dynamic tessellation.

With my 11bit depth buffer technique in PV3D the primary goal was enabling post processing effects that are only achievable with a depth buffer however at the back of my mind I wondered if depth testing was in some way feasible. Initially I contemplated lowering the precision to 8bit and using BitmapData methods to create per object masks but this would involve a large number of bitmap operations.
Using custom PixelBender blend modes seemed like the perfect solution offering a similar setup minus all the bitmap operations while still keeping 11bit precision. The first blend mode does the depth testing for each depth buffer layer resulting in a clipped depth buffer. Then a second blend mode copies over the texture based on a red channel encoded object ID.
  • Facebook
  • Twitter
  • Netvibes Share
  • Delicious
  • Share/Bookmark

6 Responses Subscribe to comments


  1. Videometry

    Very nice :)
    Depth masks seem to have ignored for anything other than depth of field blur effects. I have had some success using them to make complex backgrounds function like geometry.
    http://videometry.blogspot.com/2009/08/depthmap-filter-new-example.html

    PS

    Oct 27, 2009 @ 6:30 am


  2. Dan

    Would it be possible to post some source code? I am interested in utilizing a depth-buffer over the papervision z-sort painters algorithm, for rendering for obvious reasons. I can’t tell is this what is going on here?

    Nov 09, 2009 @ 8:04 am


  3. Ben

    @Dan I will release the source eventually once it’s cleaned up and integrated with the engine better. Feel free to drop me an email if you want to discuss further.

    Nov 19, 2009 @ 12:14 pm


  4. Ben

    @Videometry nice experiments! I’m contemplating doing something similar using the depth buffer to save rendering far away objects. They could be renderered with their depth information stored and then use that as a kind of depth-cache…

    Nov 19, 2009 @ 12:18 pm


  5. geraldine

    Could you point to some code (related) or perhaps further explanation for a more “intermediate” reader?
    Thanks.

    Nov 27, 2009 @ 11:54 am


  6. Ben

    @geraldine at some point in the near future I’ll write a follow up that explains this PixelBender approach better. If you read up about depth buffers/zbuffers and PixelBender blendmodes - this technique uses the 11bit depth material from my previous examples with a custom PB blend mode that compares the per-pixel depth with that of the layer below it.

    Nov 30, 2009 @ 12:59 pm

Reply