Jump to content
Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.
Posted 25 June 2012 - 07:03 AM
Posted 25 June 2012 - 07:16 AM
Edited by _Sauce_, 25 June 2012 - 07:18 AM.
Posted 25 June 2012 - 12:15 PM
X = (X + 1) * Viewport.Width * 0.5 + Viewport.TopLeftX Y = (1 - Y) * Viewport.Height * 0.5 + Viewport.TopLeftY Z = Viewport.MinDepth + Z * (Viewport.MaxDepth - Viewport.MinDepth)
Posted 26 June 2012 - 08:31 AM
Thanks MJP, that helps a lot.
Your vertex shader outputs homogeneous coordinates in clip space. When you divide XYZ by W, you get "normalized device coordinates" where X = -1 is the left side of the viewport, x = 1 is the right side, Y = -1 is the bottom, Y = 1 is the top, Z = 0 is the near clip plane, and z = 1 is the far clip plane. Any coordinates outside of these bounds will be clipped.
After that comes the viewport transform, which looks like this:X = (X + 1) * Viewport.Width * 0.5 + Viewport.TopLeftX Y = (1 - Y) * Viewport.Height * 0.5 + Viewport.TopLeftY Z = Viewport.MinDepth + Z * (Viewport.MaxDepth - Viewport.MinDepth)
At this point the Y-axis is flipped such that (0, 0) is the top left, and (Viewport.Width, Viewport.Height) is the bottom right.
GameDev.net™, the GameDev.net logo, and GDNet™ are trademarks of GameDev.net, LLC.