Jump to content
  • Advertisement
Sign in to follow this  
dark216

why do we need to divide w in texture projection

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

oh my poor English. Please, bear with me.

 

I'm trying to figure out the math in texture projection. and such shader code comes to me:

half4 col = tex2Dproj( _GrabTexture, i.uvgrab);

//half4 col = tex2D( _GrabTexture, i.uvgrab);
 
I found  the difference between tex2Dproj and tex2D is 
 
half4 col = tex2Dproj( _GrabTexture, i.uvgrab);

equals to

half4 col = tex2D( _GrabTexture, i.uvgrab / i.uvgrab.w);

what I don't get is the reason for this.

 

the concept of texture projection is finding the texcoord of each vertex in projector's draw call, and convert screen coords([-1,1],  [-1, 1], [ -1,1]) to clamped texture coords ([0,1],  [0, 1], [ -1,1]) . and then the modified screen coords can be used to sample frame buffer(rt) and draw those vertices again. But it seems to me at this point it's sufficed. I don't see the reason to divide the depth field. 

 

can anyone give me a clue.

 

 

Share this post


Link to post
Share on other sites
Advertisement

guys, frankly, I thank you all for reply, but I still don't get it.

 

Why is this divide called perspective divide? and it's a  (x or y / depth) => tan( fov / 2) right? 

 

I'm gonna go through some basic knowledge again, I must be missing sth, seriously!

Share this post


Link to post
Share on other sites

It's called perspective correct texture mapping because dividing the u and v coordinates by the depth (z) coordinate causes the texture look up to be compressed by distance.

 

In the early days of graphics programming, you divided by the depth (z) component. Today, with the use of matrices, the z component somehow (I'm a little unclear on this) gets merged into the 'w' component during projection. When you divide by 'w', you are dividing by depth. Either way, you are forcing the texture to be mapped to the polygon in a way that shows perspective foreshortening.

Share this post


Link to post
Share on other sites

guys, frankly, I thank you all for reply, but I still don't get it.
 
Why is this divide called perspective divide? and it's a  (x or y / depth) => tan( fov / 2) right? 
 
I'm gonna go through some basic knowledge again, I must be missing sth, seriously!


The "perspective divide" comes from the use of homogeneous coordinates. If you're not familiar with that term, I would suggest reading some background material. This link that I found explains some of the basics, and how it applies to graphics. Edited by MJP

Share this post


Link to post
Share on other sites

thanks to you all.

 

"Don't build your house on the quicksand!" that means me, I'm gonna get this clear!

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!