Jump to content
  • Advertisement
Sign in to follow this  
staticVoid2

Affine Texture Mapping

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi, I've just finished writing a function to texture a triangle using affine texture mapping but im not sure if there's somthing wrong with it or if it's just the way affine mapping works. here's a few screenshots of a sample image split into two triangles, it seems to curve at some points which i don't think is right: Free Image Hosting at www.ImageShack.us Free Image Hosting at www.ImageShack.us you can see the two triangles clearly in the first image and at the bottom left you can see the pixels sort of curving to the left. [Edited by - staticVoid2 on February 7, 2008 2:12:17 AM]

Share this post


Link to post
Share on other sites
Advertisement
i forgot to swap the gradients:



/* (determines which side is which)if the gradient of the left side is
greater than that of the right side then the points need to be swaped */

if(dxdyl > dxdyr) {
swap(x1, x2, temp); // swap the points
swap(y1, y2, temp);
swap(tu1, tu2, temp);
swap(tv1, tv2, temp);
<b>swap(dudyl, dudyr, temp);</b>
<b>swap(dvdyl, dvdyr, temp);</b>
swap(dxdyl, dxdyr, tempf); // swap the gradients instead of recalculating
}






i think that eliminated the curve effect but does this look more like affine mapping?:


Free Image Hosting at www.ImageShack.us




Share this post


Link to post
Share on other sites
Looks like you need perspective correction. You could try doing it every four pixels or so and interpolating inbetween (subdivided affine texturing). I'm assuming you're after speed here, otherwise just do it at each pixel.

This is done by computing U/Z and V/Z and 1/Z at the vertices and interploating them like normal, then at each point where you perspective correct you simply take the interlopated 1/Z, extract Z from it, multiply the U/Z and V/Z by Z to get the the perspective correct U and V coordinates.

Share this post


Link to post
Share on other sites
Only the second image in your first post looks correct. In the others, you have some kind of a bug in the way you interpolate the texture coordinates across the diagonal. It looks like only the triangle that makes up the bottom right half of the quad has a problem in your last image.

Affine texture mapping will produce the "kink" effect you see in the second image (as it's not perspective-correct) but shouldn't cause the kind of discontinuity evident in the other two. Both polygons should produce the same texture coordinates along that edge since it's just a linear interpolation.

[Edited by - Fingers_ on February 8, 2008 2:31:37 PM]

Share this post


Link to post
Share on other sites
yeh, there were a lot of bugs that i fixed, because I transferred the code to java to display the image and (for example) I used a swap macro which i thought would easily transfer into a java function but never because java does not support pointers to primitives so i had to inline 3 lines of code for evey swap function. there were a few other bugs aswell that i can't remember. I'm just implementing the clipping procedures in the function which is a nightmare but it seems to be working now.

Share this post


Link to post
Share on other sites
Why do you need the swap anyway? I can't think of any reason you would need them. In my software renderer I simply compute the gradients from the three vertices and thats it. They can be negative, but that is no problem at all.

Share this post


Link to post
Share on other sites
for perspective correct, when you are interpolating the reciprocal of z for each vertex, what should the interpolant be? i've tried (delta 1/z / delta y) for each line segment on the triangle but i don't think it's working. Is it that difficult to change a function for affine texture mapping to perspective correct?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!