forked from: Pixel Bender Test
酷く重い。使えない
マウス位置に反応させるよりなにかのエフェクトに使った方が良いかもしれない
Pixel Bender Test
// forked from northprint's Pixel Bender Test
// write as3 code here..
//酷く重い。使えない
//マウス位置に反応させるよりなにかのエフェクトに使った方が良いかもしれない
//Pixel Bender Test
package {
import flash.display.*;
import flash.events.*;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.URLLoaderDataFormat;
import flash.system.Security;
import flash.filters.ShaderFilter;
import flash.system.LoaderContext;
[SWF(backgroundColor="#ffffff")]
public class PixelBenderTest extends MovieClip{
private var _pbloader:URLLoader;
private var _imgloader:Loader;
private var _twirlShader:Shader;
private var _filter:ShaderFilter;
private var _bmp:Bitmap;
public function PixelBenderTest(){
Security.loadPolicyFile("http://narayama.heteml.jp/crossdomain.xml");
_pbloader = new URLLoader();
_pbloader.dataFormat = URLLoaderDataFormat.BINARY;
_pbloader.addEventListener(Event.COMPLETE,PbLoadHandler);
_pbloader.load(new URLRequest("http://narayama.heteml.jp/test/pixelbender/zoom_blur.pbj"));
}
private function PbLoadHandler(e:Event):void{
_imgloader = new Loader();
_imgloader.contentLoaderInfo.addEventListener(Event.COMPLETE,ImgLoadHandler);
_imgloader.load(new URLRequest("http://narayama.heteml.jp/test/pixelbender/tokyo.jpg"), new LoaderContext(true));
}
private function ImgLoadHandler(e:Event):void{
var loaderInfo:LoaderInfo = LoaderInfo(e.currentTarget);
var loader:Loader = loaderInfo.loader;
var bmd:BitmapData = new BitmapData(loader.width, loader.height, true);
bmd.draw(loader);
_bmp = new Bitmap(bmd);
_bmp.x = (stage.stageWidth/2) - (loader.width/2);
_bmp.y = (stage.stageHeight/2) - (loader.height/2);
_bmp.cacheAsBitmap = true;
_twirlShader = new Shader(_pbloader.data);
_twirlShader.data["amount"]["value"] = [0.2];
_twirlShader.data["steps"]["value"] = [10];
_filter = new ShaderFilter(_twirlShader);
_bmp.filters = [_filter];
addChild(_bmp);
addEventListener(Event.ENTER_FRAME,EnterframeHandler);
}
private function EnterframeHandler(e:Event):void{
_twirlShader.data["center"]["value"] = [_bmp.mouseX,_bmp.mouseY];
_bmp.filters = [_filter];
}
}
}