Personal tools

Views

Technodots hydra

From Adobe Labs

[edit]

Technodots source code

/*****************************************************************************
 *
 * Author: Joa Ebert
 * http://blog.je2050.de
 * Contact: j -at- je2050.de
 *
 *****************************************************************************/
kernel TechnoDots
<   nameSpace:          "popforge::ImageProcessing";
    vendor:             "Joa Ebert";
    version:            1;
    description:        "Like a pixelate filter but using nice dots with spacing.";
>
{
    parameter float spacing
    <
        minValue:       0.0;
        maxValue:       16.0;
        defaultValue:   2.0;
        description:    "Spacing between the dots.";
    >;
    
    parameter float radius
    <
        minValue:       1.0;
        maxValue:       64.0;
        defaultValue:   4.0;
        description:    "Radius of the dots.";
    >;
    
    parameter pixel4 fillColor
    <
        minValue:       0.0;
        maxValue:       1.0;
        defaultValue:   0.0;
        description:    "The fill or background color.";
    >;
    
    void evaluatePixel( in image4 source, out pixel4 result)
    {
        // xy0 = origin
        // xy1 = translated
        float2 xy0 = outCoord();
        float2 xy1 = xy0;
        
        // aabb of dot with spacing
        float rs = radius * 2.0 + spacing;
        
        // shift into square
        xy1 -= mod( xy1, float2( rs, rs ) );
        
        // put into the middle
        xy1 += float2( radius );
        
        // use constants
        float  a = length(xy0-xy1); // check if inside
        float  b = radius;          // the radius
        pixel4 c = fillColor;
        pixel4 d = sampleNearest(source, xy1);
        
        // no flash error with constant selection
        result = ( a > b ) ? c : d;
        
        /*
        Smooth edges by Jan Van Coppenolle
        
        pixel4 d = sampleNearest(source, xy1);
        float o = smoothStep(b, b - 1.0, a);
        result = c - c * o + d * o;
        */
    }
}
Retrieved from "http://labs.adobe.com/wiki/index.php/Technodots_hydra"