Complex Blur

From GameStudio Wiki

Jump to: navigation, search

Lite-C:


Material and function to adjust the effect:

// Blur in all directions (Highquality)
MATERIAL* ComplexBlur_mat =
{
	effect = "complex_blur.fx";
}

function ComplexBlur_set_Value(Blur)
{
	ComplexBlur_mat.skill1 = floatv(Blur);	// should be very small between 0.001 and 0.05
}

The complex_blur.fx file:

//Complex blur in each direction, change the strength with vecSkill1[0]

float4 vecSkill1;

float2 samples[12]
=	{
		-0.326212, -0.405805,
		-0.840144, -0.073580,
		-0.695914,  0.457137,
		-0.203345,  0.620716,
		 0.962340, -0.194983,
		 0.473434, -0.480026,
		 0.519456,  0.767022,
		 0.185461, -0.893124,
		 0.507431,  0.064425,
		 0.896420,  0.412458,
		-0.321940, -0.932615,
		-0.791559, -0.597705
	};
	
texture TargetMap;

sampler postTex = sampler_state
{
   texture = (TargetMap);
   MinFilter = linear;
   MagFilter = linear;
   MipFilter = linear;
   AddressU = Clamp;
   AddressV = Clamp;
};

float4 Blur_PS(float2 texCoord: TEXCOORD0) : COLOR
{
	float4 color;

	color = tex2D(postTex, texCoord);

	for (int i = 0; i < 12; i++)
	{
		color += tex2D(postTex, texCoord + vecSkill1[0] * samples[i]);
	}

	return color / 13;
}

technique tech_00
{
	pass pass_00
	{
		VertexShader = null;
		PixelShader = compile ps_2_0 Blur_PS();
	}
}

technique fallback { pass one { } }


C-Script


Material and function to adjust the effect:

// Blur in all directions (Highquality)
material ComplexBlur_mat
{
	effect = "complex_blur.fx";
}

function ComplexBlur_set_Value(Blur)
{
	ComplexBlur_mat.skill1 = floatv(Blur);	// should be very small between 0.001 and 0.05
}

The complex_blur.fx file:

//Complex blur in each direction, change the strength with vecSkill1[0]

float4 vecSkill1;

float2 samples[12]
=	{
		-0.326212, -0.405805,
		-0.840144, -0.073580,
		-0.695914,  0.457137,
		-0.203345,  0.620716,
		 0.962340, -0.194983,
		 0.473434, -0.480026,
		 0.519456,  0.767022,
		 0.185461, -0.893124,
		 0.507431,  0.064425,
		 0.896420,  0.412458,
		-0.321940, -0.932615,
		-0.791559, -0.597705
	};
	
texture entSkin1;

sampler postTex = sampler_state
{
   texture = (entSkin1);
   MinFilter = linear;
   MagFilter = linear;
   MipFilter = linear;
   AddressU = Clamp;
   AddressV = Clamp;
};

float4 Blur_PS(float2 texCoord: TEXCOORD0) : COLOR
{
	float4 color;

	color = tex2D(postTex, texCoord);

	for (int i = 0; i < 12; i++)
	{
		color += tex2D(postTex, texCoord + vecSkill1[0] * samples[i]);
	}

	return color / 13;
}

technique tech_00
{
	pass pass_00
	{
		VertexShader = null;
		PixelShader = compile ps_2_0 Blur_PS();
	}
}

technique tech_01
{
	pass pass_00
	{
		Texture[0] = <entSkin1>;
	}
}

--Slin 00:55, 11 November 2007 (CET)

Personal tools