Jump to content
  • Advertisement
Sign in to follow this  
renderer

World space coords in a fragment program

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

Is there a quick and easy way to go from window coordinates (x E [0,width]; y E [0,height]; z E [0,1]) to world space coordinates in a fragment program? I'm currently passing in the inverse viewing transformation, doing a DP4 on each element (including w and doing the perspective divide). Is there an easier method? Also, in the fragment.position the last component (.w) is 1/w. What is this normally used for?

Share this post


Link to post
Share on other sites
Advertisement
well, one simple way, that comes to mind, is to just pass world coordinates trough the vs.. that'll be very cheap :D

Share this post


Link to post
Share on other sites
Maybe my question is a little vague...

I want to transform each pixel from its window coordinates back to world space coordinates, and then operate on the pixel in world space coordinates (a depth replacement algorithm).

Share this post


Link to post
Share on other sites
if this was GLSL then I'd say use the gl_ModelViewProjectionMatrixInverse uniform (unless I'm going crazy that should do what you want it to...).. however, as it appears you arent, unless the fragment program interface has a simular mapping you'll have to work it out yourself and pass it to the program as a parameter of some kind

Share this post


Link to post
Share on other sites
Thanks for the reply..


I'm currently doing that...I use glProgramLocalParameter4dARB() and pass in the 4 rows of the inverse matrix.

I then take the x and y coords and divide them by the window width and height, and then take those along with the depth and do a MAD to convert them from [0,1] to [-1,1].

Then I do DP4 on each row...divide by w, yadda yadda...but I'm still not getting the correct values. It seems so straight foward, I feel I'm missing something very simple.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!