0
votes

I am trying to implement a gaussian blur with convolution matrix on my shader.

This is the code i have:

float4 ppPS(float2 uv : TEXCOORD0, uniform sampler2D t1) : COLOR { 
  //kernel matrix
  float3x3 kernel={1*(1/16),2*(1/16),1*(1/16),
  2*(1/16),4*(1/16),2*(1/16),
  1*(1/16),2*(1/16),1*(1/16)
  };

  int x,y;
  float2 sum = 0;
  for (x = -1; x <= 1; x++)
  {
    for (y = -1; y <= 1; y++)
    {
      float2 fl;
      fl.x = uv.x+x;
      fl.y = uv.y+y; 
      sum += (fl)*(kernel[x+1][y+1]);
    }
  }
  return tex2D(t1, sum);
 }

but for some reason, i get a picture all in one solid color.

Here is the image without the blur:

non blur

Here is the image with the so called blur:

with blur

any idea of what am i doing wrong over here?

1
You are applying the filter to the texture coordinates, not to the texture itself.sbabbi
but how can i apply the filter on the texture? im sorry but i have no experience of itItzik984

1 Answers

1
votes

Try to change the float3x3 initialize values into floating point format (.0f) otherwise all the values will end up as 0.

 //kernel matrix
 static const float3x3 kernel={1*(1.0f/16.0f),2*(1.0f/16.0f),1*(1.0f/16.0f),
 2*(1.0f/16.0f),4*(1.0f/16.0f),2*(1.0f/16.0f),
 1*(1.0f/16.0f),2*(1.0f/16.0f),1*(1.0f/16.0f)
};

After this change you wouldn't see the blank output image !!!