Jump to content

  • Log In with Google      Sign In   
  • Create Account


Why potatoeses

  • You cannot reply to this topic
15 replies to this topic

#1 RoundPotato   Members   -  Reputation: 126

Like
0Likes
Like

Posted 31 July 2014 - 09:00 AM




Sponsor:

#2 Álvaro   Crossbones+   -  Reputation: 12807

Like
2Likes
Like

Posted 31 July 2014 - 09:25 AM

Did you try to use Google to find an answer to your first two questions? Here's the first link I found: http://stackoverflow.com/questions/15693231/normalized-device-coordinates

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)?

#3 RoundPotato   Members   -  Reputation: 126

Like
0Likes
Like

Posted 31 July 2014 - 10:40 AM

 

Edited by RoundPotato, 23 August 2014 - 05:43 PM.


#4 samoth   Crossbones+   -  Reputation: 4677

Like
1Likes
Like

Posted 31 July 2014 - 10:56 AM

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, 31 July 2014 - 10:57 AM.


#5 Álvaro   Crossbones+   -  Reputation: 12807

Like
1Likes
Like

Posted 31 July 2014 - 11:15 AM

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, 31 July 2014 - 11:20 AM.


#6 SeanMiddleditch   Members   -  Reputation: 5056

Like
3Likes
Like

Posted 31 July 2014 - 11:59 AM

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.

#7 RoundPotato   Members   -  Reputation: 126

Like
0Likes
Like

Posted 31 July 2014 - 12:16 PM

 

Edited by RoundPotato, 23 August 2014 - 05:43 PM.


#8 Álvaro   Crossbones+   -  Reputation: 12807

Like
0Likes
Like

Posted 31 July 2014 - 12:31 PM

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.

#9 Samith   Members   -  Reputation: 2139

Like
0Likes
Like

Posted 31 July 2014 - 01:09 PM


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 tongue.png



#10 RoundPotato   Members   -  Reputation: 126

Like
0Likes
Like

Posted 31 July 2014 - 01:53 PM

 

Edited by RoundPotato, 23 August 2014 - 05:43 PM.


#11 Álvaro   Crossbones+   -  Reputation: 12807

Like
1Likes
Like

Posted 31 July 2014 - 02:05 PM

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].

#12 RoundPotato   Members   -  Reputation: 126

Like
0Likes
Like

Posted 31 July 2014 - 02:55 PM

 

Edited by RoundPotato, 23 August 2014 - 05:43 PM.


#13 RoundPotato   Members   -  Reputation: 126

Like
0Likes
Like

Posted 01 August 2014 - 10:31 AM



Edited by RoundPotato, 23 August 2014 - 05:43 PM.


#14 Álvaro   Crossbones+   -  Reputation: 12807

Like
0Likes
Like

Posted 01 August 2014 - 02:11 PM

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.

#15 RoundPotato   Members   -  Reputation: 126

Like
0Likes
Like

Posted 01 August 2014 - 02:25 PM



Edited by RoundPotato, 23 August 2014 - 05:44 PM.


#16 Álvaro   Crossbones+   -  Reputation: 12807

Like
0Likes
Like

Posted 01 August 2014 - 03:24 PM

The counter to that is that debugging is an important skill for a programmer. The most important thing you might learn with your current efforts could very well be the ability to efficiently explore the workings of your program so you can understand those "quirks".

Your formulas are probably right, although the notation you used to describe what your are doing is imprecise or at least not standard.





PARTNERS