Gaussian blur atlas map

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

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;
};

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
{

}
}

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?

• 16
• 13
• 23
• 10
• 19