Sign in to follow this  

What exactly are 3d textures

This topic is 4088 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

Hi everyone, I'm just tryign to figure out what exactly is a 3d texture? I understand 2D and 1D, but how does a 3d texture look different from a 2D texture when mapped to an object, and when are 3d textures used? Thanks. Gavin

Share this post


Link to post
Share on other sites
3D textures aren't particularly useful for texturing objects.. As you point out you'd only see a 2D slice of it so you may as well use a 2D texture. One game-related use of 3D textures is you can store things like spherical light attenuation in one...

Share this post


Link to post
Share on other sites
A 2D texture is a function of two variables, implemented as a two-dimensional look-up table with filtering: color = f(u, v).

A 3D texture is a function of three variables: color = f(u, v, w), implemented as a three-dimensional look-up table with filtering.

Typically, you use 3D textures as function look-ups; for example, noise functions for using in procedural shaders.

When trying to use 3D textures to blend between material layers, you have to be careful about MIP mapping, because the very first MIP map layer will blend two terrain types into one, and you won't get any cross-blending. I can't really recommend the method Boder suggests, because of this.

Share this post


Link to post
Share on other sites
Quote:
Original post by Boder
You can use it to smoothly blend between two 2D textures, like a terrain with low sandy pits and grassy knolls.


ooooo...Do you konw of any tutorials on this? I've been trying to figure out how to do this for my terrain.

Share this post


Link to post
Share on other sites
Quote:
Original post by Gavinl
Quote:
Original post by Boder
You can use it to smoothly blend between two 2D textures, like a terrain with low sandy pits and grassy knolls.

ooooo...Do you konw of any tutorials on this? I've been trying to figure out how to do this for my terrain.

It's very rare to see 3D textures used for this. Most of the time, you'll use multitexturing to accomplish the same thing; a vertex parameter will be used in the pixel shader to blend between different bound textures. Googling for "terrain" and "multitexturing" will give you the details.

Share this post


Link to post
Share on other sites
Ken Perlin has done some interesting things with 3D textures. Flip through the slideshow here to see some examples of potential real world applications for 3D textures.

EDIT: changed the link to start at the 3D textures portion of the talk.

Share this post


Link to post
Share on other sites
the main advantage of 3d textures is more room for textures. e.g I use lightmaps, which means generating a texture for every polygon. This shouldn't be bounded again and again for drawing every polygon. therefore it is usefull to store mulitple textures in one. a 2 one can be used, but if this get to small, emply 3d to get more space

Share this post


Link to post
Share on other sites
Quote:
Original post by Sneftel
Quote:
Original post by Gavinl
Quote:
Original post by Boder
You can use it to smoothly blend between two 2D textures, like a terrain with low sandy pits and grassy knolls.

ooooo...Do you konw of any tutorials on this? I've been trying to figure out how to do this for my terrain.

It's very rare to see 3D textures used for this. Most of the time, you'll use multitexturing to accomplish the same thing; a vertex parameter will be used in the pixel shader to blend between different bound textures. Googling for "terrain" and "multitexturing" will give you the details.

The (potential) advantage of a 3d texture over two overlaid textures is the liberty to use a transition other than simple crossfading, for example nonlinear morphing, special intermediate steps, and anything else that can be precomputed or hand edited.


Share this post


Link to post
Share on other sites
Besides the obvious use as volumetric data sets (eg. in medical imaging), 3D textures are a great tool as per-pixel lookup tables. They can be used anywhere a complex function depended on three variables must be evaluated per pixel. They can be used as spatial storage containers, eg. for dynamic lighting (light fields).

Also keep in mind, that you can bind slices of them to an FBO, which opens a whole new world of possibilities.

I have successfully used them for:

* PRT light fields, storing spherical harmonic coefficients over a 3D space
* Shadow functions and light shaft calculations in participating media
* BRDF
* Various noise and other procedural functions
* Multi layer shadow maps (ie. deep shadow maps, for hair and fur rendering)
* GPU based fluid dynamics

And recently, I did some experimentation with GPU based collision detection using 3D textures, which seems to work pretty well.

In conclusion, 3D texture are an invaluable tool in modern 3D graphics programming. I often wish we also had hardware support for 4D textures (older SGI hardware used to have it).

Quote:

the main advantage of 3d textures is more room for textures. e.g I use lightmaps, which means generating a texture for every polygon. This shouldn't be bounded again and again for drawing every polygon. therefore it is usefull to store mulitple textures in one. a 2 one can be used, but if this get to small, emply 3d to get more space

That's a good example of how 3D texture should not be used ;) You'll sooner or later run into problems with filtering and performance. You should pack your small lightmaps into larger 2D textures instead.

Share this post


Link to post
Share on other sites
the point was made in the case very large 2D wasn't enough. size runs out you know. Indeed, i agree, use 2d when possible, but when size get is the way....
and as to dynamic lighting, 3d texcoords suffice for interpolations purposes, so with a little fantasy, in most cases you wont need the actual 3d texture, but can pack it drectly into the coordinates.... if you catch the drift

[Edited by - Kincaid on October 4, 2006 11:22:24 AM]

Share this post


Link to post
Share on other sites
Quote:
Original post by Kincaid
the point was made in the case very large 2D wasn't enough. size runs out you know. Indeed, i agree, use 2d when possible, but when size get is the way....

Then use more than one 2D map, and sort by state. 3D textures are really not meant to be 2D texture packing structures at all. While it may seem easier to implement a lightmap packing system into a 3D texture, it has a lot of drawbacks, especially with regards to performance and texture cache coherency. Memory management is another important issue. A 3D texture always has to be loaded into VRAM as a whole, the GPU cannot process partially uploaded 3D textures. If you didvide your lightmaps into a set of medium sized 2D textures (1024² is typically a good size), then the driver can selectively upload only the textures you will actually need in a particular frame. It then uses time coherency (possibly LRU based) to gradually swap in new maps, and swap out old ones as you move through your level or scene.

Oh, and mipmapping or anisotropically filtering a packed 2D texture (or texture atlas) is much more efficient than a 3D texture.

Not even talking about wasted memory areas when you don't tightly pack irregular shaped lightmaps (waste can very easily go into the 30 to 40% range without packing !)

Quote:
Original post by Kincaid
and as to dynamic lighting, 3d texcoords suffice for interpolations purposes, so with a little fantasy, in most cases you wont need the actual 3d texture, but can pack it drectly into the coordinates.... if you catch the drift

Only for very basic lighting. Not for the kind of lighting I was talking about above, it's not as easy for that ;) In many scenarios involving non-linear or highly complex lighting functions (for example BRDF - bidirectional reflectance distribution functions), a 3D lookup texture (and in some case a 4D or 5D one) is the only way to get interactive framerates.

Share this post


Link to post
Share on other sites
I guess that would be a mathematical discussion rather than a programming one. any 'highly' complex function (and light isn't that complex of a function in 99% of the (programming) cases when looking at it from a mathematical point of view) can be approximated at any precision with polynomeals to name just one option. there is an overabbundance of representational tranformation possibilities and the trick is to hunt down the perfect one. Also, abstracting correctly from concept to concept functions will reduce complexity. a good modeling priciple, reduce complexity.
No, my points were simple. you'd like to keep rendering without interuptions like binding. multiple textures in one does the trick. 2d size runs out. 3d size has more. if you do like to rebind, then fine go ahead and make more 2d's.
any performance problem will be also the case in your highly complex lighting. its a choice...a tradeoff..however, i notice very little preformance loss, but my size is bigger (exponetially) (this offcourse slows a bit down, but in reasonable ratio to 2D)
and besides that im just saying, there's a philosofy behind representation, and with an creative mind and math tricks there's a lot to be simplified. That's what i call elegance in a program, doing as much as possible with as little knowlegde as possible. Now, I know 3d textures aren't meant as stacks, but they can be used like that.....

and for complex functions, make them less complex if they're costing to much...

Share this post


Link to post
Share on other sites
Look Kincaid, please don't take this is an offense, but from your posting profile it looks like you don't have a lot of experience with modern shader and physically based rendering yet. I can assure you, representing light and its interactions is the hardest and most complex part of 3D rendering there is. Especially when talking about physically based global illumination. Even the most complex equations used in 3D rendering (those with page long fragment shaders, tnos of lookup tables, etc) are just rough approximations of reality. If you want realistic rendered images, then you won't go very far with vertex based approximations as you suggested.

About using 3D textures as lightmaps - well, yes, it's possible. No, it's ususally not a good idea for performance reasons, because 3D textures were not meant for this. GPU manufacturers make certain assumptions about how certain features will be used in practice, so to optimize for these cases. This might change in the future, but right now 2D packed maps are a much more reasonable choice.

Anyway, this is going offtopic. You're free to PM me, if you want to discuss this further.

Share this post


Link to post
Share on other sites

This topic is 4088 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this