Vulkan perspective projection matrices or more flexible perspective matrix functions #711
Replies: 2 comments 5 replies
-
|
Hi there. Yes providing a more general solution is something I'd like to do for glam. Interface wise I haven't worked out exactly how it should look, but behind the scenes it could be a method that can generate the correct matrix for the input parameters that you describe. What I'm thinking is:
Not suggesting that you do all of this, but if you have some code that does some of the implementation it would help progress things. Dealing with different graphics APIs and projection matrices is not something I regularly do so any help is appreciated. |
Beta Was this translation helpful? Give feedback.
-
|
@bitshifter As discussed, here's a slightly jank example version for what I was imagining. It's nowhere near complete, but it should give you an idea for it. How this works is basically:
I ended up making Some further discussion items could be:
I didn't check if this actually compiles nicely, hopefully the matrix multiplications get constant evaluated Also if you think of any extra parameters, let me know. One thing I thought about already is pre and post multiplication (in webgpu, vulkan and opengl people tend to write Had to rename the file to txt as GitHub doesn't support uploading rs files. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
For a personal project I needed a set of vulkan-specific projection matrices, meaning:
I implemented these into a fork of glam and thought you might be interested in a PR for them? I have tests and stuff ready for it.
Alternatively I've seen discussions about a more general solution (#569), which I would be willing to tackle if there's a need for it, just need some pointers on what the preferred implementation would look like.
What I'm thinking is that a perspective projection matrix is basically the result of the following "decisions":
I think the simplest and probably most user-friendly approach to go at this is something like
which generates the perspective matrix from smaller components, each influencing how a view space position would get mapped to clip space. Second step after this would be to hope this mess can get untangled by the compiler into something that doesn't need runtime matrix multiplications.
My personal opinion is that the purposefully specific perspective_lh, perspective_rh, perspective_rh_gl, etc. functions are nice to have, since most people probably don't want to fuss with exact projection parametrizations too much, but if a more general solution emerges, they could use that as the implementation backend.
Beta Was this translation helpful? Give feedback.
All reactions