From: Tony B. <ton...@kr...> - 2008-07-26 21:14:32
|
In other words, yes. > There's a number of issues involved in mapping a texture to a triangle, > and given the nature of your question, I have to assume you may not be > aware of some of them, so I'll try to explain the very fundamental > components. > > The UV coordinates of a vertex are just that... a location in a texture > mapped from 0..1 in each axis. Graphics hardware typically have > different settings to handle what happens when UV values are outside of > that range. The most basic are Clamp, Wrap, and Mirror. If you set it > to Clamp, any value outside 0..1 becomes either 0 or 1, so you can't > exceed the given map on a model. On a typical cube with default UV > mapping, that means you'll have one face with a texture on it and all > the other faces will have the perimeter color stretched through them. > If you set it to Mirror, every odd modulus is frac(U) and every even > modulus is 1-frac(U), so 1.1 is remapped to 0.9... thus you can > essentially tile a texture across a plane and have it unfold the texture > forward and backward forever. With Wrap set, you get the texture > repeating as frac(U), so 1.1 is the same as 0.1. Each axis is > configured separately. > > There's also a texture matrix that can be applied to the UVs, which I > believe (correct me if I'm wrong) is applied before the > wrap/clamp/mirror operation, so you can scale or rotate the UVs on a > model without actually modifying the input data. > > Now, what you were asking about is the direction of a mapping. A > geometric triangle has a face normal that can be computed by cross > product, or using the right-hand rule from edges 0-1 to 0-2. Let's > pretend the texture is in the same plane as the triangle. The three UVs > of the triangle vertices form a triangle in the texture plane. Since > it's a triangle, it has a facing as well. Computing the sign of the > cross product, if it's positive (the right hand rule of edge 0-1 to 0-2 > leaves you with your thumb pointing the same direction as the triangle's > face normal), the triangle's texture will be mapped as you see it in the > texture. However, if you have a negative sign, or your thumb points > opposite of the face normal, it will appear to be mirrored/backwards. > It's not wrong, just the way it works. > > One thing is certain, if you are just poking at UV values and trying to > figure it out, it will seem complicated. Here's a few things to think > about. If you map a triangle, translating the UVs will never cause the > direction of the mapping to flip (unless you set Mirror mode). But > simply negating them will, because that reverses the face normal. > Negating either the positions or UVs will make the texture appear > mirrored/backward. So, if you negate both the vertex positions and UVs, > you have flipped both triangle normals, and it will appear to be mapped > correctly, but facing the opposite direction. :-) > > I hope that helps. > > JH > > skunkwerk wrote: >> hi, >> i'm looking for an explanation of what negative UV coordinates do >> when using texture mapping. my initial thought was that negative >> coordinates are just a continuation in the same U-V plane of the tiled >> texture, so a value of -1.6 would be equivalent to a positive value of 1.4 >> >> however, based on tests i did opening a simple 3d model of a plane >> with positive, and then negative uv coordinates, it seems like the >> negative sign is actually flipping the texture around the u/v axis. >> is this correct? >> > > ------------------------------------------------------------------------- > This SF.Net email is sponsored by the Moblin Your Move Developer's challenge > Build the coolest Linux based applications with Moblin SDK & win great prizes > Grand prize is a trip for two to an Open Source event anywhere in the world > http://moblin-contest.org/redirect.php?banner_id=100&url=/ > _______________________________________________ > GDAlgorithms-list mailing list > GDA...@li... > https://lists.sourceforge.net/lists/listinfo/gdalgorithms-list > Archives: > http://sourceforge.net/mailarchive/forum.php?forum_name=gdalgorithms-list > > This message and its attachments may contain legally privileged or confidential information. This message is intended for the use of the individual or entity to which it is addressed. If you are not the addressee indicated in this message, or the employee or agent responsible for delivering the message to the intended recipient, you may not copy or deliver this message or its attachments to anyone. Rather, you should permanently delete this message and its attachments and kindly notify the sender by reply e-mail. Any content of this message and its attachments, which does not relate to the official business of the sending company must be taken not to have been sent or endorsed by the sending company or any of its related entities. No warranty is made that the e-mail or attachment(s) are free from computer virus or other defect. |