[Patch] Custom projection with quad_normals camera_direction

Discussion area about developing with Ogre-Next (2.1, 2.2 and beyond)


zxz
Gremlin
Posts: 184
Joined: Sat Apr 16, 2016 9:25 pm
x 19

[Patch] Custom projection with quad_normals camera_direction

Post by zxz »

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;
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5503
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1370

Re: [Patch] Custom projection with quad_normals camera_direc

Post by dark_sylinc »

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
zxz
Gremlin
Posts: 184
Joined: Sat Apr 16, 2016 9:25 pm
x 19

Re: [Patch] Custom projection with quad_normals camera_direc

Post by zxz »

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
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5503
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1370

Re: [Patch] Custom projection with quad_normals camera_direction

Post by dark_sylinc »

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