#### Archived

This topic is now archived and is closed to further replies.

# perspective and texture mapping..ack!

This topic is 6031 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I''m having major problems with my texture mapping function. I''m not sure whats going on. It seems to work fine when it''s just a flat triangle, the texture maps just fine, but as soon I start changing the Zs it really starts to act goofy. And I''m not quite sure where my problem is. I am seriously going insane over this, it seems so simple, but I can''t figure it out for the life of me. Heck I''m not even sure if the problem lies in my texture mapping function. So I have a couple of questions. 1. What the heck do I multiple my x,y values by to get it to look correct when I add the Z value. In otherwords how I get perspective when I''m just drawing a simple triangle? 2. Does how you figure out the perspectice above affect how your texture mapping triangle will look? I don''t know, I''m really at my ends here. I have no idea whats going wrong. It just seems like I can''t do anything correct lately..

##### Share on other sites
Ok.. well I solved my first question. Thanks to reading this board a bit more. But now my texture mapping is more messed up then before. It''s very frustrating. It sort of looks like there are lots of little square of my texture inside the main triangle, if that makes sense :D

##### Share on other sites
Ok I'm just working this out in my head.
First we need to interpolate
u/z v/z and 1/z over the whole triangle to get
the starting u,v,z at each hor. scan line.

Then at each scan line we interpolate
z=1/(1/z) u=(u/z)*z v=(v/z)*z
to get the u,v.

We also need to interpolate x,y to get their
correct starting values at each scan line.

Am I missing anything?

So if the basic outline of the triangle is being drawn, then I am interpolating X and Y correctly, getting their correct values. But since the texture isn't being drawn correctly, I am not interpolating U and V correctly.

[edited by - kc_agogo on April 18, 2002 2:07:33 AM]

##### Share on other sites
You are talking about starting values only. How are you determining your ''ending''-values? If you treat them in the same way, your approach seems correct to me. Oh, and within the scanline, you should still interpolate 1/z=z'' and u''=(u/z) in a linear way . ua=u''*(1/(1/z)) (respectivly va) is only performed to get the actual u and v-coords for rendering. Be sure to interpolate u/z, not (u/z)*(1/z''), because that will result in an elimination of your perspective correction and you would just do affine mapping. I''m not sure, if you meant it that way.

##### Share on other sites
OK well I thought I had it working.
I took a look at making sure the starting and ending points were figured out, but it's still not working correctly.
I have no idea whats going with it any more. urgh.

I can't believe I'm having such problems with this! It is so fustrating!!!!!!!!!

[edited by - kc_agogo on April 18, 2002 3:12:24 AM]

##### Share on other sites
Ok well now I'm sorta back where I started. It looks good when viewed at a good Z, but when you change that Z it starts to messed big time. I don't know where the problem is.

Ok to calc the values across the scan line it's just
dx = xb - xa;

then
diz = (izb - iza)/dx;
duiz = (uizb - uiza)/dx;
dviz = (vizb - viza)/dx

where
iz = 1/z
uiz = u/z;
viz = v/z;

So then when you're going across from xa to xb.
you have
z = 1/iz;
ui = uiz * z;
vi = viz * z;

then
iz+=diz;
ui+=dui;
vi+=dvi;

then once the X loop is done, step up all the beginning and ending values, by their change in y.

[edited by - kc_agogo on April 18, 2002 3:59:53 AM]

[edited by - kc_agogo on April 18, 2002 4:02:48 AM]

##### Share on other sites
OK, here''s what i''m thinking about it:

dx = xb - xa; --> correct

then
diz = (izb - iza)/dx; --> correct
duiz = (uizb - uiza)/dx; --> correct
dviz = (vizb - viza)/dx --> correct

where
iz = 1/z --> correct
uiz = u/z; --> correct
viz = v/z; --> correct

So then when you''re going across from xa to xb.
you have
z = 1/iz; --> correct
ui = uiz * z; --> correct, but only used for rendering...NOT for interpolation
vi = viz * z; --> correct, but only used for rendering...NOT for interpolation

then
iz+=diz; --> correct
ui+=dui; --> NOT correct, should be uiz+=duiz;
vi+=dvi; --> NOT correct, should be viz+=dviz;

##### Share on other sites
Sorry, that was my mistake. I have it written correctly in my code, but not here for some reason. Anyway, it''s still not working correctly.

Could it be some place else, not involved with the interpolation, for example how I have my texture mapped to my triangle?

I did notice that my iza and izb were the same. But I think I have them interpolating correctly.

I don''t know :-(

##### Share on other sites
Could you post (or mail...have a look at my webpage in the profile for the address) a piece of the incorrect code or at least a screenshot where one can see how it looks now?

##### Share on other sites
i sent email to address on web page. Let me know if its helpful or not.

1. 1
Rutin
33
2. 2
3. 3
4. 4
5. 5

• 11
• 10
• 13
• 96
• 11
• ### Forum Statistics

• Total Topics
632974
• Total Posts
3009647
• ### Who's Online (See full list)

There are no registered users currently online

×