Download

Question about 3D textures for data lookup

I’m getting to a point where there’s quite a few things where having access to 3D textures in a material would be very useful - mainly for lookup tables of precomputed data. I understand UE4 doesn’t yet have 3D textures, so in general people are creating grids of 2D texture ‘slices’ of a 3D volume - as in the incredible work of Ryan Brucks, for example.

What I’m wondering (and I’m pretty new to all this and not coming from a CS background so this might be a stupid question) is what would be the problem with instead having a three dimensional array fully laid out inside a custom node?

Eg.
var[0][0][0] = 427.52117;
var[0][0][1] = 213.73671;

var[99][99][99] = 37363.26;

Then you could simply look up the appropriate value with the three indices, without having to calculate the correct UV position in a texture.

Obviously, for large arrays this could end up with some pretty big custom hlsl nodes, but what kind of effect would that have on performance compared to a texture? Is the problem that the array wouldn’t be initialised into memory and stay there, but have to be re-initialised every time the code is called (on each pixel I guess)? If so, then I suppose the benefit of using a texture is that it’s loaded into memory once and values can be read out from it any time without reloading it? I don’t know how shaders work under the hood or get compiled, so not sure if this even makes total sense.

UE4 has full support of 3D textures. They are not yet exposed to content browser/material editor level, sadly.

When comparing 3-dimensional array of floats, declared as static const variable in a shader, to 3d float texture, typically, they would be working with different memory, and the memory, you’d want to have your array in, was not/ is not designed for such purposes. I’d expect great variance between GPU makers and models, when reading large data from constant buffer memory, not speaking of the fact, that constant buffer memory is quite limited.Plus there are almost certainly additional platform/hardware restrictions applying.
I don’t think that you can declare const variable in a custom node either. Creating local array of variables in a custom node itself will certainly be exceptionally slow.

For a proper approach, you would need to pass your array via texture buffer, rather than using shader constants. You would need some coding done for that. Can’t use material editor alone.

The question touches more or less advanced parts of GPU architecture and there might be some further info on the subject on the web. Ultimately, it boils down to size of your array.

I’m working on this part of my project again so resurrecting this thread. You say that UE4 has full support of 3D textures, but not at the editor level - what does that mean exactly? If we wanted to use one in a project, is there any way to do it?
What would it take to implement on in a material?