# Does XNA support 1 dimensional textures

Does XNA support 1 dimensional textures. And by 1 dimension texture I mean something like Texture1d not a Texture2d where one dimension is 1 (because of the 4096 limit)

• 1 dimensional? Like a line? Which has no thickness? Nov 17 '11 at 0:33
• X-Zero, yes, I mean like a line. More specifically, though, I mean like a 1 dimensional array of data that can be passed to a pixel shader Nov 17 '11 at 0:41
• Can't you make your own 1D array with your data in it? Unless your question is whether or not you can pass 1D of data to a pixel shader, which I have no experience in.
– DMan
Nov 17 '11 at 0:59
• Couldn't you just pass in a 2D texture, and in the shader code turn off extra sampling, then treat it as 1D Nov 17 '11 at 7:52
• It looks like it might support Texture1D; but I couldn't get it to work. Nov 17 '11 at 9:42

As per my comment, SetValue(Vector4[]) does not work. However, you should be able to use a Texture2D to achieve what you are after.

You can map a one-dimensional index to a two-dimensional index using the following function:

x = index % width;
y = (index - x) / width;


Therefore you can simply perform a SetData(Vector4[]) on a Texture2D and map the indicies within the shader (make sure you use point sampling). If you use all the pixels in a 4096x4096 texture you will effectively have an array that can contain 16777216 values.

int ValuesStride = 4096; // a.k.a Width.
texture2D Values;
sampler2D ValuesSampler =
sampler_state
{
Texture = <Values>;
Filter = POINT;
};

float4 PixelShaderFunction(float4 Position : POSITION0, float2 UV : TEXCOORD0) : COLOR0
{
var value = ArrayLookup(ValuesSampler, ValuesStride, 100);
// ...
}

float4 ArrayLookup(sampler2D sampler, int width, int index)
{
float2 coord = (float2)0;
coord.x = index % width;
// We don't need to subtract coord.x because of how integral math works.
coord.y = asint(index / width);
return tex2D(sampler, coord);
}


HLSL has a Texture1D but XNA doesn't. I know little about shaders but I suggest you start first checking if the included basic effect supports Texture1D. If so then you just need to store in a buffer then pass it to the effect. If not you have to implement it from the ground up.

Not sure if it does but I hope that helps.