• 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.

# Post Processing Texel Offsets

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.

2 replies to this topic

Posted 13 February 2012 - 11:47 PM

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

float4 Color = 0;

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



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.

### #2Tsus  Members

Posted 14 February 2012 - 04:21 AM

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.
Cheers!