Jump to content
  • Advertisement
Sign in to follow this  
nbertoa

NDC to Pixel Space

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

Hi, community.

I searched in google about this but I am confused because there are a lot of different answers.

In DirectX, if I have a point in normalized device coordinates then (X, Y, Z) values will be ( [-1.0f, 1.0f], [-1.0f, 1.0f], [0.0f, 1.0f])

The orientation of X and Y coordinates are described in this MSDN link

How can I get pixel space coordinates from here?

I used mathematics and my conclusion was:

float pixelX = (NDCx + 1.0f) * 0.5 * screenWidth;
float pixelY = (1.0f - NDCy) * 0.5 * screenHeight;
because when NDCx is -1 then we get 0 and when NDCx is 1 we get screenWidth

and when NDXy is 1 then we get 0 and when NDCy is -1 we get screenHeight

But I decided to make some research.

I saw a stack overflow post about a Jim Blinn's Pixel Coordinates article, but unfortunately, I do not have that book. Apparently, Jim describes that this is not so simple to calculate because:

<p>A user/programmer does all screen design in NDC. There are three nasty realities of the hardware that NDC hides from us:

  • The actual number of pixels in x and y.
  • Non-uniform pixel spacing in x and y.
  • Up versus down for the Y coordinate. The NDC-to-pixel transformation will invert Y if necessary so that Y in NDC points up.

In another post, I found in stack overflow we have the following:

float screen_x = (vertex.x / vertex.w + 1) * 0.5 * screenwidth;float screen_y = (vertex.y / vertex.w + 1) * 0.5 * screenheight;
According to MSDN information, I think that maps correctly NDCx to PixelSpacex but not in the case of y.

Am I missing something?

Share this post


Link to post
Share on other sites
Advertisement

Thanks MJP. I was looking for that kind of reference

Edited by nicolas.bertoa

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!