Personal tools

Views

Twirl hydra

From Adobe Labs

[edit]

Twirl source code

/*****************************************************************************
 *
 * Author: Joa Ebert
 * http://blog.je2050.de
 * Contact: j -at- je2050.de
 *
 *****************************************************************************/
kernel Twirl
<   nameSpace:          "popforge::ImageProcessing";
    vendor:             "Joa Ebert";
    version:            1;
    description :       "Applies twirl displacement map.";
>
{
    parameter float2 center
    <
        minValue:       float2(0.0);
        maxValue:       float2(400.0);
        defaultValue:   float2(200.0);
        description:    "The center of the twirl.";
    >;
    
    parameter float angle
    <
        minValue:       -9.423;
        maxValue:       9.423;
        defaultValue:   0.0;
        description:    "The angle of the twirl.";
    >;
    
    parameter float radius
    <
        minValue:       1.0;
        maxValue:       400.0;
        defaultValue:   100.0;
        description:    "The radius of the twirl.";
    >;
    
    void evaluatePixel(in image4 source, out pixel4 result)
    {
        float2 xy0 = outCoord();
        float2 xy1 = xy0;
        float2 delta = xy0 - center;
        
        float d = length(delta);
        float r = radius;
        float phi = atan(delta.y, delta.x) + angle * ( r - d ) / r;
        
        xy1 = center + float2(d * cos(phi), d * sin(phi));
        
        pixel4 c0 = sampleLinear(source,xy0);
        pixel4 c1 = sampleLinear(source,xy1);
        
        result = ( d < r ) ? c1 : c0;
    }
}
Retrieved from "http://labs.adobe.com/wiki/index.php/Twirl_hydra"