TEXCOORD0 tex;
Center_Color = tex2D(texture, tex);
// to sample the pixel to the left
tex.x -= 1;
Left_Color = tex2D(texture, tex);
[HLSL] Pixel Shader, what's the best way to sample bordering pixels
What's the best way to sample the pixel next to the one you're working on? Or will simply, using
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?
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);
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.
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
Jack
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement