XNA Creators Club Online
foros de la comunidad
Page 1 of 1 (8 items)
Sort Posts: Previous Next

hlsl texture array

Last post 05/11/2009 13:18 by schobbejak. 7 replies.
  • 03/11/2009 9:49

    hlsl texture array

    I want a pixelshader to do lookups in an array of 256 textures. One of these textures will be updated each frame (the other 255 remaining unchanged).  I would prefer doing a lookup in a 3d texture, but a 3d texture cant be partially updated (updating it completely is not an option because of bandwidth).

    To initialize the textures and samplers I would like to do:

    texture texSlices[256];

    sampler sliceSamplers[256];

    for (int i = 0; i < 256; i++){
        sliceSamplers[i] = sampler_state
        {
            Texture = <texSlices[i]>;
        }
    }

    That does not work : it is complaning about the for loop. And even if it wasnt , this post says it wont work, and I have to outroll the loop.

    Is there an other way to access a large amount of data, which changes partly every frame?


    Edit: A sampler array is not a possibility : return tex2D(sliceSamplers[sliceIndex], uv); fails, because the arrayindex cant be a variable (....whose content cant be known at compile-time);
  • 04/11/2009 20:39 In reply to

    Re: hlsl texture array

    Are you sure about volume textures not doing partial updates? The docs imply that the LockBox-function records dirty regions. Sorry, I don't have much advice otherwise. Maybe tiling the data in a couple of large 2d-textures (depending on how much data it really is of course)?

    /Jimmy
    Buy Tank-tastic! here
  • 04/11/2009 22:03 In reply to

    Re: hlsl texture array

    Thanks.
    I have posted this in the wrong section I think. I thought because it was hlsl related, i'd put it in the direct3d section, but I am using xna. Your suggestion looks good, but I cant use native direct3d instructions in xna right?
    The second suggestion (couple of large 2d-textures) would be too wastefull for my project: I would need to use setdata() on a large texture, while I only really want to update a part of it.
  • 04/11/2009 23:31 In reply to

    Re: hlsl texture array

    try the setpixel function although thats also most likely not what you want to do.
  • 05/11/2009 0:10 In reply to

    Re: hlsl texture array

    The Texture3D class in XNA have an overload (of SetData) for passing the dimensions of the "sub-box" you want to update. I would assume/hope the underlying D3D method is called.

    /Jimmy
    Buy Tank-tastic! here
  • 05/11/2009 10:32 In reply to

    Re: hlsl texture array

    Thanks! that worked (using setdata() on part of a texture3d).
    The data I want to put in the texture3d is generated in hlsl, so it would be better if I could render to a slice of a rendertarget3d directly, and then use gettexture(). But a rendertarget3d does not exist, and a rendertargetcube only has 6 slices.

    So, if i understand correctly, the only way to fill a texture3d is by using setdata()?
  • 05/11/2009 12:17 In reply to

    Re: hlsl texture array

    Answer
    Reply Quote
    Yes in D3D9 the only way as far as I know is to update using SetData / Lock. In D3D10 you can of course use a texture array, but since you were using XNA that is not an option.

    How much data is it? If your card supports 8192x8192 2D textures, you can simulate a 512x512x256 volume texture (about 67Mb) with some pixel shader magic. Then it would be trivial to render to a selected 'slice' (just set the viewport). Of course this will be a lot less if there is only support for 4096 dimensions (256^3).

    /Jimmy
    Buy Tank-tastic! here
  • 05/11/2009 13:18 In reply to

    Re: hlsl texture array

    It will be about as much data as my videocard can handle (512 MB ati 4870).
    The simulated 3d texture on a 2d texture is a good idea; I think I will try it later on. I am using the "Color" surfaceformat without mips, so that would be 256 MB for 1 8k*8k texture, I think, which should be enough.
    Thanks for all the help.


Page 1 of 1 (8 items) Previous Next