/*********************************************************************NVMH3****

******************************************************************************/

float4x4 worldViewProj : WorldViewProjection;
float4x4 Proj : Projection;

float3 campos : CAMERAPOS;

float  ImageWidth;
float  ImageHeight;
float  MaxSampleRadius;
float  BlurFactor;

float4 gaussian7[7] = {
float4( -5,  0.066342, 0.0f, 0.0f ),
float4( -4,  0.079425, 0.0f, 0.0f ),
float4( -3,  0.091361, 0.0f, 0.0f ),
float4( -2,  0.100969, 0.0f, 0.0f ),
float4( -1,  0.107213, 0.0f, 0.0f ),
float4( 0,  0.109379, 0.0f, 0.0f ),
float4( 1,  0.107213, 0.0f, 0.0f ),
};

float4 gaussian11[11] = {
float4( -5,  0.066342, 0.0f, 0.0f ),
float4( -4,  0.079425, 0.0f, 0.0f ),
float4( -3,  0.091361, 0.0f, 0.0f ),
float4( -2,  0.100969, 0.0f, 0.0f ),
float4( -1,  0.107213, 0.0f, 0.0f ),
float4( 0,  0.109379, 0.0f, 0.0f ),
float4( 1,  0.107213, 0.0f, 0.0f ),
float4( 2,  0.100969, 0.0f, 0.0f ),
float4( 3,  0.091361, 0.0f, 0.0f ),
float4( 4,  0.079425, 0.0f, 0.0f ),
float4( 5,  0.066342, 0.0f, 0.0f )
};

float4 gaussian15[15] = {
float4( -7,  0.066342, 0.0f, 0.0f ),
float4( -6,  0.079425, 0.0f, 0.0f ),
float4( -5,  0.066342, 0.0f, 0.0f ),
float4( -4,  0.079425, 0.0f, 0.0f ),
float4( -3,  0.091361, 0.0f, 0.0f ),
float4( -2,  0.100969, 0.0f, 0.0f ),
float4( -1,  0.107213, 0.0f, 0.0f ),
float4( 0,  0.109379, 0.0f, 0.0f ),
float4( 1,  0.107213, 0.0f, 0.0f ),
float4( 2,  0.100969, 0.0f, 0.0f ),
float4( 3,  0.091361, 0.0f, 0.0f ),
float4( 4,  0.079425, 0.0f, 0.0f ),
float4( 5,  0.066342, 0.0f, 0.0f ),
float4( 6,  0.100969, 0.0f, 0.0f ),
float4( 7,  0.091361, 0.0f, 0.0f )};

texture diffuseTexture : DiffuseTexture;
sampler DiffuseTextureSampler = sampler_state 
{
    texture = <diffuseTexture>;
    AddressU  = CLAMP;        
    AddressV  = CLAMP;
    AddressW  = CLAMP;
    MIPFILTER = LINEAR;
    MINFILTER = LINEAR;
    MAGFILTER = LINEAR;
};

struct vertexInput {
    float4 position				: POSITION;
    float2 texCoordDiffuse		: TEXCOORD0;
};

struct vertexOutput {
    float4 hPosition		: POSITION;
    float2 texCoordDiffuse	: TEXCOORD0;
};


vertexOutput VS_Screen(vertexInput IN) 
{
    vertexOutput OUT;
    OUT.hPosition = mul( IN.position, Proj );    
    OUT.texCoordDiffuse = IN.texCoordDiffuse;
    return OUT;
}


float4 PS_GaussianY7( vertexOutput IN): COLOR
{
	float pixelSizeH = 1.0f / ImageHeight;
	
	float3 blurred = float3( 0.0f, 0.0f, 0.0f);	
	
	float NUM_SAMPLES = 7;
	float2 coord;
	float4 thisGaussian;		
	
	pixelSizeH *= MaxSampleRadius * BlurFactor;
	
	coord = IN.texCoordDiffuse;
	for(int s=0; s<NUM_SAMPLES; s++)
	{
		thisGaussian = gaussian7[s];
		
		float texelOffset;      
		 // sample twice as far, but on half-texels so filtering takes into
        //  account both texels
     	texelOffset = pixelSizeH * (thisGaussian.x * 2 + 0.5f); 		
		coord.y = IN.texCoordDiffuse.y + texelOffset;
		
		blurred += tex2D(DiffuseTextureSampler, coord) * thisGaussian.y;
	}
		
	return float4( blurred, 1 );
}

float4 PS_GaussianY11( vertexOutput IN): COLOR
{
	float pixelSizeH = 1.0f / ImageHeight;
	
	float3 blurred = float3( 0.0f, 0.0f, 0.0f);	
	
	float NUM_SAMPLES = 11;
	float2 coord;
	float4 thisGaussian;		
		
	pixelSizeH *= MaxSampleRadius * BlurFactor;
	
	coord = IN.texCoordDiffuse;
	for(int s=0; s<NUM_SAMPLES; s++)
	{
		thisGaussian = gaussian11[s];
		
		 float texelOffset;      
		 // sample twice as far, but on half-texels so filtering takes into
        //  account both texels
     	texelOffset = pixelSizeH * (thisGaussian.x * 2 + 0.5f); 		
		coord.y = IN.texCoordDiffuse.y + texelOffset;
		blurred += tex2D(DiffuseTextureSampler, coord) * thisGaussian.y;
	}
		
	return float4( blurred, 1 );
}


float4 PS_GaussianY15( vertexOutput IN): COLOR
{
	float pixelSizeH = 1.0f / ImageHeight;
	
	float3 blurred = float3( 0.0f, 0.0f, 0.0f);	
	
	float NUM_SAMPLES = 15;
	float2 coord;
	float4 thisGaussian;
		
	pixelSizeH *= MaxSampleRadius * BlurFactor;
	
	coord = IN.texCoordDiffuse;
	for(int s=0; s<NUM_SAMPLES; s++)
	{
		thisGaussian = gaussian15[s];
		
        float texelOffset;
        // sample twice as far, but on half-texels so filtering takes into
        //  account both texels
     	texelOffset = pixelSizeH * (thisGaussian.x * 2 + 0.5f); 		
		coord.y = IN.texCoordDiffuse.y + texelOffset;
		blurred += tex2D(DiffuseTextureSampler, coord) * thisGaussian.y;
	}
		
	return float4( blurred, 1 );
}

float4 PS_GaussianY7NoFilter( vertexOutput IN): COLOR
{
	float pixelSizeH = 1.0f / ImageHeight;
	
	float3 blurred = float3( 0.0f, 0.0f, 0.0f);	
	
	float NUM_SAMPLES = 7;
	float2 coord;
	float4 thisGaussian;		
	
	pixelSizeH *= MaxSampleRadius * BlurFactor;
	
	coord = IN.texCoordDiffuse;
	for(int s=0; s<NUM_SAMPLES; s++)
	{
		thisGaussian = gaussian7[s];
		
		float texelOffset;      
		texelOffset = pixelSizeH * thisGaussian.x; 		
		coord.y = IN.texCoordDiffuse.y + texelOffset;
		
		blurred += tex2D(DiffuseTextureSampler, coord) * thisGaussian.y;
	}
		
	return float4( blurred, 1 );
}

float4 PS_GaussianY11NoFilter( vertexOutput IN): COLOR
{
	float pixelSizeH = 1.0f / ImageHeight;
	
	float3 blurred = float3( 0.0f, 0.0f, 0.0f);	
	
	float NUM_SAMPLES = 11;
	float2 coord;
	float4 thisGaussian;		
		
	pixelSizeH *= MaxSampleRadius * BlurFactor;
	
	coord = IN.texCoordDiffuse;
	for(int s=0; s<NUM_SAMPLES; s++)
	{
		thisGaussian = gaussian11[s];
		
		float texelOffset;      
		texelOffset = pixelSizeH * thisGaussian.x;
		coord.y = IN.texCoordDiffuse.y + texelOffset;
		blurred += tex2D(DiffuseTextureSampler, coord) * thisGaussian.y;
	}
		
	return float4( blurred, 1 );
}


float4 PS_GaussianY15NoFilter( vertexOutput IN): COLOR
{
	float pixelSizeH = 1.0f / ImageHeight;
	
	float3 blurred = float3( 0.0f, 0.0f, 0.0f);	
	
	float NUM_SAMPLES = 15;
	float2 coord;
	float4 thisGaussian;
		
	pixelSizeH *= MaxSampleRadius * BlurFactor;
	
	coord = IN.texCoordDiffuse;
	for(int s=0; s<NUM_SAMPLES; s++)
	{
		thisGaussian = gaussian15[s];
		
        float texelOffset;
        texelOffset = pixelSizeH * thisGaussian.x; 		
		coord.y = IN.texCoordDiffuse.y + texelOffset;
		blurred += tex2D(DiffuseTextureSampler, coord) * thisGaussian.y;
	}
		
	return float4( blurred, 1 );
}


//-----------------------------------
technique gaussian7
{
    pass p0 
    {		
		VertexShader = compile vs_2_0 VS_Screen();
		PixelShader  = compile ps_2_0 PS_GaussianY7();
		cullmode = none;
    }
}

technique gaussian11
{
    pass p0 
    {		
		VertexShader = compile vs_2_0 VS_Screen();
		PixelShader  = compile ps_2_0 PS_GaussianY11();
		cullmode = none;
    }
}

technique gaussian15
{
    pass p0 
    {		
		VertexShader = compile vs_2_0 VS_Screen();
		PixelShader  = compile ps_2_0 PS_GaussianY15();
		cullmode = none;
    }
}

//-----------------------------------
technique gaussian7NoFilter
{
    pass p0 
    {		
		VertexShader = compile vs_2_0 VS_Screen();
		PixelShader  = compile ps_2_0 PS_GaussianY7NoFilter();
		cullmode = none;
    }
}

technique gaussian11NoFilter
{
    pass p0 
    {		
		VertexShader = compile vs_2_0 VS_Screen();
		PixelShader  = compile ps_2_0 PS_GaussianY11NoFilter();
		cullmode = none;
    }
}

technique gaussian15NoFilter
{
    pass p0 
    {		
		VertexShader = compile vs_2_0 VS_Screen();
		PixelShader  = compile ps_2_0 PS_GaussianY15NoFilter();
		cullmode = none;
    }
}