Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question
2  
Have you tried making the texture smaller and manually adding a red border, then setting the wrapping mode to clamp? –  Mokosha Mar 20 '13 at 13:01
    
no I haven't, but this is very clever, thanks! –  pivotnig Mar 20 '13 at 13:09
    
@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 :) –  pivotnig Mar 20 '13 at 17:13
    
No problem. Glad it worked =) –  Mokosha Mar 20 '13 at 19:24
add comment

1 Answer

up vote 2 down vote accepted

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
share|improve this answer
1  
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. –  Jimmy Shelter Mar 20 '13 at 20:24
1  
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. –  Mokosha Mar 20 '13 at 21:17
1  
"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. –  Jimmy Shelter Mar 20 '13 at 21:41
    
@mho01 thanks for your suggestion –  pivotnig Mar 21 '13 at 10:58
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.