-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PerspectiveCamera: Add Kooima's Generalized Projection Formulation #21825
Conversation
Addresses Issue mrdoob#5381 This PR adds an implementation for Kooima's Generalized Projection Matrix Formulation, better known as "the way CAVE rendering works". In a nutshell, it sets the `projectionMatrix` frustum to exactly frame an arbitrary rectangle. This is a key operation in rendering portals, CAVEs, and certain kinds of projection based effects. I find myself porting and reporting this function wherever I go because it's so darn useful. I'm not certain that this is the right place in the codebase for it, but I'd really love for three.js to have a working implementation for people to use. Here's a video I made years ago that utilizes the formulation: https://www.youtube.com/watch?v=90kHhOUzeQc&t=1s
Seems used something like Oblique Near-Plane Clipping, will it distort depthBuffer? Related: #21574 |
Very nice! Would you be up for also adding an example that shows how to use it to the PR? |
Completely arbitrary? Your demo appears to only consider rectangles whose bottom edge is parallel to the x-z plane. |
Sorry; it does work on arbitrary (camera-facing) rectangles, but I made a poor choice of specifying corner manipulations in the gif-demo, so the more interesting movements would have broken rectangliness. I’m putting together a portal example now that will show off the feature more effectively... |
Just added the portal example: Hopefully the mirror example fellow doesn't mind me being derivative xD Is the base camera class the best place for this utility function? Does it need additional documentation translations and some unit tests? Or should it belong in an example utility class? |
e8c8dff
to
3977828
Compare
Ops! Could you remove the build from the PR? |
3977828
to
2e2b4a0
Compare
Yep! (Sorry about that) |
Thanks! |
Considering that bundlers can't yet treeshake methods... |
Related issue: #5381
Description
This PR adds an implementation for Kooima's Generalized Projection Matrix Formulation, better known as "the way CAVE and Portal rendering work".
In a nutshell, it sets the camera's quaternion and
projectionMatrix
frustum to exactly frame an arbitrary rectangle. This is a key operation in rendering portals, CAVEs, and certain kinds of projection based effects.I find myself porting and reporting this function wherever I go because it's so darn useful. I'm not certain that this is the right place in the codebase for it, but I'd really love for three.js to have a working implementation for people to use. Happy to move it to a more appropriate location and/or to add unit tests.
Here's a live demo of the new Portal Example:
https://raw.githack.com/zalo/three.js/feat-generalized-projection/examples/?q=portal#webgl_portal
Here's a .gif that shows my test implementation:
And here's a fun video I made a while ago in Unity that uses the same formulation.