Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upFix perspective projection transform #465
Conversation
Please review this commit carefully, as I only partially know what I'm doing. I believe that setting `m44` to one for the perspective projection matrix is wrong. First, the sources I can find that explain this all set it to zero. Granted, I can't find many sources online that explain this clearly, but the few that I can find support my point (see Wikipedia[1] and this university lecture[2], for example). Second, I did some transformation on paper, to better understand this, and while the approaches in the cited sources starting making sense to me, I can't make head or tails of that one in the m44 position. It just seems to get in the way. So while I can't rule out that the way things currently are make total sense for reasons I don't understand yet, as of right now, it seems more like an oversight. [1] https://en.wikipedia.org/wiki/Transformation_matrix#Perspective_projection [2] https://courses.cs.washington.edu/courses/cse455/09wi/Lects/lect5.pdf, page 23
|
You had me scratch my head for a good hour and a half (and I learned stuff in the process). Before we go into why, let's start with references (it at least gave me some confidence that we aren't doing something crazy)
Why then ? It's interesting because your reasoning and your sources do make sense. My understanding is that it is a question of which plane the perspective transform is projecting things on. In the case of euclid, the matrix projects points onto the plane defined by I think that it makes most sense for euclid to keep perspective as is and continue following the CSS specification. That said this method really need better documentation. Anyway I'll close this now since I believe that we shouldn't change the behavior of perspective. |
|
Thank you for your reply! I hate to take up more of your time, but here I go.
Those are certainly some strong sources. If I had been aware of those at an earlier point, I probably wouldn't have even posted this pull request. However, I'm too deep into it by now to just yield to these, especially since I don't quite follow your explanation :-)
I think this isn't quite on point, for two reasons. First, yes, the Wikipedia matrix projects to Second, I don't believe that projecting to First, let's take a closer look at the matrices. I'm going to ignore the Wikipedia matrix from here on, as it's basically equivalent to the Washington matrix (modulo the hardcoded distance and different viewing direction), and the Washington matrix is much closer to the Euclid one, hence being better suited to demonstrate the difference. Here's the Washington matrix:
And here's the Euclid matrix. Please note that the Euclid documentation formats matrices differently, based on the order of their fields in memory. I'm translating it into the format used by all of the sources (including yours) here, for clarity:
The only difference between them is the I'm claiming that the Washington matrix projects points into the Let's try that for the Washington matrix with
We're getting the same point out that we put in. Let's do the same with the Euclid matrix:
The
Which are not the same coordinates that our original point had, even though we were projecting it into the plane it was already in. Doing the same for other planes leads to similar results. I've done lots more calculations along the same lines, and the result is always the same: The Washington approach (with Maybe I'm missing something. Maybe the Euclid approach has some advantage that I'm not seeing. Maybe something else needs to happen before or after the perspective transformation to correct for this (I don't know what that might be, or why it might be an advantage). Thoughts on your sourcesIf this was just a Euclid thing, I'd be fully convinced that this is buggy behavior that needs to change. However, that you can point to those sources that are doing it the same way, is a strong argument that there is something going on here that I don't understand. I don't have much insight into browser and web standards development, so what I'm about to say might be preposterous. Still, let me float this possibility: Is it possible, that this is an error in the spec, and everyone just copied the same mistake from the spec and/or each other? Please consider the following notes, that could make this theory less preposterous:
Again, this might be preposterous, as I don't know how much scrutiny goes into the development of these standards and their implementation. Additional sourcesWhile articles explaining this subject clearly (and without resorting to "call this perspective function to make the matrix") seem to be rare, all I have seen use a I figured it wouldn't hurt to dig up some more sources, preferably involving real code. Here's what I came up with:
I didn't omit any sources. I just looked up the math libraries I could come up with off the top of my head, and all of them set I'm sorry for being so persistent when it's so likely I'm just missing something, but I've become obsessed at this point. If the behavior in Euclid is correct, I absolutely need to know why :-) |
|
I'm going to have to ponder on this for a bit, don't worry if you don't hear back for a time. @jrmuizel do you have any insight or know who was involved in this spec? |
hannobraun commentedAug 21, 2020
Please review this commit carefully, as I only partially know what I'm
doing. I believe that setting
m44to one for the perspectiveprojection matrix is wrong.
First, the sources I can find that explain this all set it to zero.
Granted, I can't find many sources online that explain this clearly, but
the few that I can find support my point (see Wikipedia[1] and this
university lecture[2], for example).
Second, I did some transformation on paper, to better understand this,
and while the approaches in the cited sources starting making sense to
me, I can't make head or tails of that one in the m44 position. It just
seems to get in the way.
So while I can't rule out that the way things currently are make total
sense for reasons I don't understand yet, as of right now, it seems more
like an oversight.
[1] https://en.wikipedia.org/wiki/Transformation_matrix#Perspective_projection
[2]
https://courses.cs.washington.edu/courses/cse455/09wi/Lects/lect5.pdf,
page 23