Jump to content

  • Log In with Google      Sign In   
  • Create Account


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.

  • You cannot reply to this topic
2 replies to this topic

#1 Endemoniada   Members   -  Reputation: 291

Like
0Likes
Like

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

// pixel shader part
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.

Sponsor:

#2 Tsus   Members   -  Reputation: 992

Like
1Likes
Like

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

Acagamics e.V. – IGDA Student Game Development Club (University of Magdeburg, Germany)


#3 Endemoniada   Members   -  Reputation: 291

Like
0Likes
Like

Posted 15 February 2012 - 09:33 PM

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




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.



PARTNERS