Jump to content

HELP BLUR SHADER


Yamamoto

Recommended Posts

 

Is it possible to combine these two shaders so that a black and white blur comes out?

texture texture0;
float factor;
 
sampler Sampler0 = sampler_state
{
    Texture = (texture0);
    AddressU = MIRROR;
    AddressV = MIRROR;
};
 
struct PSInput
{
  float2 TexCoord : TEXCOORD0;
};
 
float4 PixelShader_Background(PSInput PS) : COLOR0
{
        float4 sum = tex2D(Sampler0, PS.TexCoord);
        for (float i = 1; i < 3; i++) {
                sum += tex2D(Sampler0, float2(PS.TexCoord.x, PS.TexCoord.y + (i * factor)));
                sum += tex2D(Sampler0, float2(PS.TexCoord.x, PS.TexCoord.y - (i * factor)));
                sum += tex2D(Sampler0, float2(PS.TexCoord.x - (i * factor), PS.TexCoord.y));
                sum += tex2D(Sampler0, float2(PS.TexCoord.x + (i * factor), PS.TexCoord.y));
        }
        sum /= 9;
        sum.a = 1.0;
        return sum;
}
 
technique complercated
{
    pass P0
    {
        PixelShader = compile ps_2_0 PixelShader_Background();
    }
}
 
technique simple
{
    pass P0
    {
        Texture[0] = texture0;
    }
}
//
// blackwhite.fx
//

texture screenSource;
 
sampler TextureSampler = sampler_state
{
    Texture = <screenSource>;
};

float4 PixelShaderFunction(float2 TextureCoordinate : TEXCOORD0) : COLOR0
{
    float4 color = tex2D(TextureSampler, TextureCoordinate);
 
    float value = (color.r + color.g + color.b) / 3; 
    color.r = value;
    color.g = value;
    color.b = value;
 
    return color;
}
 
technique BlackAndWhite
{
    pass Pass1
    {
        PixelShader = compile ps_2_0 PixelShaderFunction();
    }
}

 

Link to comment
texture texture0;
float factor;
 
sampler Sampler0 = sampler_state
{
	Texture = (texture0);
	AddressU = MIRROR;
	AddressV = MIRROR;
};
 
struct PSInput
{
	float2 TexCoord : TEXCOORD0;
};
 
float4 PixelShader_Background(PSInput PS) : COLOR0
{
	float4 sum = tex2D(Sampler0, PS.TexCoord);
	for (float i = 1; i < 3; i++) 
	{
		sum += tex2D(Sampler0, float2(PS.TexCoord.x, PS.TexCoord.y + (i * factor)));
		sum += tex2D(Sampler0, float2(PS.TexCoord.x, PS.TexCoord.y - (i * factor)));
		sum += tex2D(Sampler0, float2(PS.TexCoord.x - (i * factor), PS.TexCoord.y));
		sum += tex2D(Sampler0, float2(PS.TexCoord.x + (i * factor), PS.TexCoord.y));
	}
	sum /= 9;
	sum.a = 1.0;
	float value = (sum.r + sum.g + sum.b) / 3; 
	return float4(value, value, value, 1.0);
}
 
technique complercated
{
    pass P0
    {
        PixelShader = compile ps_2_0 PixelShader_Background();
    }
}

Test it 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...