Jump to content
  • Advertisement
Sign in to follow this  
freeworld

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

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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);

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!