Sign in to follow this  
renderer

World space coords in a fragment program

Recommended Posts

renderer    202
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
renderer    202
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
_the_phantom_    11250
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
renderer    202
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this