# Why potatoeses

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

## Recommended Posts




##### Share on other sites

I don't understand how ints could be used instead of floats in DirectX. floats have a huge range and similar relative errors across the range. If you were to use ints, how would you encode the normalized vector (0.707107f, 0.707107f, 0)?

##### Share on other sites

Edited by RoundPotato

##### Share on other sites

About the "why" part, it's because it makes a lot of things substantially easier, not only conceptually but also the involved math. Plus, it is something that you kind of have to do anyway in order to bring everything on screen, but by normalizing (instead of projecting into, say, a 1024x768x1 coordinate system) you do not have to bother about the actual resolution any more.

As an example where it makes your life easier, take clipping. Finding out whether something is inside your viewing frustum is quite non-trivial work. Not like this can't be done, but it's 6 plane tests, which is considerable work compared to...

... having transformed everything to NDC, anything in [-1, +1] is inside, the rest is not.

Edited by samoth

##### Share on other sites
You can convert coordinate by coordinate. If you want something that maps [-1,1] to [0,Width] linearly,

pixel_x = (ndc_x + 1) * Width / 2

Similarly,

pixel_y = (ndc_y + 1) * Height / 2

[EDIT: You may have to put a -' in front of ndc_y', depending on the conventions you are using.]

If you don't know how to deduce the inverse formulas, you should probably stop what you are doing and learn some basic algebra. Edited by Álvaro

##### Share on other sites
It's how the pipeline works. You transform vertices into NDC with some simple matrices that work independently of resolution. Screen space transformation has to happen after transformation to NDC. If you want to work in screen space, nothing stops you from doing so.

You can also render independently of resolution. For most of the rendering needs, the final resolution is irrelevant. You might render smaller or bigger than the real resolution for a variety of reasons. You can also render at different aspect ratios. You can render to viewports smaller than the actual screen. etc.

There's also supersampling and so on which cause rendering to happen at a different "resolution" than screen resolution.

I'd suggest picking up a copy of Frank Luna's D3D11 book. It explains the math, API, and basic techniques you need to get started as a graphics programmer.

##### Share on other sites

Edited by RoundPotato

##### Share on other sites
I chose [-1,1] instead of [0,1] because that's the typical range of NDC. If I remember correctly, OpenGL uses [-1,1] for all three axes, and DirectX uses [-1,1] for x and y and [0,1] for z.

##### Share on other sites

As an example where it makes your life easier, take clipping. Finding out whether something is inside your viewing frustum is quite non-trivial work. Not like this can't be done, but it's 6 plane tests, which is considerable work compared to...
... having transformed everything to NDC, anything in [-1, +1] is inside, the rest is not.

Minor nitpick, but: you don't have to be in NDC to do simple clipping. After the projection transformation but before the perspective divide you can simply clip everything to [-w, w] (which, after the perspective divide, would be [-1, 1]). And doing clipping before going to NDC makes it so you can still linearly interpolate attributes to create the new verts.

Also, I feel a kinship with you because our (case insensitive) handles are only different by one character

##### Share on other sites

Edited by RoundPotato

##### Share on other sites

I chose [-1,1] instead of [0,1] because that's the typical range of NDC. If I remember correctly, OpenGL uses [-1,1] for all three axes, and DirectX uses [-1,1] for x and y and [0,1] for z.

Oh, so by adding 1 you make it positive and later divide by 2 to make up for adding 'that half of the screen' ???

Yes. One way to think about it is that (x + 1) / 2 maps the interval [-1,1] to [0,1], and multiplying by Width maps [0,1] to [0,Width].

##### Share on other sites

Edited by RoundPotato

##### Share on other sites


Edited by RoundPotato

##### Share on other sites
I grew up in an environment where I didn't know anyone that knew math or programming, and I was really interested in both. I didn't have access to many books and the Internet hadn't been invented yet. All in all, you are probably better off learning in today's environment, with easy online access to tons of resources and experts. But there is something to be said about learning to fight with a problem and having to learn to convince yourself that your answer is correct without external help, by trying a few examples or proving a few theorems. I think you should give it a try and find out for yourself if you are right or not.

##### Share on other sites


Edited by RoundPotato