Post Processing Texel Offsets

Started by
1 comment, last by Endemoniada 12 years, 2 months ago
Hi guys, I'm trying to do a simple horizontal blur filter. I don't understand what to use for the texture coordinate values.

This is from the DirectX PostProcess sample:



// what the hell is this ?
float2 TexelKernel[g_cKernelSize]
<
string ConvertPixelsToTexels = "PixelKernel";
>;

// pixel shader part
float4 Color = 0;

for(int i=0;i<g_cKernelSize;i++){
Color += tex2D( g_samSrcColor, Tex + TexelKernel.xy ) * BlurWeights;
}



I am pretty sure a texel is either:

texel=1/textureWidth;
or
texel=1/(textureWidth-1);

(which one ?)

...so is the TexelKernel x-values for a 5-sample filter simply:



TexelKernel[0].x= -2*texel;
TexelKernel[1].x= -1*texel;
TexelKernel[2].x= 0;
TexelKernel[3].x= 1*texel;
TexelKernel[4].x= 2*texel;



Thanks.
Advertisement
Hi!


texel=1/textureWidth;

That one.

There is a small difference in the alignment of pixels and texels.
If you are using D3D9, you may want to look at this.
Or if you are using D3D10+ then look at this.

If you use Dx10+ you can consider using the Load intrinsic. It allows fetching data without filtering or sampling and is thus much faster if you want to access texels directly. Small sample:
inputTexture.Load(int3(input.Position.xy, 0));

The position argument of the Load intrinsic is in integers, which means in [0…width-1]x[0…height-1]. The xy component of the SV_Position gives you in a pixel shader the position of the current pixel in device coordinates (with a half texel offset but that will be truncated if you cast it to int.)

Hope it helps. smile.png
Cheers!
Thank you. I finally read the Directly Mapping Texels to Pixels (DIrect3D 9) article (twice) and seem to fully understand it now.

This topic is closed to new replies.

Advertisement