Skip navigation
Currently Being Moderated

Shader works in toolkit, not in Flash

Apr 19, 2012 6:11 AM

Tags: #bugs #pixel_bender_toolkit

The following shader (Which creates a circular gradient fill that interpolates along the angle, not the radius: the full shader code and it working is here) works in Pixel Bender Toolkit but not in Flash: in Flash it seems to go into an infinite loop

 

    void

    evaluatePixel()

    {

        // calculate where we are relative to the center

        float2 relativePos = outCoord() - center;

        // get our bearing relative to start angle, wrap it and scale to (-2, 2)

        float dir = atan(relativePos.y, relativePos.x);

        dir = dir - startAngle;

        float dir2 = dir + TWOPI;

        dir = dir < -PI ? dir2 : dir;

        dir = dir * 4.0 / TWOPI;

 

        // get colours to interpolate between and how far to interpolate

        float3 colFrom, colTo;

        if (dir < 0.0) {

            if (dir < -1.0) {

                dir = dir + 2.0;

                colFrom = col1;

                colTo = col2;

            } else {

                dir = dir + 1.0;

                colFrom = col2;

                colTo = col3;

            }

        } else {

            if (dir < 1.0) {

                colFrom = col3;

                colTo = col4;

            } else {

                dir = dir - 1.0;

                colFrom = col4;

                colTo = col1;

            }

        }

        // linearly interpolate

        float3 interp = mix(colFrom, colTo, float3(dir, dir, dir));

        // convert to smooth interpolation through colours

        interp = colFrom + (colTo - colFrom) * smoothStep(colFrom, colTo, interp);

        dst = pixel4(interp.x, interp.y, interp.z, 1.0);

    }

}

 

To fix it 'dir' cannot be used both in the 'if' statements and set in the statements that depend on them. I.e. the following which replaces 'dir' with 'dir2' works. It would be better if this were consistent between the toolkit and Flash (the shader is one without an input image so won't work in AE or PS). Tested with Flash 11.2.

 

   void

    evaluatePixel()

    {

        // calculate where we are relative to the center

        float2 relativePos = outCoord() - center;

        // get our bearing relative to start angle, wrap it and scale to (-2, 2)

        float dir = atan(relativePos.y, relativePos.x);

        dir = dir - startAngle;

        float dir2 = dir + TWOPI;

        dir = dir < -PI ? dir2 : dir;

        dir = dir * 4.0 / TWOPI;

 

        // get colours to interpolate between and how far to interpolate

        float3 colFrom, colTo;

        if (dir < 0.0) {

            if (dir < -1.0) {

                dir2 = dir + 2.0;

                colFrom = col1;

                colTo = col2;

            } else {

                dir2 = dir + 1.0;

                colFrom = col2;

                colTo = col3;

            }

        } else {

            if (dir < 1.0) {

                dir2 = dir;

                colFrom = col3;

                colTo = col4;

            } else {

                dir2 = dir - 1.0;

                colFrom = col4;

                colTo = col1;

            }

        }

        // linearly interpolate

        float3 interp = mix(colFrom, colTo, float3(dir2, dir2, dir2));

        // convert to smooth interpolation through colours

        interp = colFrom + (colTo - colFrom) * smoothStep(colFrom, colTo, interp);

        dst = pixel4(interp.x, interp.y, interp.z, 1.0);

    }

}

 
Replies
  • Currently Being Moderated
    Apr 19, 2012 11:20 AM   in reply to John Blackburne

    Hi John,

     

    Thanks for that information, and thank you for the workaround.  I'll add it as a bug.  It sounds like variable scoping might have a bug in the pb -> pb-byte-code conversion for Flash.

     

    I don't have a good feel for when this would be addressed, but unfortunately my best guess is not for some time.  We've largely buttoned up CS6 save for crazy show stopper issues and this is well-below that threshhold.  While Flash isn't tied to that schedule, most current Pixel Bender developement is aimed at the mainline suite apps so that's the schedule compiler fixes would be likely to come down.

     

    Best,

    Chuck.

     
    |
    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