World space coords in a fragment program
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?
well, one simple way, that comes to mind, is to just pass world coordinates trough the vs.. that'll be very cheap :D
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).
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).
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
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement