Jump to content
  • Advertisement
Sign in to follow this  
Such1

Texture3D Sampling

This topic is 2000 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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. Edited by Such1

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!