0

A question sort of addressing the problem and another question asking a related question.

I have a 2D texture that has 12x12 slices of a volume layered in a grid like this: enter image description here

What I am doing now is to calculate the offset and sampling based of the 3D coordinate inside the volume using HLSL code myself. I have followed the descriptions found here and here, where the first link also talks about 3D sampling from a 2D sliced texture. I have also heard that modern hardware have the ability to sample 3D textures.

That being said, I have not found any description or example code that samples the 3D texture. What HLSL, or OpenGL, function can I use to sample this flipbook type of texture? If you can, please add a small example snippet with explanations. If you cant, pointing me to one or the documentation would be appreciated. I have found no sampler function where I can provide the number of layers in the U and V directions so I dont see how it can sample without knowing how many slices are per axis.

If I am misunderstanding this completely I would also appreciate being told so.

Thank you for your help.

Community
  • 1
  • 1
Noobs DeSroobs
  • 253
  • 1
  • 6
  • 24
  • So what are you actually using: DirectX or OpenGL? In case of OpenGL you will most likely write your shaders in GLSL, not HLSL. – BDL Sep 04 '16 at 22:27
  • I am using HLSL and DirextX right now, but I could much easier search for the HLSL equivalent is I knew the OpenGL function. Further, I might have to also implement this in OpenGL code at some point. – Noobs DeSroobs Sep 04 '16 at 22:29
  • 1
    "*I have also heard that modern hardware have the ability to sample 3D textures.*" If by "modern", you mean almost any (desktop) GPU made in the last 15 years or so, sure ;) – Nicol Bolas Sep 04 '16 at 23:38
  • @nicolbolas Might be. I am just parroting what I was told. – Noobs DeSroobs Sep 04 '16 at 23:40

1 Answers1

2

OpenGL has support for true 3D textures for ages (actually 3D texture support already appeared in OpenGL-1.2). With that you upload your 3D texture not as a "flipbook" but simply as a stack of 2D images, using the function glTexImage3D. In GLSL you then just use the regular texture access function, but with a sampler3D and a 3 component texture coordinate vector (except in older versions of GLSL, i.e. before GLSL-1.5/OpenGL-3 where you use texture3D).

datenwolf
  • 159,371
  • 13
  • 185
  • 298
  • Can you confirm then, that there are no flipbook type of 3D texture and as long as I get the data in the format I showed I will have to do it manually? I will see if I can request the data in seperate images instead if that is the case. – Noobs DeSroobs Sep 05 '16 at 12:20
  • @NoobsDeSroobs: There is indeed no support for a "flipbook format" 3D texture. Any why should there be something like that? That being said, it's pretty easy to set pixel store parameters, namely GL_UNPACK_SKIP_PIXELS and GL_UNPACK_ROW_LENGTH so that you can fetch the subimages directly from your flipbook without going through a conversion step first. – datenwolf Sep 05 '16 at 13:03