import flash.net.URLLoader;
import flash.events.Event;
import flash.net.URLRequest;
import flash.display.Shader;
import flash.net.URLLoaderDataFormat;
import flash.filters.ShaderFilter;
var shader:Shader;
var i:int = 0,j:int = 0;
var loader:URLLoader=new URLLoader();
loader.addEventListener(Event.COMPLETE,onComplete);
loader.dataFormat = URLLoaderDataFormat.BINARY;
loader.load(new URLRequest("offset.pbj"));
function onComplete(e:Event):void
{
shader = new Shader(e.target.data);
setInterval(updata,100);
function updata():void
{
j++,i++;
shader.data.offset.value = [i,j];
var shaderFilter:ShaderFilter = new ShaderFilter(shader);
mc.filters = [shaderFilter];
}
}
1, 生成了一个pbj文件。
2, offset是pbj设置的变量值。
<languageVersion : 1.0;>
kernel offset
< namespace : "Your Namespace";
vendor : "Your Vendor";
version : 1;
>
{
input image4 src;
output pixel4 dst;
parameter float2 offset
<
defaultValue:float2(0.0,0.0);
minValue:float2(-10.0,-10.0);
maxValue:float2(10.0,10.0);
>;
void
evaluatePixel()
{
dst = sampleNearest(src,outCoord());
pixel4 image=sampleNearest(src,outCoord()+offset);
dst+=image;
dst/=2.0;
}
}