• Advertisement
Sign in to follow this  

Per-Pixel eye vectors for fullscreen quad

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

I am rendering a full-screen quad, and I want to get a vector per-pixel representing the ray from the camera through the pixel in view space.  It will also need to take the viewport field of view and aspect ratio into account.  Is there an optimal way of doing this?

 

I'm converting a skybox to a full-screen quad.  I tried using the texture coordinates to calculate x and y values (remapped to -0.5 to 0.5), normalizing it with a z value of -1, and multiplying it by the inverse of the view matrix, but that came out warped and incorrect.

Share this post


Link to post
Share on other sites
Advertisement

You need to undo your projection, not the view transform. To do that you can take your pixel position in normalized device coordinates (bottom left is (-1,-1), top right is (1,1), transform by the inverse of your projection matrix, and then divide by w. Just make sure you normalize the result, since it won't be a unit vector.


This is the best way to do it, and it works for essentially any type of projection.

My method is more straightforward and not the best approach. If you know your field of view (for instance 90 degrees), then you know that the end of your normalized device coordinates map to that FOV. So at at x =1, y=0, tan(90/2) = x/z, so your z coordinate for the FOV is z = 1/tan(45), or cot(45). Your view vector would then be v=normalized(x,y,cot(FOV/2)), where x and y map to {-1,+1}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement