gwycon.com
Silverlight, WPF and C# .NET development
User NamePassword

Iterative Pixel Shader Effect

This application is very similar to the Pixel Shader Effect Rendering application except for one important difference. This time when the button is clicked the source image is copied to a WriteableBitmap (new to Silverlight 3) and then back again to the source image unmodified. The cloned image is always bound in XAML code the the source image as before.

When the button is clicked something interesting happens. As far as the pixel shader code is concerned the original image pixels have been modified and the shader code acts on these new pixels before the final rendering. This means that the inverted image is copied to the bitmap in memory then back to the source image again, and the pixel shader inverts the image pixels as before but this time it inverts the already inverted image! Thus the image appears to go back to the original unmodified state.

However, the clone image gives the game away by showing the source images unmodified (by the shader code) pixels. So, when the button is first clicked the clone image displays the inverted image which is now become new source image pixels which the shader code will then modify.

Each subsequent button click toggles the source image from inverted to non-inverted, and the same pixel shader code can be forced to run again on the source image by simply overwriting the source pixels (copy to bitmap and back again). This simple technique can be used to iteratively run shader code on an image by updating the image source. This can potentially be used to overcome the pixel shader 2.0 limit of 64 concurrent instructions, for example in fractal applications.

Click for live demo

For further information please contact us.