Skip to main content
GameDev.net gamedev.net
🔒 Locked

Perspective Correct Barycentric Interpolation Texture Mapping [Solved]

Started by Jesse Farag May 10, 2015 at 5:41 AM 3 replies 5.3k views
Original Post
Jesse Farag
Jesse Farag

Hey, I know that you need to divide u,v,w,1 by w, but what is w? How is it calculated?

If w is 1 for vertices, 0 for vectors, then wouldn't dividing by w not make any sense?

I'm so confused, and google doesn't help.

I can't give you much as this is not a problem per-se that I'm having, rather I'm needing some sort of in depth explanation on this w component.

Thank you in advance.

[attachment=27227:affine.PNG]

L. Spiro
L. Spiro

If w is 1 for vertices, … then wouldn't dividing by w not make any sense?

It is 1 prior to being multiplied by the world-view-projection matrix. It certainly isn’t going to stay 1 after that.


L. Spiro
I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid
slicer4ever
slicer4ever

Hey, I know that you need to divide u,v,w,1 by w, but what is w? How is it calculated?

If w is 1 for vertices, 0 for vectors, then wouldn't dividing by w not make any sense?

I'm so confused, and google doesn't help.

I can't give you much as this is not a problem per-se that I'm having, rather I'm needing some sort of in depth explanation on this w component.

Thank you in advance.

attachicon.gifaffine.PNG


It's called the perspective divide, it fixes the distortion caused by your perspective viewpoint being mapped to a 2D screen.

when you do Vertex*ViewProjMatrix, you are modifing the w component of the Vertex. the x, y, and z component must be divided by the w component of the transformed vertex to fix their locations for screen space. the reason that we use 0 for vectors, is because vectors are directions, and transforming them in 3D space only causes a rotational change, and not a positional change(because the w component is set to 0). vertices are positional points, which need to be also translated with the matrix to end up at a point somewhere around the camera, however this space isn't in homogeneous coordinates(openGL and DX use this space to map to the physical window, this space is between -1->1 coordinates, with 0 being in the center), so to transform your vertices to this space, we must divide by the vertices w component.
Jesse Farag
Jesse Farag

Ohhh. Thank you for clearing this up, never knew w was actually ever changed. :I

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.