Texture3D Sampling

Started by
1 comment, last by Such1 11 years, 4 months ago
Hey guys, I'm using 3D textures on my engine, but one thing I need to do is to get the exact texture coordinate of a pixel.
Like this, my 3D texture is actually several 2D textures. But I am using them like that because they are also used as render target.
But when I use them as resource I need to separate them again. How is the texture coordinates system work? I tried a few times and sometimes I get blended between 2 2D Textures.

EDITED:
Actually, I just changed my code to use Texture2DArray instead. I realized that they don't have a render target limit that could affect me.
Advertisement
You fixed your problem and used a 2D array, which is more logical, but I think your blending problem is because, well, in a 3D texture, you also get bilinear (trilinear, actually) filtering, which means if you were just stacking textures one on top of the other, you might end up interpolating two different textures.

I think the problem is you tried to sample the 3D texture "between" two adjacent textures instead of on exactly one, probably by using the z-coordinate = (texture I want) / (number of textures total) trick. This will work, but only if you add a 0.5 offset to your texture number, because of the way sampling works, so you need to use (texture I want + 0.5) / (number of textures total) to sample right on a given texture in your 3D texture (a "slice" of your 3D texture).

The 3D texture coordinates work exactly the same as the 2D and 1D coordinates - a floating-point range from 0 inclusive to 1 exclusive, in each dimension. That said, if you have D3D10, you can use the Load() method to bypass sampling and directly access each texel through integer coordinates (but you also lose sampling, which is not what you want anyway).

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

I tried all your suggestions before I posted here, none of them worked. Maybe I got something wrong. But I fixed it by using Texture2DArray anyway so...
But thank you for your suggestions.

This topic is closed to new replies.

Advertisement