I want to use and interpolated 4D texture in OpenGL, i.e. a texture that is accessed with a texture coordinate vector (s, t, p, q) and interpolated linearly in every texture coordinate.

The extension GL_SGIS_texture4D does exactly this. However, it is unsupported on literally every GPU I have access to.

If the was a GL_TEXTURE_3D_ARRAY, I guess I could sample the appropriate 2 layers of a 3D array texture with the (s, t, p) coordinates and then manually interpolate in the q coordinate. However, there are only "ordinary" GL_TEXTURE_2D_ARRAY texture arrays. A possible solution is to treat the texture array as 2D array of 2D texture, sample the appropriate 4 layers with (s, t) and then manually interpolate in p and q. This method is somewhat constrained by GL_MAX_ARRAY_TEXTURE_LAYERS​. I am also afraid of the relatively large number of 2D texture fetches required to fetch a single 4D texture value.

Is there a simpler way of achieving 4D interpolated textures?

  • 2
    \$\begingroup\$ You mean s, t, p, q. I know this sounds pedantic, but GLSL does not let you mix-and-match swizzle component sets. w belongs to xyzw, t belongs to stpq and r belongs to rgba. Logically, these coordinates would normally be s, t, r, q, but GLSL uses p as a synonym for the 3rd component in texture coordinates. Otherwise, r would refer to the first component. \$\endgroup\$ May 25, 2014 at 12:46
  • \$\begingroup\$ @AndonM.Coleman Thanks, I edited my question accordingly. \$\endgroup\$ May 25, 2014 at 14:56

1 Answer 1


About a decade ago, GL_TEXTURE_2D_ARRAY wasn't widely available, people could only get an array of 2D textures using texture atlases.

This means that people stored the data in a faily big 2D texture and when they wanted to fetch a texel, they offseted the texture coordinates with a function of the slice value (the "depth").

This worked well, since the 2D textures were required to support at least 8192*8192 texel resolution, and back then, people didn't really want to use textures bigger than 512*512 texels.

On the current hardwares you need to use this trick to extend GL_TEXTURE_3D to 4 dimension. There's a little bit of differance though, 3D textures are required to support at least 1024*1024*256 texels, which kinda limits the texture size you can use. As far as I know, you can use 16 textures in a shader program simultaneously, which lets you store up to 2^32 texels. With this, you can implement a 256*256*256*256 4D texture, and you get bilinear sampling in 3 coordinates, and you can do it manually for the forth coordinate.

  • 1
    \$\begingroup\$ I think nowadays you can use up to 32 textures in a shader. \$\endgroup\$ May 25, 2014 at 12:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .