Re: [Flashcoders] Q:Convolution filter and Zoom blur effect

2006-05-03 Thread Jon Bradley


On May 3, 2006, at 10:14 AM, [EMAIL PROTECTED] wrote:


Hi
Anyone been able to use the convolution filter to create realistic  
motion blur effects?


I do not believe a convolution operation cannot perform a zoom and  
spin blur alone. Those need to be performed separately on every  
single pixel in an image. You can get a similar result from  
transforming the bitmap using a transformation matrix that's offset  
from the center of the zoom or spin, rotating or scaling the copied  
bitmap and overlaying the pixels onto the original.


Motion blur can be done to an extent. The problem that you will find  
is that it doesn't work for fast curved motion. Slower curved motion  
it works fine.


The code below is what I posted on my now-defunct site shiftedPixels.  
It's a simplified method to do motion blur by using sampled locations  
and linearly interpolating filter-applied copies of the source.


A better choice would be to use a spline-based sampling system on  
your object and motion blur along points of the spline using a surve  
or slerp method. Of course, doing so will be much slower due to point- 
on-curve routines.


cheers,

Jon

//  
//  Temporal Anti-aliasing (motion blur)
//  jon bradley, 2005
//
//  Create a movie clip on your stage named src.
//  Copy the following code in the first frame.
//  Set the frame rate of your file high, like 120.
//  

import flash.display.BitmapData;
import flash.filters.*;
import flash.geom.*;

_quality = medium;
src.startDrag(true);
Mouse.hide();
src._visible = false;


// set up the filters:
colorM = new ColorMatrixFilter 
([1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0.4,0]);

blurFilter = new BlurFilter(5, 5, 1);

src.cacheAsBitmap = true;

var blurImg:BitmapData = new BitmapData(550, 400, true, 0xFF);
blurImg.transparent = false;

var blurClip:MovieClip = createEmptyMovieClip(blurClip, 99947);
blurClip.attachBitmap(blurImg, 0);
blurClip.cacheAsBitmap = true;

var rect = new flash.geom.Rectangle(0,0,Stage.width, Stage.height);
var pt = new flash.geom.Point(0,0);

//  Linear interpolation to get points between object position points
//  A more accurate choice would be to use spline interpolation based on
//  a motion path of the object - of course this will run much slower.
function lerp(t,a,b)
{
return a+t*(b-a);
}

var x = _xmouse;
var y = _ymouse;

function updateBlur()
{
var m = src.transform.matrix;
var xa = _xmouse;
var dx = Math.sqrt(Math.abs(xa*xa - x*x));
var ya = _ymouse;
var dy = Math.sqrt(Math.abs(ya*ya - y*y));

blurFilter.blurX = dx/20;
blurFilter.blurY = dy/20;

var i = 15;
var t = 1/i;
while (i--)
{
m.tx = lerp( (i+1)*t, xa, x);
m.ty = lerp( (i+1)*t, ya, y);
blurImg.draw(src,m);
}

blurImg.applyFilter(blurImg, rect, pt, colorM);
blurImg.draw(src,m);
blurImg.applyFilter(blurImg, rect, pt, blurFilter);

x = _xmouse;
y = _ymouse;
}

//  Pprocessor intensive - stick with onEnterFrame
//  blurInterval = setInterval(updateBlur,0);

onEnterFrame = function()
{
src._x = _xmouse;
src._y = _ymouse;
updateBlur();
}

//  END CODE
___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


Re: [Flashcoders] Q:Convolution filter and Zoom blur effect

2006-05-03 Thread Jon Bradley
Since I didn't post a solution for zoom or spin blur, here's a method  
you can try out.


A way to account for zoom or spin blur is to do the following:

Perform a polar transform on the bitmap.
Horizontal blur (or vertical blur) the transformed image
Reverse polar transform
Result is a spin blur (or zoom blur if vertical blur is used)

The problem there is that a polar transformation on a bitmap requires  
a loop over every pixel.  No bueno for real-time effects.


cheers,

Jon
___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com