Skip navigation
WChristian
Currently Being Moderated

Pixel bender Vignette circle to elepsis

Jan 18, 2012 3:39 AM

Hi Everyone, Im pretty new to PB and am tweaking a file to use in a Flash project. My problem is creating a new paremeter which distorts the circular vignette to an eleptical one. Increasing the blurWidth Size should increase the width (not height) of the focal point making it wide, can anyone point me in the right direction? Many thanks Code so far is below.

 

<languageVersion : 1.0;>
kernel ZoomBlurFocus
<
    namespace : "com.abril";
    vendor : "Daniel Allegretti";
    version : 1;
    description : "Ajustable zoom blur, you can control focal size, edge hardness and light. Based on ZoomBlur by Ryan Phelan.";
>
{


    parameter float amount
    <
        minValue:0.0;
        maxValue:0.5;
        defaultValue:0.25;
    >;


    parameter float2 center
    <
    minValue: float2(0.0);
    maxValue: float2(900.0);
    defaultValue: float2(200.0);
    >;


    parameter float focalSize
    <
    minValue: 0.0;
    maxValue: 500.0;
    defaultValue: 100.0;
    >;
    /*
    parameter bool invert           // TODO: nada de boolean
    <
    defaultValue: false;
    >;
    */
    
    parameter int invert
    <
    minValue: 0;
    maxValue: 1;
    defaultValue: 0;
    >;
    
    parameter float vignette
    <
    minValue: 0.0;
    maxValue: 1.0;
    defaultValue: 0.6;
    >;
    parameter int blurWidth
    <
    minValue: 0;
    maxValue: 2;
    defaultValue: 1;
    >;


    parameter float edgeHardness
    <
    minValue: 0.0;
    maxValue: 1.0;
    defaultValue: 0.0;
    >;


    input image4 src;
    output pixel4 dst;
    
    void evaluatePixel() {
    
        float str = 1.0 - vignette;
        float2 coord = outCoord();
        float cur_radius = length(coord - center);
        pixel4 color = sampleNearest(src, coord);
        int cond1 = (cur_radius > focalSize) ? 1 : 0;
        
        if(invert == 1) {
            //cond1 = !cond1;
            if(cond1 == 0) {
                cond1 = 1;
            } else {
                cond1 = 0;
            }
        }
        
        float strength;
        if(invert == 1) {
            strength = cur_radius / focalSize;
        } else {
            strength = focalSize / cur_radius;
        }
        
        float tmpAmount = strength * amount;
        coord -= center;
        pixel4 tmpDst = float4(0.0);
        float scale;
        scale = 1.0;
        tmpDst += sampleNearest( src, coord*scale + center );
        scale = 1.0 + tmpAmount * (1.0/14.0);
        tmpDst += sampleNearest( src, coord*scale + center );
        scale = 1.0 + tmpAmount * (2.0/14.0);
        tmpDst += sampleNearest( src, coord*scale + center );
        scale = 1.0 + tmpAmount * (3.0/14.0);
        tmpDst += sampleNearest( src, coord*scale + center );
        scale = 1.0 + tmpAmount * (4.0/14.0);
        tmpDst += sampleNearest( src, coord*scale + center );
        scale = 1.0 + tmpAmount * (5.0/14.0);
        tmpDst += sampleNearest( src, coord*scale + center );
        scale = 1.0 + tmpAmount * (6.0/14.0);
        tmpDst += sampleNearest( src, coord*scale + center );
        scale = 1.0 + tmpAmount * (7.0/14.0);
        tmpDst += sampleNearest( src, coord*scale + center );
        scale = 1.0 + tmpAmount * (8.0/14.0);
        tmpDst += sampleNearest( src, coord*scale + center );
        scale = 1.0 + tmpAmount * (9.0/14.0);
        tmpDst += sampleNearest( src, coord*scale + center );
        scale = 1.0 + tmpAmount * (10.0/14.0);
        tmpDst += sampleNearest( src, coord*scale + center );
        scale = 1.0 + tmpAmount * (11.0/14.0);
        tmpDst += sampleNearest( src, coord*scale + center );
        scale = 1.0 + tmpAmount * (12.0/14.0);
        tmpDst += sampleNearest( src, coord*scale + center );
        scale = 1.0 + tmpAmount * (13.0/14.0);
        tmpDst += sampleNearest( src, coord*scale + center );
        scale = 1.0 + tmpAmount * (14.0/14.0);
        tmpDst += sampleNearest( src, coord*scale + center );
        tmpDst /= 15.0;
        if (cond1 == 1) {
            dst = ((1.0 - edgeHardness) * ((color * strength) + (tmpDst * (1.0 - strength)))) + (tmpDst * edgeHardness);
            dst.rgb = ( vignette * dst.rgb * strength ) + ( dst.rgb * (1.0 - vignette) );
        } else {
            dst = color;
        }
        dst.a = color.a;
    }
}
 
Replies
  • Currently Being Moderated
    Jan 19, 2012 3:56 PM   in reply to WChristian

    I'm not totally sure what the effect is that you're going for, but as soon as you mention ellipses you're going to need to use separate scaling values for the x and y values of the sampling coordinates.

     

    Bob

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 16, 2012 8:55 AM   in reply to WChristian

    If you change your scale variable from a float to a float2, then the x,y components of should scale the width/height of the effect...

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points