• FEATURED

View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# Problem with bluring using compute shader

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

### #1BlackBrain  Members

Posted 15 August 2014 - 05:55 PM

Hello.

I have implemented Gaussian Blur using compute shaders and it works good but as I increase the alpha the outcome becomes darker and darker. And I don't know understand why because the weights sum is equal to one.

This is how I calculate weights :

void CalculateWeights()
{
weights = new float[2 * BlurRadius+1];

for (int i = 0; i < weights.Length; i++)
{
weights[i] = (float)Math.Exp(- (  (x*x)/(2*Alpha*Alpha)  )  ) ;
}

float sum = 0;

foreach (float weight in weights)
{
sum += weight;
}

for (int i = 0; i < weights.Length; i++)
{
weights[i] /= sum;
}

}


And this is Horizontal Blur shader:

cbuffer Globals
{
float Width;
float Height;
};

Texture2D Input;
RWTexture2D<float4> Output;

SamplerState ClampSampler
{
Filter = MIN_MAG_MIP_LINEAR;

};

{

//set left pixels
{
}

//set right pixels
{
}

// Wait for all threads to finish sampling
GroupMemoryBarrierWithGroupSync();

float4 blurColor = float4(0,0,0,0);

[unroll]
{
}

}

technique11 Tech0
{
pass P0
{
}
}


cbuffer Globals
{
float Width;
float Height;
};

Texture2D Input;
RWTexture2D<float4> Output;

SamplerState ClampSampler
{
Filter = MIN_MAG_MIP_LINEAR;

};

{

//set up pixels
{
}

//set down pixels
{
}

// Wait for all threads to finish sampling
GroupMemoryBarrierWithGroupSync();

float4 blurColor = float4(0,0,0,0);

[unroll]
{
}

}

technique11 Tech0
{
pass P0
{
}
}


Any idea why is this happening? The darkening is more clear when Blur radius is a low number such as 2 or 3.

### #2BlackBrain  Members

Posted 16 August 2014 - 12:37 PM

I figured it out myself. the for loops shoud be as follows :

{
}