• FEATURED

View more

View more

View more

Image of the Day Submit

IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

Why potatoeses

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

15 replies to this topic

#1RoundPotato  Members

Posted 31 July 2014 - 09:00 AM




#2Álvaro  Members

Posted 31 July 2014 - 09:25 AM

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

#3RoundPotato  Members

Posted 31 July 2014 - 10:40 AM



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

#4samoth  Members

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  Members

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.

#6SeanMiddleditch  Members

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.

Game Developer, C++ Geek, Dragon Slayer - http://seanmiddleditch.com

C++ SG14 "Games & Low Latency" - Co-chair - public forums

Wargaming Seattle - Lead Server Engineer - We're hiring!

#7RoundPotato  Members

Posted 31 July 2014 - 12:16 PM



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

#8Álvaro  Members

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.

#9Samith  Members

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

#10RoundPotato  Members

Posted 31 July 2014 - 01:53 PM



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

#11Álvaro  Members

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

#12RoundPotato  Members

Posted 31 July 2014 - 02:55 PM



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

#13RoundPotato  Members

Posted 01 August 2014 - 10:31 AM




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

#14Álvaro  Members

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.

#15RoundPotato  Members

Posted 01 August 2014 - 02:25 PM




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

#16Álvaro  Members

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.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.