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.

I'm using the tex2D function of HLSL, and I am wondering what will happen if I try to grab a pixel from a pixel coordinate outside of my texture (as an example 1.1). Will it clamp? Will it repeat the texture and grab something else? Will it return transparent?

share|improve this question
1  
Depends on how the texture is defined I suppose - I haven't used XNA, but textures (or texture stages) generally have options on whether to wrap, mirror or clamp. –  Jari Komppa Sep 22 '11 at 6:52
    
Could you make an answer that explains these 3 types, and what they do? I'll mark that as the answer then. –  Mathias Lykkegaard Lorenzen Sep 22 '11 at 7:10
add comment

1 Answer

up vote 13 down vote accepted

Depends on how the texture is defined I suppose - I haven't used XNA, but textures (or texture stages) generally have options on whether to wrap, mirror or clamp.

In OpenGL, the wrap type is defined on the texture object, on DirectX it's set in texture stages. Both have their good and bad sides.

Common wrap types include:

  • Clamp to edge - repeats the bordermost texel when reading outside the texture

  • Clamp to border - any uv coordinates outside the rectange return a separately set border color (probably OpenGL specific)

  • Mirror - the borders act as mirrors for the uv coordinates, creating a "pingpong" effect

  • Wrap or Repeat - the texture repeats from the opposite edge

share|improve this answer
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.