Jump to content
  • Advertisement
Sign in to follow this  

linear texture mapping - perspective correct

This topic is 3627 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

I posted about a week ago asking about texture coordinates, and was told that before I try perspective correct, that I should be able to do linear mapping. I've finished making my program do linear mapping, but it looks really bad. Mapping onto a square made of two triangles makes straight lines look bent at certain angles. Anyways, what's the next step? I have done my texturing by assigning texture coords to each vertex that range from 0 to 1(the width/height of the texture), and linear interpolating the texture coords down the edges, and then between the edges. I've read in many places that a formula with 1/z u/z and v/z fit in here somewhere. Can someone explain? Thanks again =) edit: here is the relevant code from my project... //when edge is added: y_steps = int(GET

.edges[v].pt[1][1] - GET

.edges[v].pt[0][1]); GET

.edges[v].u_inc = (GET

.edges[v].p_texcoord[1][0] - GET

.edges[v].p_texcoord[0][0]) / (float)y_steps; GET

.edges[v].v_inc = (GET

.edges[v].p_texcoord[1][1] - GET

.edges[v].p_texcoord[0][1]) / (float)y_steps; GET

.edges[v].U = GET

.edges[v].p_texcoord[0][0]; GET

.edges[v].V = GET

.edges[v].p_texcoord[0][1]; //when edges are updated, per scanline: GET

.left_edge->V += GET

.left_edge->v_inc; GET

.left_edge->U += GET

.left_edge->u_inc; GET

.right_edge->V += GET

.right_edge->v_inc; GET

.right_edge->U += GET

.right_edge->u_inc; //when rendered: for(sx = (int)GET

.left_edge->x_int; sx <= (int)GET

.right_edge->x_int; sx++) { if(sx >= 0 && sx < SCREENWIDTH) { pixel_x = (((sx - GET

.left_edge->x_int) / (GET

.right_edge->x_int GET

.left_edge->x_int)) * (GET

.right_edge->U - GET

.left_edge->U) + GET

.left_edge->U) * bm_texture.bmWidth; pixel_y = (1-(((sx - GET

.left_edge->x_int) / (GET

.right_edge->x_int - GET

.left_edge->x_int)) * (GET

.right_edge->V - GET

.left_edge->V) + GET

.left_edge->V)) * bm_texture.bmHeight; if(pixel_y < 0) pixel_y = 0; if(pixel_x < 0) pixel_x = 0; p_bits[(SCREENWIDTH * sy) + sx] = t_bits[(bm_texture.bmWidth * pixel_y) + pixel_x]; } }

Share this post

Link to post
Share on other sites
I found this article on perspective correct interpolation, but right after Figure 2, (1), (2), ect, I am lost. I can't figure out what those fomulas mean, or how to apply them to what Im doing...Can anyone help?

the article:

Thanks, Nick

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!