Jump to content

  • Log In with Google      Sign In   
  • Create Account


What makes OpenGL right handed?


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.

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

#41 scgames   Members   -  Reputation: 1977

Like
0Likes
Like

Posted 26 March 2010 - 03:50 AM

Quote:
Frustum clipping is something we have no control over, so possibly at this point OpenGL expects a right handed system (i.e. looking down -z) to properly clip. Is this right?
No, I don't believe that is right.
Quote:
Direct3D uses a left handed clip space and OpenGL a right handed clip space.
What leads you to believe that clip space is right-handed in OpenGL?

Sponsor:

#42 szecs   Members   -  Reputation: 2111

Like
0Likes
Like

Posted 26 March 2010 - 03:52 AM

Even in the most recent openGL versions there is a default setup/whatever. The identity matrices, depth-range/test, for example. Doesn't that make handedness defined?
(Okay, I am perfectly aware, that this is pure philosophy, not CS, but anyway.)

(Sorry, I want to fulfill my prophecy about the multipaged-then-closed thread.)

#43 GaryNas   Members   -  Reputation: 134

Like
0Likes
Like

Posted 26 March 2010 - 04:06 AM

Quote:
Original post by jyk
What leads you to believe that clip space is right-handed in OpenGL?


The internet? :)

For DirectX (using a left handed system), if I look at the vertex shader output in PIX, all visible vertices have a positive z value.

#44 scgames   Members   -  Reputation: 1977

Like
0Likes
Like

Posted 26 March 2010 - 04:13 AM

Quote:
Even in the most recent openGL versions there is a default setup/whatever. The identity matrices, depth-range/test, for example. Doesn't that make handedness defined?
I would say so, and I would say that this 'default' setup would be left-handed, not right-handed. (This is because if no non-identity transforms are applied, vertices will be passed unchanged to normalized device space, which is left-handed.)

#45 scgames   Members   -  Reputation: 1977

Like
0Likes
Like

Posted 26 March 2010 - 04:14 AM

Quote:
Original post by GaryNas
Quote:
Original post by jyk
What leads you to believe that clip space is right-handed in OpenGL?


The internet? :)
Can you provide a link to a reference?

#46 swiftcoder   Senior Moderators   -  Reputation: 9860

Like
0Likes
Like

Posted 26 March 2010 - 05:02 AM

This is the closest I found to 'official' docs on the matter: http://www.opengl.org/resources/faq/technical/transformations.htm#tran0150.

Tristam MacDonald - Software Engineer @Amazon - [swiftcoding]


#47 scgames   Members   -  Reputation: 1977

Like
0Likes
Like

Posted 26 March 2010 - 05:14 AM

Quote:
This is the closest I found to 'official' docs on the matter: http://www.opengl.org/resources/faq/technical/transformations.htm#tran0150.
I realize that comes from the OpenGL website, but that FAQ entry seems a bit suspect to me. Even with the fixed-function pipeline, you shouldn't have to apply an 'extra' scaling in order to get a left-handed system; rather, it should be as simple as creating your own (left-handed) view and projection transforms and uploading them via glLoadMatrix() and/or glMultMatrix().

#48 szecs   Members   -  Reputation: 2111

Like
0Likes
Like

Posted 26 March 2010 - 05:15 AM

Quote:
Original post by swiftcoder
This is the closest I found to 'official' docs on the matter: http://www.opengl.org/resources/faq/technical/transformations.htm#tran0150.
Ahhahahaha (sorry). This won't end soon...

#49 swiftcoder   Senior Moderators   -  Reputation: 9860

Like
0Likes
Like

Posted 26 March 2010 - 05:48 AM

Quote:
Original post by jyk
Quote:
This is the closest I found to 'official' docs on the matter: http://www.opengl.org/resources/faq/technical/transformations.htm#tran0150.
I realize that comes from the OpenGL website, but that FAQ entry seems a bit suspect to me.
Thus the quote marks on 'official'. I have no idea who wrote or maintained those FAQ pages, but they haven't been updated since the dawn of time, and at least one answer was wrong to start with.

Tristam MacDonald - Software Engineer @Amazon - [swiftcoding]


#50 GaryNas   Members   -  Reputation: 134

Like
0Likes
Like

Posted 26 March 2010 - 06:10 AM

Quote:
Original post by jyk
Can you provide a link to a reference?


This is the best I can do:

http://www.gamerendering.com/2008/10/05/clip-space/

:(

#51 scgames   Members   -  Reputation: 1977

Like
0Likes
Like

Posted 26 March 2010 - 07:58 AM

Quote:
:(
Hehe :)

The image at the top of that page shows the view frustum in view space. The coordinate system as shown is right-handed, but that's just by convention; you could just as easily set it up to be left-handed (e.g. by building your own projection matrix and uploading it via glLoadMatrix(), or by performing the transform yourself in a shader).

After the division by w, the geometry is in normalized device coordinates, which are described here. Note that it says that the 'near clip plane will map to -1' and 'the far clip plane will map to 1'. In other words, normalized device coordinates are left-handed in OpenGL.

See also here, in the section titled 'The Projection Transform and Perspective Division'. The second diagram in that section shows the canonical view volume. Note the arrangement of the axes (left-handed). It also states that NDC are left-handed in the next paragraph.

As for clip space, unless I'm missing something very obvious, it is also left-handed. z values are clipped to the range -w (near) to w (far), which after division by w is transformed to the range [-1, 1].

So in short, I don't see anything there that indicates that clip space is right-handed in OpenGL.

#52 GaryNas   Members   -  Reputation: 134

Like
0Likes
Like

Posted 26 March 2010 - 09:04 AM

Quote:
Original post by jyk
So in short, I don't see anything there that indicates that clip space is right-handed in OpenGL.


Here's a test for you jyk - try running your right handed OpenGL/Direct3D engine through PIX and see what your post vertex shader values are. I'm willing to bet that they are represented in this space by a left handed system. If we could somehow use PIX with OpenGL, then I would guess they would be represented by a right handed system. It's precisely this space that I'm *guessing* makes DirectX/OpenGL left/right handed.

I've just tried this using two Direct3D right handed engines and both are left handed when I look at the vertex shader output.

Thoughts?


#53 scgames   Members   -  Reputation: 1977

Like
0Likes
Like

Posted 26 March 2010 - 01:09 PM

Quote:
Here's a test for you jyk - try running your right handed OpenGL/Direct3D engine through PIX and see what your post vertex shader values are. I'm willing to bet that they are represented in this space by a left handed system. If we could somehow use PIX with OpenGL, then I would guess they would be represented by a right handed system. It's precisely this space that I'm *guessing* makes DirectX/OpenGL left/right handed.

I've just tried this using two Direct3D right handed engines and both are left handed when I look at the vertex shader output.

Thoughts?
Honestly, I don't think that idea makes any sense. I haven't busted out PIX yet, but I will if I have to (I'm committed to this thread now - this is going to get resolved one way or another ;).

First, let me ask you this. Do you agree that normalized device coordinates are left-handed in OpenGL? For what it's worth, I've provided a couple of links to substantiate it, and I think it would probably be useful to establish this as a 'fact', at least for the purpose of this discussion.

I think we can also agree that prior to being transformed in the vertex shader, geometry is in whatever space we want it to be (left-handed, right-handed, etc.).

So that leaves what I understand to be called 'homogenous clip space'; the space that geometry is in *after* transformation by the vertex shader and *before* division by w. This is the space that you're arguing is somehow left-handed in Direct3D, but right-handed in OpenGL. Assuming we agree about NDC, this would mean that along with the division by w, coordinates are somehow transformed from a RH system to a LH system between clip space and NDC space. How does this happen exactly?

There are several lines of argument that could be pursued here, so I'll just choose a couple. First, I'll refer you again to the second diagram on this page. The NDCS shown there is left-handed, as we've established. Note how the axes are labeled: x'/w', y'/w', and z'/w'. In other words, normalized device coordinates are simply the 'projection' of homogenous clip coordinates into 3-d space. So how would it be exactly that this projection would also effect a change of handedness?

To make this a little more concrete, let's work through an example. Consider a right-handed perspective projection transform with a field of view of 90 degrees, a square aspect ratio, and near and far values of 1 and 2, respectively. The matrix generated by gluPerspective() for this transform is:
1 0  0  0
0 1 0 0
0 0 -3 -4
0 0 -1 0
Now consider the two points:
A = [0 0 -1 1]T
B = [0 0 -2 1]T
Since the system is right-handed and the modelview transform is identity, these points lie directly in front of the viewer, with B farther away than A. Ok so far?

Now, we apply the projection transform to yield homogenous clip coordinates:
[1 0  0  0][ 0]   [ 0]
[0 1 0 0][ 0] = [ 0]
[0 0 -3 -4][-1] [-1]
[0 0 -1 0][ 1] [ 1]

[1 0 0 0][ 0] [ 0]
[0 1 0 0][ 0] = [ 0]
[0 0 -3 -4][-2] [ 2]
[0 0 -1 0][ 1] [ 2]
We already know that B is farther from the viewer than A, and we can see here that if we examine the values z/w, Bz is farther along the positive z axis than is Az. Of course these are just the values of the corresponding normalized device coordinates, so it's no surprise that the results would appear to be in a left-handed coordinate system.

Anyway, I guess my question for you would be, what in the above example indicates that clip coordinates are in a right-handed space? What should I be looking for exactly?

Disclaimer time. There are folks around here who know everything there is to know about the 3-d graphics pipeline (both Direct3D and OpenGL). I'm not one of them, so I can't claim 100% certainty or authority on this matter. There have certainly been times that I really thought I understood something and then found out I was wrong, and who knows - maybe this'll be one of those times. Maybe there's a 'magical right-handed fairy' hiding in the OpenGL pipeline somewhere that I just happen to be blissfully unaware of :)

I don't think that's the case though. I can understand the confusion, but I really think that you (and others) have just heard 'OpenGL is right-handed' so many times that you're determined to find 'right-handedness' where there is none :)

I could trot out some more references and examples, but I think what might be useful at this point would be for you to explain why you think clip space is right-handed in OpenGL. What's the evidence? Can you find any references that state this? How do you reconcile it with the example shown above? And what does it even mean for a homogenous space to be right-handed, or for the space in which the homogenous coordinates reside to have a different handedness than the space in which their 3-d projections reside?

[Ouch - that was a long post :-|]

#54 szecs   Members   -  Reputation: 2111

Like
0Likes
Like

Posted 26 March 2010 - 07:23 PM

SOLD!

#55 scgames   Members   -  Reputation: 1977

Like
0Likes
Like

Posted 26 March 2010 - 07:47 PM

szecs, your prediction about the length of this thread seems to have been well founded ;)

Anyway, I dug around in the specifications a little in the hopes of perhaps putting this to rest. We'll start with this section of the 1.1 spec, item 15.

Item 15 is very clear. Among other things, it states that 'OpenGL does not force left- or right-handedness on any of its coordinate systems'.

It then goes on to give an example of a typical setup, where the view and projection transforms are right-handed, no mirroring or reflection is performed, and near < far for the depth range. It then states that given this setup, the eye coordinate system is right-handed and the clip, normalized device, and window coordinate systems are left-handed [emphasis added]. To repeat, assuming a typical setup, the clip coordinate system is left-handed according to the 1.1 spec.

Now, I don't think any of that has changed since 1.1, but just to be sure, I checked the 4.0 spec as well.

In 'Corollaries', item 7, it states that 'OpenGL does not force left- or right-handedness on any of its coordinate systems'. This is of course the same as the corresponding entry in the 1.1 spec, except that the example has been removed (presumably because it refers to functionality that has been deprecated).

Although the example (in which it is explicitly stated that clip space is left-handed) has been removed, I don't see anything in the section on clipping (2.20) to suggest that anything has changed as far as clipping is concerned.

It seems to me that we can conclude that:

1. The OpenGL API is not 'right-handed', nor is it 'left-handed'. As far as the developer is concerned, it has no inherent handedness.

2. Assuming a typical setup, clip space is left-handed.

So, I hope that settles it :) We'll see though...

#56 Yann L   Moderators   -  Reputation: 1794

Like
0Likes
Like

Posted 26 March 2010 - 08:34 PM

Quote:
Original post by jyk
1. The OpenGL API is not 'right-handed', nor is it 'left-handed'. As far as the developer is concerned, it has no inherent handedness.

What a surprise... [rolleyes]

Quote:
Original post by jyk
2. Assuming a typical setup, clip space is left-handed.

OpenGL clip space is a totally symmetric cube. As such, it doesn't have any inherent handedness by itself. As you quoted, it's apparent handedness is entirely dependent on whatever data you feed it with, and however you use this data afterwards.


#57 scgames   Members   -  Reputation: 1977

Like
0Likes
Like

Posted 26 March 2010 - 08:41 PM

Quote:
What a surprise...
Yeah, I know - I was just trying to convince the holdouts :)

#58 GaryNas   Members   -  Reputation: 134

Like
0Likes
Like

Posted 29 March 2010 - 01:55 AM

Quote:
Original post by jyk
Anyway, I guess my question for you would be, what in the above example indicates that clip coordinates are in a right-handed space? What should I be looking for exactly?


Thanks for the great example jyk. Going through your calculations, it's clear that this confirms what you found regarding OpenGL clip space being left handed. The -1 (3,2) entry in the projection matrix is what turns the right handed system into a left handed one.

To me, this thread has been a great help in simplifying OpenGL/Direct3D interoperability. To me, the only fundamental difference between the two is the z-axis of NDC space going from [-1,1] in OGL and [0,1] in D3D, and an engine that uses both renderers only has to take this difference into consideration.


#59 scgames   Members   -  Reputation: 1977

Like
0Likes
Like

Posted 29 March 2010 - 05:31 AM

Quote:
To me, the only fundamental difference between the two is the z-axis of NDC space going from [-1,1] in OGL and [0,1] in D3D, and an engine that uses both renderers only has to take this difference into consideration.
Yup, exactly - that's pretty much the only thing that differs (mathematically) between my OpenGL and D3D renderers as well.

#60 BradDaBug   Members   -  Reputation: 893

Like
0Likes
Like

Posted 09 April 2010 - 02:56 PM

Quote:
Original post by GaryNas
Quote:
Original post by jyk
Anyway, I guess my question for you would be, what in the above example indicates that clip coordinates are in a right-handed space? What should I be looking for exactly?


Thanks for the great example jyk. Going through your calculations, it's clear that this confirms what you found regarding OpenGL clip space being left handed. The -1 (3,2) entry in the projection matrix is what turns the right handed system into a left handed one.

To me, this thread has been a great help in simplifying OpenGL/Direct3D interoperability. To me, the only fundamental difference between the two is the z-axis of NDC space going from [-1,1] in OGL and [0,1] in D3D, and an engine that uses both renderers only has to take this difference into consideration.


How would you take that into consideration? Is your projection matrix slightly different between OpenGL and Direct3D?




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.



PARTNERS