Problem With Hlsl Of Blur

Started by
3 comments, last by jvfl 7 years, 8 months ago

Im trying run some shader of blur in my game, but nothing happen and the render be normal, without blur..

HLSL Code:


sampler ColorSampler1 : register(s0);

#define SAMPLE_SIZE 15

float2 texelSize = {1/1024,1/768};
float offsets[SAMPLE_SIZE] = {-0.006836,-0.005859,-0.004883,-0.003906,-0.002930,-0.001953,-0.000977,0.000000,0.000977,0.001953,0.002930,0.003906,0.004883,0.005859,0.006836};
float weights[SAMPLE_SIZE] = {0.008847,0.018216,0.033562,0.055335,0.081638,0.107778,0.127325,0.134598,0.127325,0.107778,0.081638,0.055335,0.033562,0.018216,0.008847};

float4 PS_BlurH(float2 texCoord : TEXCOORD0) : COLOR0
{
	float4 sum = float4(0.0, 0.0, 0.0, 1.0);
	
	for (int i = 0; i < SAMPLE_SIZE; i++)
		sum += tex2D(ColorSampler1, float2(texCoord.x + (offsets[i] * texelSize.x), texCoord.y)) * weights[i];
	
	clip(sum.a < 0.01f ? -1 : 1);
	
	return sum;
}

float4 PS_BlurV(float2 texCoord : TEXCOORD0) : COLOR0
{
	float4 sum = float4(0.0, 0.0, 0.0, 1.0);
	
	for (int i = 0; i < SAMPLE_SIZE; i++)
		sum += tex2D(ColorSampler1, float2(texCoord.x, texCoord.y + (offsets[i] * texelSize.y))) * weights[i];
	
	clip(sum.a < 0.01f ? -1 : 1);
	
	return sum;
}

technique Glow
{
	pass BlurHorizontal
	{
		PixelShader = compile ps_2_0 PS_BlurH();
	}
	
	pass BlurVertical
	{
		PixelShader = compile ps_2_0 PS_BlurV();
	}
}

Screenshot:

b7189a0e52.png

As can see in pic, nothing happens with meshe, dno why.. If i change values of offsets and weights same thing... Blur dont work.

Someone know what can be? Thanks

Advertisement
Did you test if the expected pixel shader is executed at all, I.e output a static color?

First for the horizontal pass and then for the vertical.

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

Maybe the render target is still bound as a input somewhere?

Don't quite understand this:

float4 sum = float4(0.0, 0.0, 0.0, 1.0);

sum += ....

clip(sum.a < 0.01f ? -1 : 1);

alpha channel will never be less than 1.0 because that's what it starts with and you're only adding to it?

.:vinterberg:.

Thanks for all, I got it, i remade shader and now the blur works...

Now I need clip mesh from render and leave just the silhouette. Some idea?

I can do this:

41b19e1a63.jpg

but, i need to draw just the silhouette outline,

anyone can help? Thanks ^^

This topic is closed to new replies.

Advertisement