Jump to content
  • Advertisement
Sign in to follow this  

Gaussian blur atlas map

This topic is 3585 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi i am trying to gaussian blur an atlas map. This is for a test to try to avoid a number of renderTarget sets for blurring my shadow maps. The code of the hlsl:
        // 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.

        #define SAMPLE_COUNT 11
        #define TILE_COUNT 4

        uniform extern float4 SampleOffsets[SAMPLE_COUNT];
        uniform extern float SampleWeights[SAMPLE_COUNT];
        uniform extern texture SceneTex;

        uniform extern float2 OffsetAClamp[TILE_COUNT];
        uniform extern float2 OffsetBClamp[TILE_COUNT];

        float mapID = 0;

        sampler TextureSampler = sampler_state
	        Texture = <SceneTex>;
	        MinFilter = POINT;
	        MagFilter = POINT;
	        MipFilter = POINT;
            AddressU = CLAMP;
            AddressV = CLAMP;

        float2 getUV(float2 UV)
            UV = clamp(UV, OffsetAClamp[mapID], OffsetBClamp[mapID]);

            return UV;

        float4 PixelShaderCode(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, getUV(texCoord + SampleOffsets.xy)) * SampleWeights;
                //c += tex2D(TextureSampler, texCoord + SampleOffsets.xy) * SampleWeights;           
            return c;

        technique GaussianBlur
            pass P0
                PixelShader = compile ps_2_b PixelShaderCode();
the clamp arrays are calculated as folllowing:
            for (int i = 0; i < Rows; i++)
                for (int j = 0; j < Rows; j++)
                    offsetAClamp[i * Rows + j] = new Vector2((1.0f / Rows) * j, (1.0f / Rows) * i);
                    offsetBClamp[i * Rows + j] = new Vector2((1.0f / Rows) * (j + 1), (1.0f / Rows) * (i + 1)) - new Vector2(1.0f / AtlasSize);
my question is, do you guys think this is an optimized way of avoiding rendertarget switches, and do you think this is more effective? Also, normally a blur uses a filter (linear) on the texture sampler, but since it is an atlas, i thought this would not be possible. Does any of you have any idea if this code is optimized enough and if so, if it is a very big lost that i don't have the sampler filter set to linear anymore?

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!