Oblique near clipping plane for camera

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Igor Kosyanenko

Hello there.
I’m trying to create oblique near clipping plane matrix for camera for rendering portals as seen in this tutorial
I’ve managed to edit engine’s source code so now Camera object has new projection called “Oblique” so I can now specify Quat for near clipping plane.
Here’s code i’ve added to the engine to generate oblique matrix: https://pastebin.com/t6NcTe3E
I’ve grabbed this piece of code from there.
If you’re interested here is some science paper about oblique near plane
Next I wrote some code to calculate Quat for Oblique matrix(as seen in the tutorial at the beginning of question(code from repo))
_multiply_point and _multiply_vector are my interpretation of similar functions from this Unity repo(Find MultiplyPoint and MultiplyVector)
Now to question part:
1) Sky box is somewhat distorded when I use my new projection matrix but mesh rendering is OK. I have no idea why this is happening.

Sky should not be upside down.

Sun is distorded near the horizon.

2) main one. Somewhat calculations are wrong and near clipping plane is doing whatever it wants to. I’ve done same calculations by myself in Unity and everything is working perfectly.(Here’s repo from tutorial above)

I have NO idea what and where could possibly go wrong. I’ve tried swapping matrix indexes, moving _multiply_point and _multiply_vector to source code, swapping variables and etc.

Here’s my project
Here’s modified engine source code(Heavy!)
Here’s linux build

Thank you!

Hello Igor,

I’ve just been successful in applying your solution to my project, up to the point where the only thing going wrong is the skybox too.

I’ve tried to give the portal camera the same environment as the player-camera, but, to no avail (likely because it was already inheriting it by default).

I think there must be some relationship between skyboxes and the camera that must be accounted when applying the oblique matrix.

If you’ve had any success in the 1.5 years since you posted, please let me know, otherwise I will try to update with my progress towards a solution.

qaptoR | 2021-11-10 18:09

:bust_in_silhouette: Reply From: qaptoR

Hello Igor,

Trust me when I say I have also been trying like 1000 things to solve this issue, so don’t think the solution came easily to me. (I stumbled on it once I finally decided to look into how the skybox is rendered, and just sorta played with the settings)

Simply go to the WorldEnvironment node (or whichever environment your camera can see, and change ‘Environment->Background->Sky_Custom_FOV’ to whatever the base FOV of the portal camera is (should be the same as the player camera as well) and bam!

Here is a video showing the solution in action:

Yes, I will be providing engine source code eventually (and making a pull request once I’ve worked out how to integrate the oblique camera into the editor UI: i’m currently operating on the oblique camera using gdscript only)

I am also working on making the portal a template, though it will require the custom editor, as the matrix manipulation has to happen under the hood in order to be applied.