How to read data from a Texture3D?

With a 2d texture something like this works
char* TextureDataPtr = (char*)RHICmdList.LockTexture2D(Texture, 0, EResourceLockMode::RLM_ReadOnly, LolStride, false);

Anyone know how I would do the same with a 3d texture?

I’ve only ever done this in 2D so I would assume it probably works the same way, but I have no idea what the “stride” is for 3D. <aybe it requires a loop to read each “slice” in 2D to build up the 3D data?

Also bear something in mind - regardless of what resolution you set the texture to - it will always come back in the nearest power-of-two format. Got caught out by that one when making my plug-in.

I’m not sure I understand what you mean, that function only accepts Texture2D(RHIRef).

I was able to sort of get Texture2DArray to work; that functions similar to a 3D texture. I’m only getting the same data out of each texture in the array though… so I must be missing something.


Texture = RHICreateTexture2DArray(SizeX, SizeY, SizeZ, PF_R32_UINT, 1, TexCreate_ShaderResource | TexCreate_UAV, CreateInfo)
char* TextureDataPtr = (char*)RHICmdList.LockTexture2DArray(Texture, Z, 0, EResourceLockMode::RLM_ReadOnly, LolStride, false);

edit: nvm, apparently my unreal project is just bugging out on me, I had to close/restart the editor…

So looking further into the various RHI classes, for example the OpenGLTexture, I can see how to write to a 3d texture but I still can’t find a way to read from 3d textures… In fact, where the GetTexImage is called, it even has a check to make sure there is no depth to the texture… I guess I’ll have to add this feature if I want it? Or am I missing something?

edit: noticed in 4.20 that there has been some work on a VolumeTextureAsset, I’ll check that out next