Texture Mapping and Texture Coordinates

Published October 03, 2007
Advertisement
Work is pretty slow so far, but that's to be expected. I'm mostly tasked on patching up internal tools right now. Not exactly glamorous, but as critical as anything else and I have no objections to doing it. In the meantime, you guys should check out our kick ass Yahoo Games webisode and trailer. And although I haven't gotten to spend much time with it or go into multiplayer at all, I can confirm that Fracture is, in fact, totally awesome.

Texture Mapping and Texture Coordinates

Texture mapping isn't exactly an obscure technique. So why, exactly, are the explanations of it so bad? I was googling last night in anticipation of writing this, and I have to say I'm absolutely shocked at how bad things are. It's a miracle anyone learns to use textures at all. The explanations I found ranged from poor to nonexistent, and they were universally hand waving and vague about exactly how it all works. The only exceptions were the ones that explained texturing from a rasterization point of view, which is completely useless to a beginner working with a 3D API.

The typical explanation goes something like this. Textures are 2D images that are placed on top of the triangle. The texture coordinates control where the texture is laid down. (0,0) means the lower/upper left of the texture, and (1,1) means the upper/lower right. {Insert vaguely descriptive image here.} You can get the correct texture coordinates on a model by having a modeling package export them for you.

The details vary, and some explanations are more long winded than others, but that's the gist of it. This is a completely useless way of presenting it. First of all, it's vague and conveys little or no mathematical basis to the whole thing. Second, 1D and 3D textures make absolutely no sense on this explanation -- how can you lay a volume down on the surface of a triangle? That is totally meaningless. Same goes for a line. Anybody who is going by this explanation does not understand how texture mapping works, at all. Of course, it's obvious that plenty of people understand texture mapping just fine. Truth is, most people subconsciously manage to extrapolate to the real explanation after messing around with it for a while, even if they don't quite realize it and even continue using this crappy explanation.

So what is the real explanation? The one I gave earlier is basically right. There's just one problem -- it's backwards. The texture coordinates don't describe how the texture is laid onto the surface of the triangle. The texture coordinates describe how the triangle is laid down onto the texture. Texture coordinates, then, are exactly what they sound like. They're a second set of coordinates for each vertex, that describe the vertex position in texture space. That texture space can really have any number of dimensions. Figuring out what texel to sample when rendering is just a matter of determining what texel occupies the same object-space location as the current pixel. This is also a way more useful way of looking at the construction of a TBN matrix (which IME is glossed over completely by most people), since the alignment of the tu and tv axes becomes much more obvious.

Today's subject was texture mapping because somebody last night came in, confused to all hell about what a 3D texture was and how it worked. The basic theme here, though, is that people don't always understand how to explain graphics concepts. This stuff isn't complicated, but to convey it properly requires precision and clarity. That is very often lacking, and on the internet tutorials can make it much worse. (This tutorial is the bottom of the barrel.) I really wish I had the time to do my own book on this sort of thing. Richard Thomson (legalize) is working on a book which is by far the best I've seen to date. Unfortunately, he also uses the same backwards explanation to describe texture mapping, although he is very precise about it and comes so close to getting it right. I have been suitably impressed by his work despite that.

It's amazing how many times I've found someone totally and hopelessly confused over something (graphics or not), and had them completely sorted out within a couple minutes. Explaining things in a way that makes sense isn't an ability everybody has, and unfortunately that doesn't stop many of them from writing anyway. It becomes much more difficult to find real writing by competent people like Richard as a result. On the bright side, the backlash against that sort of thing has been growing lately, at least here on GameDev. I don't like discouraging people from writing, but it's critical to make sure you don't have newbies learning from people who barely understand something themselves, or are extremely bad at explaining it. Just because you write something doesn't mean it's worth reading, and nobody's exempt from that. I have at least a half dozen entries to this journal that I finally rejected, basically because they sucked. Sometimes my standards are too stringent even for me.
Previous Entry Day 1 at Day 1
Next Entry Gaming Roundup I
0 likes 2 comments

Comments

mittens
The reason that the explanations for texture mapping are so horrendous, though, I think is for a good reason (at least in beginner texts; it's inexcusable in other arenas): newbies are ignorant.

If someone who's trying to get started with graphics programming (and is new to programming and computer architecture on the whole) or some non-programmer trying to understand more about 3D graphics in their favorite games, I think the incorrect explanation is a nice way for the people ignorant with the basic structure of the graphics pipeline to understand what the term "texture mapping" applies to in the most basic sense. That said; if an explanation of "texture mapping" as an image being plopped onto a triangle is found in an actual 3D graphics text, then I would have some serious issues with the author.
October 03, 2007 02:09 PM
jollyjeffers
The concepts of texture mapping and texture coordinates can be explained relatively easily, but the implementation and mathematical theory details are bloody complex at times.

The 'Advanced Graphics' module I did at university caused several people's brains to spontaneously combust when perspective correction, mip-mapping and texture filtering were explained in full.
October 04, 2007 04:14 AM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement