Stencil Based Screen Wipes

Home | Up | Search | X-Zone News | Services | Book Support | Links | Feedback | Smalltalk MT | The Scrapyard | FAQ | Technical Articles

 

Written by Robert Dunlop
Microsoft DirectX MVP

Download WIPE.ZIP
Sample Source Code and Application
295KB

Requires DirectX 8.0 Runtime or Later

This sample illustrates how to transfer an image mask to the stencil buffer, and utilizes this technique to perform a dynamic wipe between two 3D scenes.

Rendering of the scene begins by rendering of a texture over the entire screen, which includes an alpha channel that contains the image mask.  After disabling writes to the color and depth buffers, we enable alpha testing and set stencil function to increment the stencil value of every pixel that passes the alpha test.

Following the application of the alpha mask to the screen, we then render two different scenes.  For the first scene, we set the stencil function so that only those pixels with a stencil value equal to zero are written to.  Pixels with a non-zero stencil buffer value are left undisturbed, preserving their color and depth values.  The second scene is rendered, after configuring the stencil function to write only to those pixels with non-zero stencil values.  Finally, the composite scene is presented, as seen in the screen grab above.  By manipulating the texture coordinates of the alpha mask primitives, quickly moving the mask from side to side while shearing the texture vertically, we achieve a very fluid and artistic transition between the two scenes.

This site, created by DirectX MVP Robert Dunlop and aided by the work of other volunteers, provides a free on-line resource for DirectX programmers.

Special thanks to WWW.MVPS.ORG, for providing a permanent home for this site.

Visitors Since 1/1/2000: Hit Counter
Last updated: 07/26/05.