[SOLVED] Texture3D invalid argument exception

Hi guys.

I’m new in this community and I’m starting to approach Monogame.

My first test was to render a 3D volume, loaded from a .raw file.
My idea is to create a 3D texture, the next steps are not important in order to explain you my current problem.

I immediately had problems with an exception when texture was created.

Here’s a bit of code:

public void InitializeVolume(GraphicsDevice d, BasicEffect effect)
{
    // Exception in the next line "HRESULT: [0x80070057], Module: [General], ApiCode: [E_INVALIDARG/Invalid Arguments], Message: Incorrect parameter.
    _volume = new Microsoft.Xna.Framework.Graphics.Texture3D(Game1.Instance.GraphicsDevice, _width, _height, _depth, false, SurfaceFormat.Single);
            
    _volume.SetData(_scalars);  // Scalars are an array of normalized float( [0 -> 1])

    effect.Parameters["Volume"].SetValue(_volume);
 }

There is some problem with the parameters? Why?
Do you have any idea?
Do not be afraid to answer, so I can continue with my study. :sweat_smile:
Thanks very much!

EDIT The problem was that the depth was not divisible by 4.:joy::sweat_smile:
@Alkher Thanks the same, if you have other tips are welcome.

I’m not sure Texture3D can be used with a BasicEffect. One important thing is… there is no “Volume” parameter on a BasicEffect… So SetValue will fail.
I would say, you should use the Effect class.
But to render a volume you should create vertices instead. How will you rotate it ? It would be expensive to always sample the texture, moreover when it is using high sizes. (By the way what size are you using ?)

Thanks for the answer.
Ok, I’ll use the Effect class.
My goal is to render volumes of 512x512x512 pixels, or even 1024x1024x1024.
The plan was to create a 3D texture and apply it to a cube, and then rotate the cube.
Do you think I should do it in another way?
Any advice is well accepted.

TextureCube would then be better for that (a cube with 6 faces)
Texture3D is 3D, i mean: with a volume of 512x512x512, you not only have the 6 faces, but also the interior can be sampled. Maybe it is what you want, but I’ve never used this, rarely seen it in use in a game too

Yes, that’s exactly what I’m looking for. Next, I will apply a “transfer function” to change the aspect of the volume.
In any case thank you for the advice.