Skip to content
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

Merged
merged 3 commits into from
May 27, 2021

Conversation

zalo
Copy link
Contributor

@zalo zalo commented May 13, 2021

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

Portal

Here's a .gif that shows my test implementation:
Kooima

And here's a fun video I made a while ago in Unity that uses the same formulation.

zalo added 2 commits May 13, 2021 00:33
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
@gonnavis
Copy link
Contributor

gonnavis commented May 13, 2021

Seems used something like Oblique Near-Plane Clipping, will it distort depthBuffer?

Related: #21574

@mrdoob mrdoob added this to the r129 milestone May 13, 2021
@mrdoob
Copy link
Owner

mrdoob commented May 13, 2021

Very nice!

Would you be up for also adding an example that shows how to use it to the PR?
Maybe a portal example?

@WestLangley
Copy link
Collaborator

it sets the camera's quaternion and projectionMatrix frustum to exactly frame an arbitrary rectangle

Completely arbitrary? Your demo appears to only consider rectangles whose bottom edge is parallel to the x-z plane.

@zalo
Copy link
Contributor Author

zalo commented May 14, 2021

Completely arbitrary [rectangle]? 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...

@zalo
Copy link
Contributor Author

zalo commented May 14, 2021

Just added the portal example:
https://raw.githack.com/zalo/three.js/39778281b2a6f0772fd6ab083a00cf2c49835080/examples/?q=portal#webgl_portal

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?

@mrdoob
Copy link
Owner

mrdoob commented May 27, 2021

Ops! Could you remove the build from the PR?

@zalo zalo force-pushed the feat-generalized-projection branch from 3977828 to 2e2b4a0 Compare May 27, 2021 03:18
@zalo
Copy link
Contributor Author

zalo commented May 27, 2021

Yep! (Sorry about that)

@mrdoob mrdoob merged commit b67a3f7 into mrdoob:dev May 27, 2021
@mrdoob
Copy link
Owner

mrdoob commented May 27, 2021

Thanks!

@mrdoob
Copy link
Owner

mrdoob commented May 27, 2021

Considering that bundlers can't yet treeshake methods...
I've moved it to a new CameraUtils class in the examples folder: e87bfeb

@Mugen87 Mugen87 mentioned this pull request May 27, 2021
@joshuaellis joshuaellis mentioned this pull request May 27, 2021
11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants