2
\$\begingroup\$

In WinRT the border color texture address mode is not supported.

The best I came up with in emulating the border address mode, is doing this in my pixel shader:

float4 tcol = tex.Sample(texSampler, texCoord);

if(texCoord.x < 0 || texCoord.y < 0 || texCoord.x > 1 || texCoord.y > 1)
  tcol = borderColor;

But as only ps_4_0_level_9_1 is supported as minimum requirement in WinRT, this conditional in the pixel shader is quite inefficient.

How would I emulate border texture addressing mode efficiently?

\$\endgroup\$
4
  • 2
    \$\begingroup\$ Have you tried making the texture smaller and manually adding a red border, then setting the wrapping mode to clamp? \$\endgroup\$
    – Mokosha
    Mar 20, 2013 at 13:01
  • \$\begingroup\$ no I haven't, but this is very clever, thanks! \$\endgroup\$ Mar 20, 2013 at 13:09
  • \$\begingroup\$ @Mokosha your suggestion worked for me with zero performance impact. I just had to shift and zoom my texture coordinates for the 1 pixel border. If you make an answer of your comment you get my vote :) \$\endgroup\$ Mar 20, 2013 at 17:13
  • \$\begingroup\$ No problem. Glad it worked =) \$\endgroup\$
    – Mokosha
    Mar 20, 2013 at 19:24

1 Answer 1

2
\$\begingroup\$

Although it was just a guess, the following method seems to work:

  1. Shrink your texture by one pixel in all directions
  2. Manually add a red border
  3. Set the texture wrapping mode to clamp
\$\endgroup\$
3
  • 1
    \$\begingroup\$ Instead of shrinking the texture I'd expand it by 1 texel in all directions and adjust texcoords. D3D11 guarantees non-power-of-two support and this would preserve image quality. \$\endgroup\$ Mar 20, 2013 at 20:24
  • 1
    \$\begingroup\$ Non power of two has performance implications regardless of whether or not the underlying API supports it. However, this would probably be the easiest solution that preserves image quality unless you add a border to reach the next power of two in each dimension and adjust the texture coordinates accordingly. This method might not be particularly memory efficient, however. \$\endgroup\$
    – Mokosha
    Mar 20, 2013 at 21:17
  • 1
    \$\begingroup\$ "This method might not be particularly memory efficient, however" - quite true; drivers are perfectly free to pad non-power-of-two textures (hence the "RowPitch" member of a mapped subresource struct) and I've personally seen some recent AMD drivers doing so. Adding a 1 texel border could result in a quadrupling of texture size! I guess it comes down to which tradeoff the OP prefers. \$\endgroup\$ Mar 20, 2013 at 21:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .