Hm, okay, makes sense.
I created following class:
public class TextureArray : Texture2D
{
public TextureArray(GraphicsDevice graphicsDevice, int width, int height, int arraySize) :
base(graphicsDevice, width, height, true, SurfaceFormat.Color, SurfaceType.Texture, false, arraySize)
{
}
public void Add(int index, Texture2D texture)
{
Color[] pixelData = new Color[texture.Width * texture.Height];
texture.GetData<Color>(pixelData);
this.SetData<Color>(0, index, null, pixelData, 0, pixelData.Length);
}
}
I pass the two textures this way:
mTexArray = new TextureArray(GlobalRessources.GraphicsDevice, 256, 256, 2);
mTexArray.Add(0, mTex);
mTexArray.Add(1, mTex1);
My hlsl-shader:
Texture2DArray Textures;
sampler sMainTextureSampler = sampler_state
{
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
ADDRESSU = Wrap;
ADDRESSV = Wrap;
};
float4 MainPS(VertexShaderOutput input) : COLOR
{
float4 color = Textures.Sample(sMainTextureSampler, float3(input.TextureCoordinate, INDEX));
return color;
}
It “works” - if I set INDEX to 0, it shows the first texture, if I set it to 1 it shows the other one… but only if
my camera is near enough to face, otherwise it fades out to black…:
Why?
Best regards.
_