# NDC to Pixel Space

This topic is 558 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, community.

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 on other sites

Thanks MJP. I was looking for that kind of reference

Edited by nicolas.bertoa

1. 1
Rutin
24
2. 2
3. 3
JoeJ
18
4. 4
5. 5

• 38
• 23
• 13
• 13
• 17
• ### Forum Statistics

• Total Topics
631712
• Total Posts
3001849
×