Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

If I call tex1d from my pixel shader on a texture that has been initialized as a texture2d will it treat the data as a one dimensional array and then just take the element at whichever position you specify?

For instance if you have a 10 x 10 texture(that would be a one dimensional array 100 elements in length) and you call tex1d(mySampler, 0.95) will it give you back element 95?

share|improve this question
up vote 1 down vote accepted

I think you will find this quote (regarding DirectX 9, which is what XNA is built on) relevant:

Because the runtime does not support 1D textures, the compiler will use a 2D texture with the knowledge that the y-coordinate is unimportant. Since tex1D(s, t) (DirectX HLSL) is implemented as a 2D texture lookup, the compiler is free to choose the y-component in an efficient manner.

In other words: you specify the X coordinate, and the Y coordinate is undefined.

From here.

So, no, it won't unwrap the indices. But you already got an answer about how to do that.

share|improve this answer

I haven't used XNA, but my guess is that calling tex1D on a 2D texture (or more generally any mismatch between the dimensionality of the sampling function and the actual texture being sampled) is an error, and will probably return some default value like black.

share|improve this answer
Do you know how I could access the Nth element of a texture2d? – Mr Bell Nov 16 '11 at 22:38
@MrBell see my answer to your other question. – Nathan Reed Nov 16 '11 at 22:46

Your Answer


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.