PDA

View Full Version : Texture Mapping theory needed



Nil_z
03-23-2001, 11:42 PM
I am writing a software rendering engine just for studying, and I have problem with texture mapping, especially texture mapping with perspective correction. I have studied some document from gamedev and PCGPE, but I do not know how to use it with my project. What they refered is mapping rectangle texture to quad and the texture is exactly mapped to the polygon(with (s,t) as 0,0 0,1 1,0 1,1) since I am using triangles and not mapping exactly, I do not know how to use those magic numbers(P, M, N). Can anyone give me some hints?

davepermen
03-24-2001, 02:58 AM
ok, simple try to help you..

you have your 3 vertices with the 4 spacecoordinates ( homogenous, yet projected ) and for example 2 texturecoordinates

now in your scanline you interpolate your vectors linearly in the "onplain" variant, so to get just one vec per position.. and if you interpolate the texturecoordinates in the same line, too, you will get automatically the correct texture coordinates

means:

( in one scanline )

vec p0 = ( x', y', 1', w', u, v ) //the ones with the ' where shortened by z-division

vec p1 = ( x', y', 1', w', u, v ) //same here

now you do it like this:

distance = p0.x - p1.x


from p0.x to p1.x step 1 with variable i

vec p_current = ( 1 - i/distance )*p0 + ( i/distance )*p1;

and you have at every p_current your perspective correct texture coordinates automatically interpolated

hope this helps giving some idea

Nil_z
03-25-2001, 03:11 PM
If I have not made a mistake, that is the affine mapping(without perspective correction). I have writen an algorithm of that, the texture looks distorted at some angle. I need some help on the algorithm of "perfect mapping".

[This message has been edited by Nil_z (edited 03-25-2001).]

Nicolas Lelong
03-26-2001, 05:12 AM
Hi,

you can find some good tutorials at Chris Hecker's page (http://www.d6.com/users/checker/index.htm) who wrote texture mapping articles some time ago (think it was for Game Dev Mag).

You can also have a look at Paul Heckbert's page, he has good articles about Texture Mapping (http://www.cs.cmu.edu/afs/cs.cmu.edu/user/ph/www/heckbert.html)

Hope that helps

davepermen
03-26-2001, 06:37 AM
hm, possible, but i think you just have to give a 3th tex coordinate ( and a texwcoordinate, and after getting the interpolated one, you do your tex_z_coordinate_division.. and you get the pos on texture.. just a thought... )