[Patch] Custom projection with quad_normals camera_direction

Discussion area about developing with Ogre2 branches (2.1, 2.2 and beyond)
Post Reply
zxz
Greenskin
Posts: 141
Joined: Sat Apr 16, 2016 9:25 pm
x 5

[Patch] Custom projection with quad_normals camera_direction

Post by zxz » Mon Nov 14, 2016 11:57 am

Hello,

There's an issue with using a custom projection matrix together with the setting "quad_normals camera_direction" when using a quad pass. In our case, we have a custom matrix for the Oculus HMD, and use the quad pass for sky rendering. The camera direction ends up wrong in the quad pass, so the sky appears zoomed in and doesn't stay stationary with respect to other objects as you look around in the HMD.

The problem is fixed by the following change in the Ogre code base (clip space corners at -1 to 1 instead of -0.5 to 0.5):

Code: Select all

diff -r 04f7437fcbb8 OgreMain/src/OgreFrustum.cpp
--- a/OgreMain/src/OgreFrustum.cpp	Mon Oct 17 19:32:28 2016 -0300
+++ b/OgreMain/src/OgreFrustum.cpp	Mon Nov 14 11:51:26 2016 +0100
@@ -321,8 +321,8 @@
         {
             // Convert clipspace corners to camera space
             Matrix4 invProj = mProjMatrix.inverse();
-            Vector3 topLeft(-0.5f, 0.5f, 0.0f);
-            Vector3 bottomRight(0.5f, -0.5f, 0.0f);
+            Vector3 topLeft(-1.0f, 1.0f, 0.0f);
+            Vector3 bottomRight(1.0f, -1.0f, 0.0f);
 
             topLeft = invProj * topLeft;
             bottomRight = invProj * bottomRight;
0 x

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 4148
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 270
Contact:

Re: [Patch] Custom projection with quad_normals camera_direc

Post by dark_sylinc » Mon Nov 14, 2016 2:55 pm

Thanks.

Pushed.

Normally I prefer PR (Pull requests). When the bug is too important or too easy to fix (and my repos aren't in a WIP state so I can push the change) I can do it myself. If you could submit PRs that would be great (tag me as reviewer so I get an email notification when the PR is created).

Thanks & Cheers
Matias
0 x

zxz
Greenskin
Posts: 141
Joined: Sat Apr 16, 2016 9:25 pm
x 5

Re: [Patch] Custom projection with quad_normals camera_direc

Post by zxz » Mon Nov 14, 2016 3:02 pm

I'll do that next time. I wasn't sure of the extent pull requests are used in the project.

Thanks for accepting the change!

Cheers
0 x

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 4148
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 270
Contact:

Re: [Patch] Custom projection with quad_normals camera_direction

Post by dark_sylinc » Thu Aug 08, 2019 4:19 pm

Hi!

Someone opened a papercut regarding this snippet.
Turns out your fix was wrong, and the original code was "mostly correct, but wrong".

It has been fixed but it will likely break your app because your Oculus projection matrices are in the wrong depth space.

I added an extra parameter 'alternateDepthRange' which you should set to true so that we handle the conversion for you automatically.

Note however that after doing this, camera->getProjectionMatrix() != originalOculusMatrix, because they have different depth range.

Cheers
Matias
0 x

Post Reply