Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Trying to understand some basic 3D concepts, at the moment I'm trying to figure out how textures actually work. I know that UV and UVW mapping are techniques that map 2D Textures to 3D Objects - Wikipedia told me as much. I googled for explanations but only found tutorials that assumed that I already know what it is.

From my understanding, each 3D Model is made out of Points, and several points create a face? Does each point or face have a secondary coordinate that maps to a x/y position in the 2D Texture? Or how does unwrapping manipulate the model?

Also, what does the W in UVW really do, what does it offer over UV? As I understand it, W maps to the Z coordinate, but in what situation would I have different textures for the same X/Y and different Z, wouldn't the Z part be invisible? Or am I completely misunderstanding this?

share|improve this question
    
ask two questions separately –  Noob Game Developer Oct 26 '12 at 7:54

2 Answers 2

up vote 17 down vote accepted

Your understanding is close. Each 3D model is made out of vertexes. Each vertex usually defines the location of a point in space, a normal (used in lighting calculations) and 1 or more texture coordinates. These are generally designated as u for the horizontal part of the texture and v for the vertical.

When an object is textured, these coordinates are used to look up which texel or pixel to plot from the texture. I find it easiest to think of them as percentages or ratios between the left edge of texture (u = 0) and the right edge of the texture (u = 1.0) and from the top of the texture (v = 0) and the bottom of it (v = 1.0). They are interpolated between the vertexes and looked up for each on-screen pixel that is rendered. They can be larger or smaller than these ranges and the render state that is set when the object is rendered specifies what happens. The options for this are CLAMP and REPEAT. Clamping limits the coordinate to either 0 or 1, causing the texture to smear where it is outside of the range. Repeat causes the texture to repeat when it is outside the range; it is effectively the same as grabbing just the decimal portion of the coordinate and using that in its place.

Before the texture coordinates are applied onto an object, they are multiplied by a texture matrix to apply some transformation to them (such as scaling, translation or rotation). This effect is sometimes animated in games to make it appear as though something is moving across an object without having to move the object itself... the texture is simply scrolling across it. When the texture matrix is multiplied by the texture coordinates, it produces 2 values that are used to look up the texel to plot (lets call them s and t). These are generated automatically from u and v even when the texture matrix is not set; it is the equivalent of multiplying u and v by an identity matrix.

This is where the w coordinate comes in, though it isn't used that often. It is an extra parameter to multiply the texture matrix against and is usually used when you want to take perspective into account (such as in Shadow Mapping). It works the same as when you transform a location in object-space to screen-space via a world-view-projection matrix. By multiplying the UVW with a projection transform, you end up with 2 coordinates, the s and t which are then mapped onto a 2D texture.

share|improve this answer
    
Very informative and clear, thanks! –  Michael Stum Dec 29 '10 at 12:20

Consider a triangle.

Each corner has a UV coordinate. You interpolate between these to get a set of UV coordinates for each pixel. (There's also perspective in play here but let's ignore that for the moment).

Then, you fetch a texel from the texture from the coordinates U and V. Which is to say, a pixel from the texture coordinate x,y - same thing, slightly different terminology since we're talking about textures.

If your texture is a truly 3-dimensional one, you'll also need a third coordinate, W.

One way to visualize this is to think of a block of wood. If you chop it somehow, you'll see that each plane inside the block contains a 2d texture of sorts.

3d textures are so rare that you can forget about them for the time being.

share|improve this answer
    
Rare? What are they used for? Can you show some example in the context of AAA titles. –  iamcreasy Nov 29 '11 at 8:55
    
No, because they're generally speaking never used. There's always some cheaper way of doing the same thing. Think of the chopped items in wii sports plus; you can break the items in any way you wish, and see the "internals". They could have wasted huge amounts of memory by making them 3d textures (assuming the hardware even supports that), but it's much cheaper to simulate that with a couple of 2d textures instead. –  Jari Komppa Nov 29 '11 at 10:31
    
So, they are not exclusive? or this is no much needed feature for any well known things game engine do? –  iamcreasy Nov 29 '11 at 13:36
    
I don't understand what you mean. 3d textures may be useful in other uses than as simply textures, though; if some data a shader needs conveniently maps into a 3d array, that would be one use. But as a "normal" texture, they're generally just a waste of memory. –  Jari Komppa Nov 29 '11 at 17:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.