1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-03-28 19:21:04 +00:00

Cherry pick 'openmw-48-stereo-fixes' into 'master'

Openmw 48 stereo fixes

See merge request OpenMW/openmw!2815
This commit is contained in:
psi29a 2023-03-12 10:53:15 +00:00 committed by Mads Buvik Sandvei
parent efebb8efd8
commit e37860c1dc
5 changed files with 21 additions and 27 deletions

View File

@ -566,7 +566,7 @@ OSG_ARCHIVE="OSGoS-3.6.5-dd803bc-msvc${OSG_MSVC_YEAR}-win${BITS}"
OSG_ARCHIVE_REPO_URL="https://gitlab.com/OpenMW/openmw-deps/-/raw/main" OSG_ARCHIVE_REPO_URL="https://gitlab.com/OpenMW/openmw-deps/-/raw/main"
if ! [ -z $OSG_MULTIVIEW_BUILD ]; then if ! [ -z $OSG_MULTIVIEW_BUILD ]; then
OSG_ARCHIVE_NAME="OSG-3.6-multiview" OSG_ARCHIVE_NAME="OSG-3.6-multiview"
OSG_ARCHIVE="OSG-3.6-multiview-ee297dce0-msvc${OSG_MSVC_YEAR}-win${BITS}" OSG_ARCHIVE="OSG-3.6-multiview-d2ee5aa8-msvc${OSG_MSVC_YEAR}-win${BITS}"
OSG_ARCHIVE_REPO_URL="https://gitlab.com/madsbuvi/openmw-deps/-/raw/openmw-vr-ovr_multiview" OSG_ARCHIVE_REPO_URL="https://gitlab.com/madsbuvi/openmw-deps/-/raw/openmw-vr-ovr_multiview"
fi fi

View File

@ -47,7 +47,7 @@ namespace MWRender
auto& sm = Stereo::Manager::instance(); auto& sm = Stereo::Manager::instance();
auto view = sm.getEye(cv); auto view = sm.getEye(cv);
int index = view == Stereo::Eye::Right ? 1 : 0; int index = view == Stereo::Eye::Right ? 1 : 0;
auto projectionMatrix = sm.computeEyeViewOffset(index) * sm.computeEyeProjection(index, true); auto projectionMatrix = sm.computeEyeProjection(index, true);
postProcessor->getStateUpdater()->setProjectionMatrix(projectionMatrix); postProcessor->getStateUpdater()->setProjectionMatrix(projectionMatrix);
} }

View File

@ -140,8 +140,7 @@ namespace MWRender
private: private:
osg::Matrixf getEyeProjectionMatrix(int view) osg::Matrixf getEyeProjectionMatrix(int view)
{ {
return Stereo::Manager::instance().computeEyeViewOffset(view) return Stereo::Manager::instance().computeEyeProjection(view, SceneUtil::AutoDepth::isReversed());
* Stereo::Manager::instance().computeEyeProjection(view, SceneUtil::AutoDepth::isReversed());
} }
osg::Matrixf mProjectionMatrix; osg::Matrixf mProjectionMatrix;

View File

@ -630,7 +630,7 @@ namespace MWRender
for (int view : { 0, 1 }) for (int view : { 0, 1 })
{ {
auto projectionMatrix = sm.computeEyeProjection(view, true); auto projectionMatrix = sm.computeEyeProjection(view, SceneUtil::AutoDepth::isReversed());
auto viewOffsetMatrix = sm.computeEyeViewOffset(view); auto viewOffsetMatrix = sm.computeEyeViewOffset(view);
for (int col : { 0, 1, 2 }) for (int col : { 0, 1, 2 })
viewOffsetMatrix(3, col) = 0; viewOffsetMatrix(3, col) = 0;
@ -645,23 +645,15 @@ namespace MWRender
{ {
auto& sm = Stereo::Manager::instance(); auto& sm = Stereo::Manager::instance();
auto* projectionMatrixUniform = stateset->getUniform("projectionMatrix"); auto* projectionMatrixUniform = stateset->getUniform("projectionMatrix");
auto projectionMatrix = sm.computeEyeProjection(0, true); auto projectionMatrix = sm.computeEyeProjection(0, SceneUtil::AutoDepth::isReversed());
auto viewOffsetMatrix = sm.computeEyeViewOffset(0); projectionMatrixUniform->set(projectionMatrix);
for (int col : { 0, 1, 2 })
viewOffsetMatrix(3, col) = 0;
projectionMatrixUniform->set(viewOffsetMatrix * projectionMatrix);
} }
void applyRight(osg::StateSet* stateset, osgUtil::CullVisitor* /*cv*/) override void applyRight(osg::StateSet* stateset, osgUtil::CullVisitor* /*cv*/) override
{ {
auto& sm = Stereo::Manager::instance(); auto& sm = Stereo::Manager::instance();
auto* projectionMatrixUniform = stateset->getUniform("projectionMatrix"); auto* projectionMatrixUniform = stateset->getUniform("projectionMatrix");
auto projectionMatrix = sm.computeEyeProjection(1, true); auto projectionMatrix = sm.computeEyeProjection(1, SceneUtil::AutoDepth::isReversed());
auto viewOffsetMatrix = sm.computeEyeViewOffset(1); projectionMatrixUniform->set(projectionMatrix);
for (int col : { 0, 1, 2 })
viewOffsetMatrix(3, col) = 0;
projectionMatrixUniform->set(viewOffsetMatrix * projectionMatrix);
} }
private: private:

View File

@ -67,16 +67,14 @@ namespace Stereo
{ {
auto* uProjectionMatrix = stateset->getUniform("projectionMatrix"); auto* uProjectionMatrix = stateset->getUniform("projectionMatrix");
if (uProjectionMatrix) if (uProjectionMatrix)
uProjectionMatrix->set(mManager->computeEyeViewOffset(0) uProjectionMatrix->set(mManager->computeEyeProjection(0, SceneUtil::AutoDepth::isReversed()));
* mManager->computeEyeProjection(0, SceneUtil::AutoDepth::isReversed()));
} }
void applyRight(osg::StateSet* stateset, osgUtil::CullVisitor* nv) override void applyRight(osg::StateSet* stateset, osgUtil::CullVisitor* nv) override
{ {
auto* uProjectionMatrix = stateset->getUniform("projectionMatrix"); auto* uProjectionMatrix = stateset->getUniform("projectionMatrix");
if (uProjectionMatrix) if (uProjectionMatrix)
uProjectionMatrix->set(mManager->computeEyeViewOffset(1) uProjectionMatrix->set(mManager->computeEyeProjection(1, SceneUtil::AutoDepth::isReversed()));
* mManager->computeEyeProjection(1, SceneUtil::AutoDepth::isReversed()));
} }
private: private:
@ -239,18 +237,24 @@ namespace Stereo
osg::Matrixd computeLeftEyeProjection(const osg::Matrixd& projection) const override osg::Matrixd computeLeftEyeProjection(const osg::Matrixd& projection) const override
{ {
(void)projection; (void)projection;
return mManager->computeEyeViewOffset(0) * mManager->computeEyeProjection(0, false); return mManager->computeEyeProjection(0, false);
} }
osg::Matrixd computeLeftEyeView(const osg::Matrixd& view) const override { return view; } osg::Matrixd computeLeftEyeView(const osg::Matrixd& view) const override
{
return view * mManager->computeEyeViewOffset(0);
}
osg::Matrixd computeRightEyeProjection(const osg::Matrixd& projection) const override osg::Matrixd computeRightEyeProjection(const osg::Matrixd& projection) const override
{ {
(void)projection; (void)projection;
return mManager->computeEyeViewOffset(1) * mManager->computeEyeProjection(1, false); return mManager->computeEyeProjection(1, false);
} }
osg::Matrixd computeRightEyeView(const osg::Matrixd& view) const override { return view; } osg::Matrixd computeRightEyeView(const osg::Matrixd& view) const override
{
return view * mManager->computeEyeViewOffset(1);
}
Manager* mManager; Manager* mManager;
}; };
@ -351,8 +355,7 @@ namespace Stereo
} }
} }
mFrustumManager->update( mFrustumManager->update({ mProjectionMatrix[0], mProjectionMatrix[1] });
{ mViewOffsetMatrix[0] * mProjectionMatrix[0], mViewOffsetMatrix[1] * mProjectionMatrix[1] });
} }
void Manager::updateMultiviewStateset(osg::StateSet* stateset) void Manager::updateMultiviewStateset(osg::StateSet* stateset)