Now, what happens with 3D textures?



As explained, 3D textures are like 2D textures but with an added dimension. So instead of just (S,T) coordinates we have (S,T,R) coordinates. You can imagine such a 3D texture as several 2D textures behind each other. The picture below illustrates this:




Now, instead of looking up texels in a flat image we need to look up a texel in a volume so we need those 3 coordinates S and T (similar to X and Y) and R (which is similar to a depth value, Z). So, do we wrap a 3D object in a 3D texture just like we did with a 2D texture? No, we don’t. We act as if we build our 3D object from a material. Imagine this: a solid block of marble is cut and worked in such a way that we end up with a model of our 3D object. The link between this and 3D volumetric solid textures is easy, the 3 coordinates give an indication of how the 3D object is modeled from the material described in the 3D texture. The 3D texture is a volume and each point inside this volume has a color. By selecting the right points inside this volume you can find the color of the surfaces of the 3D model.

Actually, the link between the 3D model and the 3D texture is quite easy. All you need to do is place the 3D model inside the block of material. A trivial sample is building a block using a 3D texture as material. Actually, the 3D model and the 3D material (the 3D texture map) are identically. So to texture map the block you just select the border pixels from the material. So, the front face just looks identically to the front texture “slice” of the 3D texture. Its quite easy to see the 3D texture as a collection of slices. So a 256x256x256 3D texture can be seen as a group of 256 slices, and each slice can be seen as a simple 2D texture. As I said, a cube would just take as front face the first slice. Now imagine making our block smaller. By doing this we select slices deeper into the material. Of course you don’t need to stay parallel, the lookup system (it’s just math) can link any object position to a position inside the material cube, the 3D texture. Below you can see an example of how a triangle can be linked to a triangle (with (S,T,R) positions) inside the volume:



Now, the next topic is filtering. You have probably all heard about things like bilinear, trilinear, and even anisotropic filtering. The issue, very briefly, is this: When you have (S,T) coordinates in a 2D texture, then these coordinates will probably not fall onto one exact pixel. For example, say a 2D texture has a resolution of 256x256. Now if the (S,T) coordinates point (assuming 0 on the left and 255 on the right for a moment, normally this is 0 and 1 but then its not so obvious to see what I mean) to a point with coordinates (12.3 , 11.98) then its obvious that you can not link these coordinates with one pixel inside this map. I mean the pixels are located at the whole numbers, so (12,11) would be a pixel and (12,12) would also also be one. So, which one do we take? When doing point-sampling (a.k.a. no filtering) you just take the closest pixel which would be (12,12) in our sample. The disadvantage of this is that everything looks very ugly when doing this. When using filtering you take more than one texel from the texture map and you do a weighted blending (read you mix the colors together using the true coordinate in a clever way). So essentially in our sample you would take all the pixels that surround the (12.3,11.98) coordinate and you blend (mix them together using a weighted average based on the exact coordinate position) them. This principle is known as bilinear filtering.