www.pudn.com > RNL.rar > BlurX.fx
//////////////////////////////////////////////////////////////////////
// Name : BlurX.fx
// Author : Anirudh S Shastry. fantascape studios. Copyright © 2003.
// Date : 28-12-2003, Sunday.
// Desc : Gaussian filter to blur along x-axis.
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
// Variables
//////////////////////////////////////////////////////////////////////
float4x4 matMVP : WorldViewProjection;
texture tBlurX;
// Pixel offsets ( 1 / 512, 1 / 384 )
float2 PixelOffset = float2( 0.001953195, 0.00260416666 );
float2 BlurOffset = float2( 0.001953195, 0 );
float PixelWeight[8] = { 0.2537, 0.2185, 0.0821, 0.0461, 0.0262, 0.0162, 0.0102, 0.0052 };
//////////////////////////////////////////////////////////////////////
// Samplers
//////////////////////////////////////////////////////////////////////
sampler BlurXSampler = sampler_state
{
Texture = (tBlurX);
};
//////////////////////////////////////////////////////////////////////
// Vertex shader
//////////////////////////////////////////////////////////////////////
struct VS_OUT
{
float4 Pos: POSITION;
float2 Tex: TEXCOORD0;
};
VS_OUT vs_main( float3 inPos: POSITION, float2 inTex: TEXCOORD0 )
{
VS_OUT OUT;
// Output the transformed vertex
OUT.Pos = mul( matMVP, float4( inPos, 1 ) );
// Output the texture coordinates
OUT.Tex = inTex + ( PixelOffset * 0.5 );
return OUT;
}
//////////////////////////////////////////////////////////////////////
// Pixel shader
//////////////////////////////////////////////////////////////////////
float4 ps_main( float2 inTex: TEXCOORD0 ) : COLOR0
{
float4 color = tex2D( BlurXSampler, inTex );
// Sample pixels on either side
for( int i = 0; i < 8; ++i )
{
color += tex2D( BlurXSampler, inTex + ( BlurOffset * i ) ) * PixelWeight[i];
color += tex2D( BlurXSampler, inTex - ( BlurOffset * i ) ) * PixelWeight[i];
}
return color;
}
//////////////////////////////////////////////////////////////////////
// Techniques
//////////////////////////////////////////////////////////////////////
technique Technique0
{
pass Pass0
{
Sampler[0] = (BlurXSampler);
VertexShader = compile vs_2_0 vs_main();
PixelShader = compile ps_2_0 ps_main();
}
}