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.

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)

share|improve this question
1  
1 dimensional? Like a line? Which has no thickness? –  Clockwork-Muse 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 –  Mr Bell 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 –  George Duckett Nov 17 '11 at 7:52
    
It looks like it might support Texture1D; but I couldn't get it to work. –  Jonathan Dickinson Nov 17 '11 at 9:42
add comment

2 Answers

up vote 2 down vote accepted

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;
  AddressU = CLAMP;
  AddressV = CLAMP;
};

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);
}
share|improve this answer
add comment

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.

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.