9

Vulkan uses a coordinate system where (-1, -1) is in the top left quadrant, instead of the bottom left quadrant as in the standard cartesian coordinate system one typically learns about in school. So (-1, 1) is in the bottom left quadrant in Vulkan's coordinate system.

Image from: http://vulkano.rs/guide/vertex-input

(image from: http://vulkano.rs/guide/vertex-input)

What are the advantages of using Vulkan's coordinate system? One plain advantage I can see is pedagogical: it forces people to realize that coordinate systems are arbitrary, and one can easily map between them. However, I doubt that's the design reason.

So what are the design reasons for this choice?

9
  • I'm not as familiar with Vulkan, but the origin of screen coordinates is typically the top left. While the (-1, -1) is unusual (IMO), it looks like Vulkan is using something akin to a unit vector (or in this case, a unit rectangle). Why do this? That's a good question, which is why this is a comment and not an answer. :)
    – TriskalJM
    Dec 30, 2017 at 18:04
  • @TriskalJM I think I wrote the question in a confusing manner initially, since it is not that (-1, 1) is the top left corner, but it is in the top left quadrant. Does that make more sense?
    – bzm3r
    Dec 30, 2017 at 18:06
  • 1
    Ok, so the origin is in the center, with positive x pointing down, and positive y pointing to the right? They wanted the origin to be in the center (which makes sense), and then they kept the traditional method of down and right being positive for screen coordinates.
    – TriskalJM
    Dec 30, 2017 at 18:09
  • @TriskalJM Actually, now I am not sure, maybe it is the unit rectangle system you were first describing. I am still only learning Vulkan, so I am not yet very sure. Anyway, I provided a picture from the guide I was reading.
    – bzm3r
    Dec 30, 2017 at 18:12
  • Upvote 'cause good to catch one of my typical 'gotchas'. Dec 30, 2017 at 18:13

2 Answers 2

15

Many coordinate systems in computer graphics put the origin at the top-left and point the y axis down.

This is because in early televisions and monitors, the electron beam that draws the picture starts at the top-left of the screen and progresses downward.

The pixels on the screen were generally made by reading memory in sequential addresses as the beam moved down the screen, and modulating that electron beam in accordance with each byte read in sequence. So the y axis corresponds to time, which corresponds to memory address.

Even today, virtually all representations of a bitmap in memory, or in a bitmapped file, start at the top-left.

It is natural when drawing bitmaps in such a medium to use a coordinate system that starts at the top-left too.

Things become a little more complicated when you use a bottom-left origin because finding the byte that corresponds to a pixel requires a little more math and needs to account for the height of the bitmap. There is usually just no reason to introduce the extra complexity.

When you start to introduce matrix transformations however, it becomes much more convenient to work with an upward-pointing y axis, because that lets you use all the vector algebra you learned in school without having to reverse the y axis and all the rotations in your thinking.

So what you'll usually find is that when you are working in a system that lets you do matrix operations, translations, rotations, etc., then you will have an upward-pointing y axis. At some point deep inside, however, the calculations will transform the coordinates into a downward-pointing y axis for the low-level operations.

4
  • Wouldn't there be significant loss in speed if one has to transform up-y coordinates into down-y coordinates using a matrix transform, only so that later than transform is undone (by the inverse transform)? wouldn't it be better to just not transform into up-y coordinates in the first place, and accept the pedagogical inconvenience of having to deal with a down-y coordinate?
    – bzm3r
    Dec 31, 2017 at 17:04
  • 4
    The nice thing about matrix transforms is that you can fold any number of them together into a single matrix, and there's always some matrix in place, so you can apply whatever transformations you like without affecting performance at all. Dec 31, 2017 at 17:57
  • @user89 I used the new OpenGL 4.5 feature of making the topleft corner (-1, -1) like Vulkan instead of the typical (-1, 1) OpenGL has. After doing that everything appeared upside down, but if you multiply second element of the Y component in the projection matrix by -1 everything becomes normal. So in other words performance wise it should be exactly the same.
    – Zebrafish
    Jan 1, 2018 at 0:03
  • 1
    There's no inherent advantages to a coordinate system with up as +y. All the same vector/matrix math applies exactly the same. What does matter is whether or not it's a "right handed" coordinate system (direction of +z relative to +x and +y). Both OpenGL and Vulkan are right handed coordinate systems, and i tend to think Vulkan makes more sense as it follows the convention for image storage and screen coordinates, and has +z into the screen. Jul 28, 2018 at 4:47
12

One of the common sources of confusion and bugs in OpenGL was that NDC and window coordinates had y increasing upwards, which is opposite of the convention used in nearly all window systems and many (but not all) image formats, where y is [0..1] increasing downwards. Developers ended up having to insert a y-flip in their transformation pipeline in many cases, and it wasn't always clear when they did and didn't.

So Vulkan decided to make it so you could load an image from a y-downwards image format directly into memory and draw it to the screen without any explicit y flips, to avoid this source of errors.

Other coordinate systems were then chosen to be consistent with that, in the sense that the y direction never flips direction in the standard Vulkan transformation pipeline. That meant that clip space vertex coordinates also had y increasing downwards.

This ended up meaning that Vulkan clip coordinates have a different orientation than D3D clip coordinates, which was an annoyance for developers supporting both APIs. So the VK_KHR_maintenance1 extension adds the ability to specify a negative viewport height, which essentially introduces a y-flip to the clip-space to framebuffer coordinate transform. (D3D has essentially always had an implicit y-flip here.)

This is how I remember the reasoning in the Vulkan Working Group, anyway. I don't think there's an authoritative public source anywhere.

1
  • I'm not sure whether this is part of the reason, but OpenGL by default assumes right-handed world coordinates, but as soon as multiplying by the projection matrix the coordinates become left-handed (x is right, z into the screen, and y is up). Having Y going down makes the coordinates right-handed again.
    – Zebrafish
    Jan 1, 2018 at 0:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.