|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.
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'
, 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
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 :-|]