Adobe Pixel Bender Effects – Circular Frame Shader

Introduction

In this tutorial we are going to learn how to write a pixel shader to create a circular frame for a given input image. The shader allows us to specify the circle center, radius and background color. It also allows us to shift the image to the left or right inside the frame.

Adobe Pixel Bender

If you want to write an image shader for your Flex or Flash application it is recommended that you install Adobe Pixel Bender Toolkit. It includes the Pixel Bender kernel language and graph language, the Pixel Bender Toolkit IDE, sample filters, and documentation needed for developing and debugging shaders. Once you finish developing your shader you can export the binary code and use it in a regular Flex/Flash application.

Circular Frame Shader

The idea behind circular frames is very simple. We use the equation of a circle. If a pixel is outside the circle we color it using the background color of choice otherwise we keep the color as it was in the input image. In order to check if a pixel is inside or outside the circle we calculate the distance between the pixel and the circle center. If the distance is greater than the circle radius then it is outside otherwise it is off-course inside. Here is the full source code of the shader:

Live Demo

In order to use the shader above in a Flex/Flash application you need to compile and export the shader using Pixel Bender Toolkit mentioned earlier. Here is the shader in action. Try to play with it to get a feeling of what it does.

[kml_flashembed movie=”https://www.8bitavenue.com/wp-content/uploads/2012/04/pixel_bender_circular_frame.swf” height=”450″ width=”550″ /]

Flex Source Code

You can download the full Flex source code here. Thanks for reading.

Add a Comment

Your email address will not be published. Required fields are marked *