Passing an array of Texture2D to a HLSL shader

I m trying to add shadows to my Pointlight Shader…
the Shader already works fine for a custom number of pointlights, and now I have written code in my monogame project that renders for every Pointlight 6 Shadow-maps (for every axis direction one), and inserted them in an Texture2D Array, size 6 * n (n = max number of pointlights)

in my Shader I added:

texture ShadowMaps[MaxLightNum*6];
SamplerState ShadowMapSampler
{
MinFilter = point;
MagFilter = point;
MipFilter = point;
AddressU = Wrap;
AddressV = Wrap;
};

float4 color = ShadowMaps[0].Sample(ShadowMapSampler, pos);

and monogame content pipeline is fine with that when I build the shader, so I assume an array of textures is allowed in monogame…

though when I try to pass the Texture2D array to the Shader by using:

_Shadows = Global._shader.Parameters[“ShadowMaps”];

_Shadows.SetValue(_shadowMaps);
(with _shadowMaps being my Texture2D array)

it underlines _shadowMaps red and says cant convert Texture2D[] to bool ?

what am I doing wrong?

Instead of passing an array of textures, you need to pass a single texture, that contains the array.

uhm… how do I add an array to a texture?

in the past few hours I already read the same thing somewhere else and tryed to find out how that works, though I couldn t find documentation regarding what most of the Texture2D or RenderTarget2D functions do, online…

I tryed something like

_shadows.SetData(_shadowMaps);

with _shadows being Texture2D and _shadowMaps beign Texture2D[]

though that wouldn t work, told me off, because Texture2D is nullable…

also tryed putting every shadowMap texture in an own Level of a single seperate shadow map, also with SetData, though ran into the problem that the Level of that texture was initialized with 1, and I couldn t find out how to change that^^

I probably don t quite understand how the Texture2D functions are meant, though for some reason, they seem to have no explaination/ definition anywhere online… at least I couldn t find anything^^

so how can I make a single texture contain the array?

thanks

The Texture2D constructor has an overload that takes an ArraySize parameter to specify how big the internal texture array should be. Texture2D.SetData has an overload that takes an array index.