-
Notifications
You must be signed in to change notification settings - Fork 189
Ortho/Perspective matrices are different than from DirectX 9 Math library. #22
Comments
Hey Franken, thanks for the question.
I looked into this too, a while back, when we added right/left-handed
support. It's caused by a difference between DirectX and OpenGL.
- In DirectX, the z-near plane maps to -1. That is, DirectX depth
clipping happens on z values in the [-1, 1] range.
- In OpenGL, the z-near plane maps to 0. That is, OpenGL depth clipping
happens on z values in the [0, 1] range.
MathFu creates OpenGL matrices, so they're slightly different than the
DirectX matrices. If you compare MathFu to glm, however, you should notice
that they're the same.
I agree it would be useful for cross-platform development to have support
for DirectX, too. If you'd like to create a pull request with that support,
I'd be very happy to take a look!
…On Wed, May 3, 2017 at 3:35 AM, Franken ***@***.***> wrote:
Hi there.
Currently i have working on some test and found some unclear moments
between Mathfu and DirectX Math.
I know how the canonical perspective and orthographic matrices looks like.
What i wondering is why DirectX Math uses different calculations for
perspective and orthographic matrices?
I work with DirectX Math almost 10 years and never had a problems with
projection matrices.
For example i had run tests from 'matrix_test.cpp' for DirectX 9 Math and
get next results.
Right-handed perspective
( atan( 1.0 ) * 2.0, 1.0, -2.0, 2.0 )
Mathfu DirectX9
| 1.0 0.0 0.0 0.0 | 1.0 0.0 0.0 0.0 |
| 0.0 1.0 0.0 0.0 | 0.0 1.0 0.0 0.0 |
| 0.0 0.0 -0.5 -1.0 | 0.0 0.0 -0.5 -1.0 |
| 0.0 0.0 2.0 0.0 | 0.0 0.0 1.0 0.0 |
Left-handed perspective
( atan( 1.0 ) * 2.0, 1.0, -2.0, 2.0 )
Mathfu DirectX9
| 1.0 0.0 0.0 0.0 | 1.0 0.0 0.0 0.0 |
| 0.0 1.0 0.0 0.0 | 0.0 1.0 0.0 0.0 |
| 0.0 0.0 0.5 1.0 | 0.0 0.0 0.5 1.0 |
| 0.0 0.0 2.0 0.0 | 0.0 0.0 1.0 0.0 |
Right-handed orthographic
( 1.0, 3.0, 1.0, 3.0, 1.0, 3.0 )
Mathfu DirectX9
| 1.0 0.0 0.0 0.0 | 1.0 0.0 0.0 0.0 |
| 0.0 1.0 0.0 0.0 | 0.0 1.0 0.0 0.0 |
| 0.0 0.0 -1.0 0.0 | 0.0 0.0 -0.5 0.0 |
|-2.0 -2.0 -2.0 1.0 |-2.0 -2.0 -0.5 1.0 |
Left-handed orthographic
( 1.0, 3.0, 1.0, 3.0, 1.0, 3.0 )
Mathfu DirectX9
| 1.0 0.0 0.0 0.0 | 1.0 0.0 0.0 0.0 |
| 0.0 1.0 0.0 0.0 | 0.0 1.0 0.0 0.0 |
| 0.0 0.0 1.0 0.0 | 0.0 0.0 0.5 0.0 |
|-2.0 -2.0 -2.0 1.0 |-2.0 -2.0 -0.5 1.0 |
This moment is crucial in cross-platform development perspective. In fact,
the DirectX math library is good enough for using it on Windows desktop
systems. But for portability purposes we need another math library. And
Mathfu looks good enough to use it on other systems.
But that difference mixes the cards. Does the different calculations makes
the real difference in results?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#22>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AF3McHouCtWsvBq8L7EFd8IzWRSrKzbmks5r2FhqgaJpZM4NPN9K>
.
|
@jsanmiya , thanks for response.
I didn't thought about it. Can you help me providing some links to DirectX and OpenGL documentation about z plane mapping? Seems this information has eluded me. What about PR for DirectX support, firstly i need to deeply understand the reasons of that difference. :) |
So, i had found the documents about transformation pipeline of Direct3D and OpenGL. Direct3D Transformation pipeline I had found two interesting notes in Direct3D Transformation pipeline:
Second:
At one side we have z-plane mapping in (0, 1]. Is it that what @jsanmiya talking about? OpenGL transformation pipeline gives me only one interesting note:
And here is the difference between DirectX and OpenGL - the range of normalized Z coordinate.
It could be important if viewport specifications for both api had lack of z-near and z-far fields. Only note about additional precision still looks important enough to keep such difference. |
Hi there.
Currently i have working on some test and found some unclear moments between Mathfu and DirectX Math.
I know how the canonical perspective and orthographic matrices looks like. What i wondering is why DirectX Math uses different calculations for perspective and orthographic matrices?
I work with DirectX Math almost 10 years and never had a problems with projection matrices.
For example i had run tests from 'matrix_test.cpp' for DirectX 9 Math and get next results.
This moment is crucial in cross-platform development perspective. In fact, the DirectX math library is good enough for using it on Windows desktop systems. But for portability purposes we need another math library. And Mathfu looks good enough to use it on other systems.
But that difference mixes the cards. Does the different calculations makes the real difference in results?
The text was updated successfully, but these errors were encountered: