Radial Blur Shader
/////////////////////////////////////////////
//
// TrueVision3d example for fullscreen shader.
// Used for scene shader and/or Draw_FullscreenQuadWithShader
//
// Radial Blur Shader based on NVIDIA example
// 
// Modify BlurWidth for different 'Speeds' 
// Modify nsamples for smoothness of effect
/////////////////////////////////////////////

float BlurStart =.8; //max 1 min -1
float BlurWidth =.09; //max 1 min -1
float4 Center = { 0.5, 0.5,0,0 };

texture Tex:S0;  //main render surface;

sampler Samp = sampler_state    //sampler for doing the texture-lookup
{
    Texture   = (Tex);          //apply a texture to the sampler
    MipFilter = LINEAR;         //set the sampler states
    MinFilter = LINEAR;
    MagFilter = LINEAR;
};

float4x4 tColor;

struct VS_OUTPUT
{
    float4 Pos    : POSITION;
    float4 TexC : TEXCOORD0;

};


VS_OUTPUT VS_RadialBlur(float4 Pos : POSITION, float4 TexC : TEXCOORD0 )
                                           {
			   		
    VS_OUTPUT OUT= (VS_OUTPUT)0;
    OUT.Pos = Pos;
    OUT.TexC = TexC  - Center;
    return OUT;
}


float4 PS_RadialBlur(float2 TexC: TEXCOORD0,uniform sampler2D tex): COLOR

{
	int nsamples =16;
    half4 c = 0;
    for(int i=0; i<nsamples; i++) {
    	float scale = BlurStart + BlurWidth*(i/(float) (nsamples-1));
    	c += tex2D(Samp, TexC.xy * scale + Center );
   	}
   	c /= nsamples;
    return c;
} 

technique RadialBlur {
    pass p0  {
		
		VertexShader = compile vs_2_0 VS_RadialBlur();
		PixelShader  = compile ps_2_0 PS_RadialBlur(Samp);
    }
}

Usage Example

//declare:
static TVShader testFS;
static TVRenderSurface testRS;
int testRSID;
//init
testRS = Core.Scene.CreateRenderSurfaceEx(-1, -1, CONST_TV_RENDERSURFACEFORMAT.TV_TEXTUREFORMAT_A8R8G8B8, true, true, 1);
testRSID = testRS.GetIndex();
testFS = Core.Scene.CreateShader();
testFS.CreateFromEffectFile(MEDIA_PATH+@"\radialBlur.fx");

//at end of render loop:
testRS.BltFromMainBuffer();
Core.Screen2d.Action_Begin2D();
Core.Screen2d.Draw_FullscreenQuadWithShader(testFS,0, 0,1,1,testRSID);
Core.Screen2d.Action_End2D();

Screenshots

 
sta_shader/radial_blur.txt · Last modified: 2013/11/22 13:31