PDA

View Full Version : 3D textures in WebGL



xrew
02-26-2011, 08:25 AM
Hi,
i would like to ask, if there is any experimental support for 3D textutres in WebGL. I am creating application for vizualization of medical data in WebGL as my Bachelor project and I really need 3D textures support. Is there any possibility, how can i resolve my problem? It's very important. I have created whole application - data are ready in memory, 3D object is ready too...but 3D texture is really missing me.

Thank you very much.

Sincerely,
Tomáš Sychra

SteveBaker
02-26-2011, 08:58 AM
The problem is that OpenGL-ES (upon which WebGL is based) doesn't support it. That means that cellphones can't do 3D texture - so that can't be added into the core spec.

Having said that, all desktop OpenGL systems support 3D texture and there is an extension mechanism in WebGL - and it might be possible to pursuade the Khronos group folks (our hosts here at this forum) to add 3D textures as an extension.

However, even if it were to be added as an extension, you'd have to realize that not all WebGL systems would be able to run your application - and you'd have to test for the existence of the extension and provide some kind of a fall-back (which, could, I suppose say "Sorry!" and exit!), but there is no way that you'll get 3D textures on all WebGL platforms...some simply don't have the hardware to support it.

The nearest thing you can to to replace 3D texture support is to pack slices of the 3D map into a gigantic 2D map (or possibly, several 2D maps) and use the pixel shader to calculate the x,y coordinate from the z coordinate of your map. If you wanted (for example) a 256x256x256 volume map, then you could pack it into a single 4096x4096 map as a 16 by 16 grid of 256x256 maps.

There are two gigantic caveats:

1) Not all WebGL-supported hardware can handle a 4096x4096 texture - that's pretty gigantic! So you might have to use (say) four 2048x2048 maps - which would be more of a pain to look up in your pixel shader...but not by enough to make it impossible. If you were hoping for more than 256x256x256, then you're screwed! If you can live with 128x128x128 then this is an easy problem!

2) When you use a real 3D map, you can have interpolation between your voxel data "for free"...so you don't get aliassing (well, not so much) between voxels. When you look up 3D data in a 2D map in the way I describe, you are jumping around, seemingly at random in the texture map and you have to use NEAREST sampling to avoid problems. So that means that you'll get aliassing. To get rid of the aliassing, you'd need to read the 8 voxels nearest to the point on the texture you're accessing and do the interpolation in shader software.

So with all of those caveats - you CAN do this without a 3D map. The results might be slower than a real 3D texture - since you're accessing all over the 2D texture, there is no chance of texture caching helping you - and if you read out 8 voxels and interpolate them - then things will be even slower. Sadly, that's really your only option.

Good luck!