Sign in to follow this  

NDC to Pixel Space

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

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