[HLSL] Pixel Shader, what's the best way to sample bordering pixels

Started by
3 comments, last by jollyjeffers 15 years, 10 months ago
What's the best way to sample the pixel next to the one you're working on? Or will simply, using

TEXCOORD0 tex;
Center_Color = tex2D(texture, tex);

// to sample the pixel to the left
tex.x -= 1;
Left_Color = tex2D(texture, tex);

Or maybe you can point me to a simple example that does an outline around a texture? The problem I see is that UV coords aren't done in integral increments but rather by percentage of the total texture size so how would I find out what the exact amount is to increment by?
[ dev journal ]
[ current projects' videos ]
[ Zolo Project ]
I'm not mean, I just like to get to the point.
Advertisement
You could always pass in the size of your texture as a variable, so, the pixel one to the left would be:
tex2D(sampler, texCoord + float2(-1.0f / textureWidth, 0.0f);
Yeah, in the past I've used a uniform variable called texelSize (or something) and set it to 1/textureSize (e.g. 1/256.0)
Quote:Original post by andur
You could always pass in the size of your texture as a variable, so, the pixel one to the left would be:
tex2D(sampler, texCoord + float2(-1.0f / textureWidth, 0.0f);


Figured so, Was just hoping there was a way that didn't require passing mor info than the texture.
[ dev journal ]
[ current projects' videos ]
[ Zolo Project ]
I'm not mean, I just like to get to the point.
Direct3D 10 and beyond allow you to sample the metadata for a texture and thus avoid having to send in an extra constant. However, with SM3 and below you're stuck with the ways described here [smile]


Jack

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

This topic is closed to new replies.

Advertisement