Hi All,
After hacking, debugging the framework, I managed to add a blur method ( Vertical).
Here is the code, and thanks for everyone that helped, Especially GoroMatsumoto, Fabian.
//Vertical Blur Effect Method, By Ahmed Saleh Tolba.
package
{
import flash.display3D.Context3D;
import flash.display3D.Context3DProgramType;
import away3d.arcane;
import away3d.core.managers.Stage3DProxy;
import away3d.materials.TextureMaterial;
import away3d.materials.compilation.ShaderRegisterCache;
import away3d.materials.compilation.ShaderRegisterElement;
import away3d.materials.methods.EffectMethodBase;
import away3d.materials.methods.MethodVO;
use namespace arcane;
public class BlurMethod extends EffectMethodBase
{
private static var MAX_AUTO_SAMPLES:int = 15;
private var _amount:uint;
private var _stepSize:int = 1;
private var _realStepSize:Number;
private var numSamples:int = 1;
private var m_texture:TextureMaterial;
private var data:Vector.<Number>;
public function BlurMethod( )
{
super();
_amount = 19;
calculateStepSize();
}
public function setTexture(texture:TextureMaterial)
{
m_texture = texture;
}
public function set Amount( amount:Number):void
{
this._amount = amount;
}
public function get Amount():Number { return _amount; }
public function set stepSize( stepSize:Number):void
{
this._realStepSize = stepSize;
}
public function ActivateNormalValues():void
{
this._amount = 10;
this._realStepSize = 1;
}
public function ActivateBlurryValues():void
{
this._amount = 10;
this._realStepSize = 10.1;
}
public function get stepSize():Number { return _realStepSize; }
/**
* @inheritDoc
*/
override arcane function initVO(vo:MethodVO):void
{
vo.needsProjection = true;
}
/**
* @inheritDoc
*/
override arcane function initConstants(vo:MethodVO):void
{
var dataV : Vector.<Number> = vo.fragmentData;
dataV[0] = 0;
dataV[1] = 0;
dataV[2] = 0;
dataV[3] = 1;
}
/**
* @inheritDoc
*/
arcane override function activate(vo:MethodVO, stage3DProxy:Stage3DProxy):void
{
var context : Context3D = stage3DProxy._context3D;
var dataV : Vector.<Number> = vo.fragmentData;
// todo: must be normalized using view size ratio instead of texture
var invH:Number = 1/512;
var texIndex:int = vo.texturesIndex;
super.activate(vo, stage3DProxy);
texIndex+=1;
context.setTextureAt(0, m_texture.texture.getTextureForStage3D(stage3DProxy));
dataV[0] = _amount*invH;
dataV[1] = _realStepSize*invH;
dataV[2] = 1/_amount;
context.setProgramConstantsFromVector(Context3DProgramType.FRAGMENT, 0, dataV, 1);
}
/**
* @inheritDoc
*/
arcane override function getFragmentCode(vo:MethodVO, regCache:ShaderRegisterCache, targetReg:ShaderRegisterElement):String
{
var code:String ="mov ft1, v1n";
code += "tex ft2, ft1, fs0 <2d,linear,miplinear,clamp>n";
calculateStepSize();
trace("amount of blur in shader",_amount);
for (var x:Number = _realStepSize; x <= _amount; x += _realStepSize)
{
code += "add ft1.y, ft1.y, fc0.y n";
code += "tex ft3, ft1, fs0 <2d,linear,miplinear,clamp>n";
code += "add ft2, ft2, ft3 n";
++numSamples;
}
code += "mul ft5, ft2, fc0.zn";
code += " mov ft0,ft5n";
return code;
}
private function calculateStepSize():void
{
_realStepSize = _stepSize > 0? _stepSize :
_amount > MAX_AUTO_SAMPLES? _amount/MAX_AUTO_SAMPLES :
1;
}
}
}