Tell me more ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am trying to implement the bloom effect, available in XNA http://create.msdn.com/en-US/education/catalog/sample/bloom, but with SlimDX and directX9.

My problems begin with the gaussian blur, instead of a nice fade out effect, all i get are blocky images:

see what "NET" text becomes: http://imgur.com/LgjbB

this is the blur effect code, copied directly from the XNA sample:

    void SetBlurEffectParameters(float dx, float dy)
    {            
        // Look up how many samples our gaussian blur effect supports.
        int sampleCount = 15; // weightsParameter.Elements.Count;

        // Create temporary arrays for computing our filter settings.
        float[] sampleWeights = new float[sampleCount];
        Vector2[] sampleOffsets = new Vector2[sampleCount];

        // The first sample always has a zero offset.
        sampleWeights[0] = ComputeGaussian(0);
        sampleOffsets[0] = new Vector2(0, 0);

        // Maintain a sum of all the weighting values.
        float totalWeights = sampleWeights[0];

        // Add pairs of additional sample taps, positioned
        // along a line in both directions from the center.
        for (int i = 0; i < sampleCount / 2; i++)
        {
            // Store weights for the positive and negative taps.
            float weight = ComputeGaussian(i + 1);

            sampleWeights[i * 2 + 1] = weight;
            sampleWeights[i * 2 + 2] = weight;

            totalWeights += weight * 2;

            // To get the maximum amount of blurring from a limited number of
            // pixel shader samples, we take advantage of the bilinear filtering
            // hardware inside the texture fetch unit. If we position our texture
            // coordinates exactly halfway between two texels, the filtering unit
            // will average them for us, giving two samples for the price of one.
            // This allows us to step in units of two texels per sample, rather
            // than just one at a time. The 1.5 offset kicks things off by
            // positioning us nicely in between two texels.
            float sampleOffset = i * 2.0f +1.5f;

            Vector2 delta = new Vector2(dx, dy) * sampleOffset;

            // Store texture coordinate offsets for the positive and negative taps.
            sampleOffsets[i * 2 + 1] = delta;
            sampleOffsets[i * 2 + 2] = -delta;
        }

        // Normalize the list of sample weightings, so they will always sum to one.
        for (int i = 0; i < sampleWeights.Length; i++)
        {
            sampleWeights[i] /= totalWeights;
        }

        // Tell the effect about our new filter settings.            
        gaussianBlurEffect.SetValue("SampleWeights", sampleWeights);
        gaussianBlurEffect.SetValue("SampleOffsets", sampleOffsets);

    }


    float ComputeGaussian(float n)
    {
        float theta = Settings.BlurAmount;

        return (float)((1.0f / Math.Sqrt(2.0f * Math.PI * theta)) *
                       Math.Exp(-(n * n) / (2.0f * theta * theta)));
    }

And this is the shader:

// Pixel shader applies a one dimensional gaussian blur filter.
// This is used twice by the bloom postprocess, first to
// blur horizontally, and then again to blur vertically.

sampler TextureSampler : register(s0);

#define SAMPLE_COUNT 15

float2 SampleOffsets[SAMPLE_COUNT];
float SampleWeights[SAMPLE_COUNT];


float4 PixelShaderFunction(float2 texCoord : TEXCOORD0) : COLOR0
{
    float4 c = 0;    
    // Combine a number of weighted image filter taps.
    for (int i = 0; i < SAMPLE_COUNT; i++)
    {
        c += tex2D(TextureSampler, texCoord + SampleOffsets[i]) * SampleWeights[i];
    }    

    return c;
}


technique GaussianBlur
{
    pass Pass1
    {
        PixelShader = compile ps_2_0 PixelShaderFunction();
    }
}

Have any of you guys seen this behavior?

share|improve this question
Are you using correct effect setting? I don't know, how it's named in DX9, this is its name in XNA. I mean: Do you have correct filtering? As is written in comments. And you should also check other texture sampling / filtering / etc. parameters. – zacharmarz Feb 20 '12 at 14:21

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.