diff --git a/source/common/rendering/hwrenderer/data/hw_viewpointbuffer.cpp b/source/common/rendering/hwrenderer/data/hw_viewpointbuffer.cpp index 0233a116b..a7a675eeb 100644 --- a/source/common/rendering/hwrenderer/data/hw_viewpointbuffer.cpp +++ b/source/common/rendering/hwrenderer/data/hw_viewpointbuffer.cpp @@ -100,20 +100,20 @@ void HWViewpointBuffer::Set2D(F2DDrawer *drawer, FRenderState &di, int width, in if (isDrawingFullscreen && isIn2D) //fullscreen 2D { - matrices.mProjectionMatrixLeft.ortho(0, (float) width, (float) height, 0, -1.0f, 1.0f); - matrices.mProjectionMatrixRight.ortho(0, (float) width, (float) height, 0, -1.0f, 1.0f); + matrices.mProjectionMatrix[0].ortho(0, (float) width, (float) height, 0, -1.0f, 1.0f); + matrices.mProjectionMatrix[1].ortho(0, (float) width, (float) height, 0, -1.0f, 1.0f); } else if (isIn2D) // HUD { auto vrmode = VRMode::GetVRMode(true); - matrices.mProjectionMatrixLeft = vrmode->mEyes[0].GetHUDProjection(width, height); - matrices.mProjectionMatrixRight = vrmode->mEyes[1].GetHUDProjection(width, height); + matrices.mProjectionMatrix[0] = vrmode->mEyes[0].GetHUDProjection(width, height); + matrices.mProjectionMatrix[1] = vrmode->mEyes[1].GetHUDProjection(width, height); } else //Player Sprite { auto vrmode = VRMode::GetVRMode(true); - matrices.mProjectionMatrixLeft = vrmode->mEyes[0].GetPlayerSpriteProjection(width, height); - matrices.mProjectionMatrixRight = vrmode->mEyes[1].GetPlayerSpriteProjection(width, height); + matrices.mProjectionMatrix[0] = vrmode->mEyes[0].GetPlayerSpriteProjection(width, height); + matrices.mProjectionMatrix[1] = vrmode->mEyes[1].GetPlayerSpriteProjection(width, height); } matrices.CalcDependencies(); SetViewpoint(di, &matrices); diff --git a/source/common/rendering/hwrenderer/data/hw_viewpointuniforms.h b/source/common/rendering/hwrenderer/data/hw_viewpointuniforms.h index dc1fae4d0..22e7d3c14 100644 --- a/source/common/rendering/hwrenderer/data/hw_viewpointuniforms.h +++ b/source/common/rendering/hwrenderer/data/hw_viewpointuniforms.h @@ -15,8 +15,7 @@ enum class ELightBlendMode : uint8_t struct HWViewpointUniforms { - VSMatrix mProjectionMatrixLeft; - VSMatrix mProjectionMatrixRight; + VSMatrix mProjectionMatrix[2]; VSMatrix mViewMatrix; VSMatrix mNormalViewMatrix; FVector4 mCameraPos; diff --git a/source/common/rendering/hwrenderer/data/hw_vrmodes.cpp b/source/common/rendering/hwrenderer/data/hw_vrmodes.cpp index c3647ff8b..dfa87fee8 100644 --- a/source/common/rendering/hwrenderer/data/hw_vrmodes.cpp +++ b/source/common/rendering/hwrenderer/data/hw_vrmodes.cpp @@ -171,7 +171,8 @@ float getHmdAdjustedHeightInMapUnit() #define isqrt2 0.7071067812f static VRMode vrmi_mono = { 1, 1.f, 1.f, 1.f,{ { 0.f, 1.f },{ 0.f, 0.f } } }; -static VRMode vrmi_stereo = { 1, 1.f, 1.f, 1.f,{ { -.5f, 1.f },{ .5f, 1.f } } }; +static VRMode vrmi_stereo = { 2, 1.f, 1.f, 1.f,{ { -.5f, 1.f },{ .5f, 1.f } } }; +static VRMode vrmi_openxr = { 1, 1.f, 1.f, 1.f,{ { -.5f, 1.f },{ .5f, 1.f } } }; static VRMode vrmi_sbsfull = { 2, .5f, 1.f, 2.f,{ { -.5f, .5f },{ .5f, .5f } } }; static VRMode vrmi_sbssquished = { 2, .5f, 1.f, 1.f,{ { -.5f, 1.f },{ .5f, 1.f } } }; static VRMode vrmi_lefteye = { 1, 1.f, 1.f, 1.f, { { -.5f, 1.f },{ 0.f, 0.f } } }; @@ -194,8 +195,10 @@ const VRMode *VRMode::GetVRMode(bool toscreen) case VR_QUADSTEREO: case VR_AMBERBLUE: case VR_SIDEBYSIDELETTERBOX: + return &vrmi_stereo; + case VR_OPENXR: - return &vrmi_stereo; + return &vrmi_openxr; case VR_SIDEBYSIDESQUISHED: case VR_COLUMNINTERLEAVED: @@ -289,7 +292,7 @@ VSMatrix VREyeInfo::GetHUDProjection(int width, int height) const new_projection.translate(-1.0, 1.0, 0); new_projection.scale(2.0 / width, -2.0 / height, -1.0); - VSMatrix proj = GetProjection(RazeXR_GetFOV(), ratio, fovratio); + VSMatrix proj = GetCenterProjection(RazeXR_GetFOV(), ratio, fovratio); proj.multMatrix(new_projection); new_projection = proj; @@ -361,7 +364,7 @@ VSMatrix VREyeInfo::GetPlayerSpriteProjection(int width, int height) const } new_projection.scale(2.0 / width, -2.0 / height, -1.0); - VSMatrix proj = GetProjection(RazeXR_GetFOV(), ratio, fovratio); + VSMatrix proj = GetCenterProjection(RazeXR_GetFOV(), ratio, fovratio); proj.multMatrix(new_projection); new_projection = proj; @@ -380,7 +383,14 @@ int VREyeInfo::getEye() const bool VR_GetVRProjection(int eye, float zNear, float zFar, float* projection); -VSMatrix VREyeInfo::GetProjection(float fov, float aspectRatio, float fovRatio) const +VSMatrix VREyeInfo::GetStereoProjection(float fov, float aspectRatio, float fovRatio) const +{ + VSMatrix projection = GetCenterProjection(fov, aspectRatio, fovRatio); + projection.translate(getStereoSeparation(1.0f), 0, 0); + return projection; +} + +VSMatrix VREyeInfo::GetCenterProjection(float fov, float aspectRatio, float fovRatio) const { VSMatrix result; @@ -422,6 +432,7 @@ VSMatrix VREyeInfo::GetProjection(float fov, float aspectRatio, float fovRatio) /* virtual */ DVector3 VREyeInfo::GetViewShift(FRotator viewAngles) const { + if (mShiftFactor == 0) { // pass-through for Mono view @@ -430,19 +441,18 @@ DVector3 VREyeInfo::GetViewShift(FRotator viewAngles) const else { vec3_t angles; - VectorSet(angles, viewAngles.Pitch.Degrees(), viewAngles.Yaw.Degrees(), viewAngles.Roll.Degrees()); + VectorSet(angles, viewAngles.Pitch.Degrees(), viewAngles.Yaw.Degrees(), + viewAngles.Roll.Degrees()); vec3_t v_forward, v_right, v_up; AngleVectors(angles, v_forward, v_right, v_up); - vec3_t tmp; - VectorScale(v_right, getShift(), tmp); - - float posforward=0; - float posside=0; - float dummy=0; + float posforward = 0; + float posside = 0; + float dummy = 0; VR_GetMove(&dummy, &dummy, &posforward, &posside, &dummy, &dummy, &dummy, &dummy); - DVector3 eyeOffset(tmp[0], tmp[1], tmp[2]); + DVector3 eyeOffset; + eyeOffset.Zero(); if (vr_positional_tracking) { diff --git a/source/common/rendering/hwrenderer/data/hw_vrmodes.h b/source/common/rendering/hwrenderer/data/hw_vrmodes.h index d62be8750..17329f9e9 100644 --- a/source/common/rendering/hwrenderer/data/hw_vrmodes.h +++ b/source/common/rendering/hwrenderer/data/hw_vrmodes.h @@ -28,7 +28,8 @@ struct VREyeInfo float mShiftFactor; float mScaleFactor; - VSMatrix GetProjection(float fov, float aspectRatio, float fovRatio) const; + VSMatrix GetCenterProjection(float fov, float aspectRatio, float fovRatio) const; + VSMatrix GetStereoProjection(float fov, float aspectRatio, float fovRatio) const; DVector3 GetViewShift(FRotator angles) const; VSMatrix GetHUDProjection(int width, int height) const; VSMatrix GetPlayerSpriteProjection(int width, int height) const; diff --git a/source/core/rendering/hw_entrypoint.cpp b/source/core/rendering/hw_entrypoint.cpp index 072ebd668..60b83bbcf 100644 --- a/source/core/rendering/hw_entrypoint.cpp +++ b/source/core/rendering/hw_entrypoint.cpp @@ -169,8 +169,8 @@ void RenderViewpoint(FRenderViewpoint& mainvp, IntRect* bounds, float fov, float di->Viewpoint.FieldOfView = FAngle::fromDeg(fov); // Set the real FOV for the current scene (it's not necessarily the same as the global setting in r_viewpoint) // Stereo mode specific perspective projection - di->VPUniforms.mProjectionMatrixLeft = vrmode->mEyes[0].GetProjection(fov, ratio, fovratio); - di->VPUniforms.mProjectionMatrixRight = vrmode->mEyes[1].GetProjection(fov, ratio, fovratio); + di->VPUniforms.mProjectionMatrix[0] = vrmode->mEyes[0].GetStereoProjection(fov, ratio, fovratio); + di->VPUniforms.mProjectionMatrix[1] = vrmode->mEyes[1].GetStereoProjection(fov, ratio, fovratio); // Stereo mode specific viewpoint adjustment diff --git a/source/core/rendering/scene/hw_drawinfo.cpp b/source/core/rendering/scene/hw_drawinfo.cpp index 263c227ae..88d66264a 100644 --- a/source/core/rendering/scene/hw_drawinfo.cpp +++ b/source/core/rendering/scene/hw_drawinfo.cpp @@ -138,8 +138,8 @@ void HWDrawInfo::StartScene(FRenderViewpoint& parentvp, HWViewpointUniforms* uni } else { - VPUniforms.mProjectionMatrixLeft.loadIdentity(); - VPUniforms.mProjectionMatrixRight.loadIdentity(); + VPUniforms.mProjectionMatrix[0].loadIdentity(); + VPUniforms.mProjectionMatrix[1].loadIdentity(); VPUniforms.mViewMatrix.loadIdentity(); VPUniforms.mNormalViewMatrix.loadIdentity(); //VPUniforms.mViewHeight = viewheight; @@ -731,19 +731,29 @@ void HWDrawInfo::DrawScene(int drawmode, bool portal) if (!gl_no_skyclear) portalState.RenderFirstSkyPortal(recursion, this, RenderState); +#ifndef __MOBILE__ + //The original location of this call RenderScene(RenderState); - if (false)//applySSAO && RenderState.GetPassType() == GBUFFER_PASS) + if (applySSAO && RenderState.GetPassType() == GBUFFER_PASS) { - //screen->AmbientOccludeScene(VPUniforms.mProjectionMatrix[0].get()[5]); - //screen->mViewpoints->Bind(RenderState, vpIndex); + screen->AmbientOccludeScene(VPUniforms.mProjectionMatrix[0].get()[5]); + screen->mViewpoints->Bind(RenderState, vpIndex); } +#endif // Handle all portals after rendering the opaque objects but before // doing all translucent stuff recursion++; portalState.EndFrame(this, RenderState); recursion--; + +#ifdef __MOBILE__ + //For some reason, doing this here this fixes the issue with portals being drawn out of order sometimes when using + // Direct to eye buffer rendering for multiview + RenderScene(RenderState); +#endif + RenderTranslucent(RenderState); } diff --git a/source/core/version.h b/source/core/version.h index 393c50afd..86626fdfe 100644 --- a/source/core/version.h +++ b/source/core/version.h @@ -44,7 +44,7 @@ const char *GetVersionString(); #define VERSIONSTR "1.7pre" -#define RAZEXR_VERSIONSTR "RazeXR 0.1.5" +#define RAZEXR_VERSIONSTR "RazeXR 0.2.0" // The version as seen in the Windows resource #define RC_FILEVERSION 1,6,9999,0