Spherize filter

Last night I was thinking of ways to create “fish eye” effect with flash 3D engines, and decided that Pixel Bender is the way to go. However, two things I’ve found on the internet did not make it look the way I wanted, so I ended up creating my own “spherize” filter:

Of course, it is not limited to 3D – you are free to use it in any other way, too. Here goes the source:

<languageVersion : 1.0;>

kernel NewFilter
<   namespace : "experimental";
    vendor : "makc";
    version : 1;
    description : "spherize";
>
{
    input image4 src;
    output pixel4 dst;

    parameter float2 center
    <
        minValue:float2(0.0, 0.0);
        maxValue:float2(1024.0, 1024.0);
        defaultValue:float2(232.5, 232.5);
    >;

    parameter float zoom
    <
        minValue:float(0.0);
        maxValue:float(10.0);
        defaultValue:float(2.0);
    >;

    parameter float radius
    <
        minValue:float(10.0);
        maxValue:float(1000.0);
        defaultValue:float(329.0);
    >;

    void
    evaluatePixel()
    {
        float2 at = outCoord ();
        float2 r = (at - center);
        float d = sqrt (r.x * r.x + r.y * r.y);
        if (d < radius) {
            r *= pow ((radius / (d + 0.1)) * asin (d / radius) / 1.57, zoom);
            at = center + r;
        }
        dst = sampleLinear (src, at);
    }
}
About these ads

3 Responses to “Spherize filter”


  1. 1 dVyper March 4, 2010 at 11:21

    That’s a pretty cool example! :)

  2. 2 nicoptere October 23, 2010 at 02:32

    why is there no sound?


  1. 1 CSI zoom to my house « ¿noʎ ǝɹɐ ʍoɥ 'ʎǝɥ Trackback on April 6, 2010 at 23:56

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s




Old stuff

March 2010
M T W T F S S
« Feb   Apr »
1234567
891011121314
15161718192021
22232425262728
293031  

Oh, btw…


Follow

Get every new post delivered to your Inbox.

%d bloggers like this: