<languageVersion : 1.0;>
kernel PBJBlend
< namespace : "Your Namespace";
vendor : "Your Vendor";
version : 1;
>
{
input image4 src;
output pixel4 dst;
parameter float con
<
minValue:1.0;
maxValue:10.0;
defaultValue:1.0;
>;
void
evaluatePixel()
{
dst = sampleNearest(src,outCoord());
dst*=con;
}
}
上面为pbj文件代码,增加一个con变量。
package
{
import com.greensock.TweenLite;
import com.greensock.easing.Expo;
import flash.display.MovieClip;
import flash.display.Shader;
import flash.events.Event;
import flash.filters.ShaderFilter;
import flash.utils.ByteArray;
public class TestPBJ extends MovieClip
{
[Embed("PBJBlend.pbj",mimeType = "application/octet-stream")]
private var pbj:Class;
private var who:MovieClip;
public var photo1:MovieClip;
public var photo2:MovieClip;
private var shader:Shader;
private var filter:ShaderFilter;
public var con:Number = 1.0;
public function TestPBJ()
{
init();
}
private function init():void
{
shader=new Shader(new pbj() as ByteArray);
filter = new ShaderFilter(shader);
who = photo1;
photo2.visible = false;
trans(null);
}
private function trans(e:Event=null):void
{
if (con==5)
{
if (photo1==who)
{
photo2.visible = true;
photo1.visible = false;
who = photo2;
}
else
{
photo1.visible = true;
photo2.visible = false;
who = photo1;
}
}
if (con==1)
{
TweenLite.to(this,1,{con:5,ease:Expo.easeIn,onUpdate:onChange,onComplete:trans});
}
else
{
TweenLite.to(this,1,{con:1,ease:Expo.easeOut,onUpdate:onChange,onComplete:trans});
}
}
protected function onChange(event:Event=null):void
{
shader.data.con.value = [con];
who.filters = [filter];
}
}
}
下面修改为四张图片的效果
package
{
import com.greensock.TweenLite;
import com.greensock.easing.Expo;
import flash.display.MovieClip;
import flash.display.Shader;
import flash.events.Event;
import flash.filters.ShaderFilter;
import flash.utils.ByteArray;
import flash.display.Sprite;
public class TestPBJ extends Sprite
{
[Embed("PBJBlend.pbj",mimeType = "application/octet-stream")]
private var pbj:Class;
private var who:MovieClip;
public var photo1:MovieClip;
public var photo2:MovieClip;
public var photo3:MovieClip;
public var photo4:MovieClip;
private var shader:Shader;
private var filter:ShaderFilter;
public var con:Number = 1.0;
public function TestPBJ()
{
init();
}
private function init():void
{
shader=new Shader(new pbj() as ByteArray);
filter = new ShaderFilter(shader);
who = photo1;
photo2.visible = false;
photo3.visible = false;
photo4.visible = false;
trans(null);
}
private function trans(e:Event=null):void
{
if (con==5)
{
switch (who)
{
case photo1:
photo1.visible = false;
photo2.visible = true;
photo3.visible = false;
photo4.visible = false;
who = photo2;
break;
case photo2:
photo1.visible = false;
photo2.visible = false;
photo3.visible = true;
photo4.visible = false;
who = photo3;
break;
case photo3 :
photo1.visible = false;
photo2.visible = false;
photo3.visible = false;
photo4.visible = true;
who = photo4;
break;
case photo4:
photo1.visible = true;
photo2.visible = false;
photo3.visible = false;
photo4.visible = false;
who = photo1;
break;
default :
break;
}
}
if (con==1)
{
TweenLite.to(this,1,{con:5,ease:Expo.easeIn,onUpdate:onChange,onComplete:trans});
}
else
{
TweenLite.to(this,1,{con:1,ease:Expo.easeOut,onUpdate:onChange,onComplete:trans});
}
}
protected function onChange(event:Event=null):void
{
shader.data.con.value = [con];
who.filters = [filter];
}
}
}