Joe Maller: FXScript Reference: Building Joe's GradientsA description of the FXScripts behind my gradient filter for Final Cut Pro. |
|
Visit the New FXScript Reference and Joe's Filters sites. These pages will be phased out soon and may already be out of date. This page describes the FXScript concepts behind Joe's Gradients. If you're looking for the page about how to use this filter, click here. OverviewSince Joe's Gradients was meant to simulate the basic effect of a real-world photographic filter, the script uses a lot of math to make sure the actual gradient effect is applied in the right place. Most of the code for this filter was also used in Building Joe's Soft Gradients. Establish Direction
The script uses Adding 360 made sure the number was always positive. I could have forced the angle input control to be always positive, but I thought it worked better going in either direction. Mod 360 is a great trick that I didn't understand before I started building these filters. Modulo is the remainder of division. It's also something like a clock face, providing a circular numerical baseline. Without SinSomehow I made it this far in life without learning about Sine and Cosine. Sine and Cosine, or Sin and Cos, refer to the vertical and horizontal measurements of the outside of a circle at a given angle. Sin is the x-coordinate, Cos is the y-coordinate. Here is a diagram showing the Sine and Cosine of the angle a: Sin and Cos are used to place the coordinates of the gradient origin point based on the angle specified in PointsSin and Cos are used to establish
Next, the
Finally, the pointer2 is filled with the contents of
FXScript includes a way to find the distance between two points, confusingly labeled
Next the script does some simple addition and subtraction to adjust the end points for the offset slider settings. Enclosing the value in an if statement skips these adjustments if the user chooses an offset of zero. In the following code, linebreaks are indicated by semicolons.
The last point operation again modifies pointer, increasing the coordinates to compensate for the gradient's width, the scale of the desktop monitor and finally increasing the circle by 120% so the origin always falls outside of the frame.
Preventing HalosIt's impossible to fade from one color to nothing. Even though that may seem to be what is happening, the gradation is actually fading between a fully opaque color and a fully transparent color. If the two colors are different (aside from their opacity), there will be a shift in the middle portion of the gradation. Below is an example of what happens when a color-to-tranparent gradation uses two different base colors: Gradation A Gradation B Notice how the blue from the first color pollutes the color of the gradient, even though it is completely transparent. Gradient A blended from yellow to yellow, with only the alpha channel information changing. Flattening the alpha channels from Gradient B reveals the problem: {R:0, G:0, B:255, A:255} → {R:255, G:255, B:0, A:255} ColorsThe alpha value for both gradation colors is set with the following lines. The script does this to guarantee each color's opacity value.
To avoid halos as shown above, the following lines are executed when the
First Wrapping upThe
The filter ends with my standard set of composite controls, combining The complete FXScript source code for Joe's Gradients is included with the paid version of Joe's Filters. |
The FXScript ReferenceFXScripting Joe's FiltersJoe's Filters for Final Cut Pro Building Joe's Minimum Maximum Joe's FXScript ExplorersJoe's Debug and Explore Filters Joe's 3x3 Convolve Matrix Tester Joe's 3x3 Matrix Values Tester Other FCP Stuff
Film & VideoRecording the sound of PhotographyProjectsFinal Cut ProDesignWRITINGSite Notes Archive (weblog) Web ResourcesAbout Joe MallerPast Home Pages Etc.Search joemaller.comContact Me
|