I'm trying to understand the mathematical theory behind UVW mapping. Can anyone explain me how UVW mapping works? Or at least provide me a pointer?
This is the way I understand it. Could be totally wrong, but I'm sure someone will
flame correct me if I'm wrong.
The mathematical theory behind UVW texture mapping is similar to the theory behind UV texture mapping.
See Bummzack's link here: What exactly is UV and UVW Mapping? to get a better explanation of what UV mapping is. Basically, you're mapping an area of a texture to an area of a surface. Interpolating the values in-between based on those mappings.
Same thing with UVW. Except now you're mapping a volume of texture to a volume of surfaces. Interpolating the values in-between. Now with the 3rd dimension you can warp a 2d texture to better fit an object.
Lets look how this is used in 3D textures. 3D textures can be created by layers of 2D textures, and interpolating the texels in-between. Visually a 3D texture could look something like this:
Where the "planes" in the R axis are 2D textures. If we were to set each layer to a different solid color, and apply this to a 3D object, we'd get something like this:
You can see how the solid colors have been interpolated in-between the layers. Here's the same type of thing, but with a landscape. Where from top to bottom, the textures could be: snow, rock, grass, sand.
Now if we're only using one R "plane" (one 2D texture), but mapping to 3D object? Obviously this doesn't give as much flexibility as multiple layers of textures, but it sure is a lot less work. However, just projecting a 2D texture onto a 3D surface is going to cause some issues. Think of the situation where you're shining a laser on a wall. At a perpendicular angle the laser point is nice and round. At any other angle, the point starts to stretch and skew. Same thing will happen when projecting a 2D texture onto a 3D surface. Any face that isn't perpendicular to the projection will be distorted. How do we fix that? By distorting the projection. Take the laser example, if we had a laser that when shone on a perpendicular surface it was stretched and skewed. When we shone that laser onto a angled wall the angle could "cancel" the effects of the stretching. The 3rd dimension allows us to "shape" the projection so that it fits the surface we're aiming at. For example, some kind of wavy 3D surface might have a texture like this (but not so crummy):
Like I said, this is just my understanding of it. I agree, there isn't much good information out there on this subject. Hopefully this (likely wrong) answer will prompt someone with more knowledge of the subject to speak up.
The images for the 3D textures came from this page: http://www.gpwiki.org/index.php/OpenGL:Tutorials:3D_Textures