how does texture mapping work?

Started by
1 comment, last by Theses 23 years, 9 months ago
ok so you got these triangles and you got this rectangular texture ok so the texture goes on the triangle the square texture goes on the triangle the square, the triangle
Advertisement
it''s easy (if you''re good at math anyway). think of each vertex as having texture coordinates U,V (which are just the x and y coords of texture).
now when you project the triangle (you can use any shape really but they are they easiest) you just interpolate the U,V coords between the verticies on the screen. make any sense?

think of it like this, i''ll show a line for easy understanding. say you have a texture that is 10 texels (texture pixels) wide and you have a line that is 20 pixels long on the screen.

the line on screen:
--------------------
and the texture:
-+-+-+-+-+

you wanna stretch the texels out to fit the line..
--------------------
--++--++--++--++--++

ok so far? so to do this you''d take the texture width (for now for easyness) and divide it by the run of the line which will give you 0.5 (10/20=0.5). now all that number is is the amount of texels you increment per screen pixel. kinda get it? so starting out with 0, then .5,1,1.5,...., and all the way till 10 as the last pixel. the middle of the line being the 5th texel.

that describes the theory behind affine texture mapping, not perspective correct where you take Z into account. hope this helps, it''s might not be enough to write your own texture mapper but it should make you understand the basics and help you on your way to understanding much easier.
er whoops, the pixel line length and texture size (the second "diagram") were supposed to be equal in length. otherwise it makes no sense

This topic is closed to new replies.

Advertisement