]> OCCT Git - occt.git/commitdiff
0031649: Visualization, TKOpenGL - broken skybox in VR output
authorkgv <kgv@opencascade.com>
Fri, 3 Jul 2020 16:48:57 +0000 (19:48 +0300)
committerbugmaster <bugmaster@opencascade.com>
Wed, 8 Jul 2020 12:53:32 +0000 (15:53 +0300)
OpenGl_ShaderManager::GetBgCubeMapProgram() and OpenGl_BackgroundArray::createCubeMapArray()
have been corrected to draw cube in straightforward way instead of a screen-quad.

Graphic3d_Camera::SetCustomStereoProjection() now recieves decomposed projection + head-to-eye matrices.
Added method Graphic3d_Camera::StereoProjection() returning projection matrix without translation part.
OpenGl_BackgroundArray::Render() now applies stereoscopic projection matrix in case of VR output,
but keeps using mono projection matrix in case of common 3D displays.

src/Graphic3d/Graphic3d_CView.cxx
src/Graphic3d/Graphic3d_Camera.cxx
src/Graphic3d/Graphic3d_Camera.hxx
src/OpenGl/OpenGl_BackgroundArray.cxx
src/OpenGl/OpenGl_BackgroundArray.hxx
src/OpenGl/OpenGl_ShaderManager.cxx
src/OpenGl/OpenGl_View.hxx
src/OpenGl/OpenGl_View_Redraw.cxx

index fa1005feb3010de73cc5a9ca8444b176c2536b09..27f71d4e1dff01d35f7cb8eede738496ca71efd4 100644 (file)
@@ -1225,7 +1225,7 @@ void Graphic3d_CView::ProcessXRInput()
     const Graphic3d_Mat4d aPoseR = myXRSession->HeadToEyeTransform (Aspect_Eye_Right);
     const Graphic3d_Mat4d aProjL = myXRSession->ProjectionMatrix (Aspect_Eye_Left,  myCamera->ZNear(), myCamera->ZFar());
     const Graphic3d_Mat4d aProjR = myXRSession->ProjectionMatrix (Aspect_Eye_Right, myCamera->ZNear(), myCamera->ZFar());
-    myCamera->SetCustomStereoProjection (aProjL * aPoseL, aProjR * aPoseR);
+    myCamera->SetCustomStereoProjection (aProjL, aPoseL, aProjR, aPoseR);
   }
   myBaseXRCamera = myCamera;
   if (myPosedXRCamera.IsNull())
index 12ef55d2a8dde08a206fa76b541c53979264632b..541a1006bb50fed90761a35a0132138a574a25b3 100644 (file)
@@ -152,7 +152,10 @@ void Graphic3d_Camera::CopyMappingData (const Handle(Graphic3d_Camera)& theOther
   ResetCustomProjection();
   if (theOtherCamera->IsCustomStereoProjection())
   {
-    SetCustomStereoProjection (theOtherCamera->myCustomProjMatL, theOtherCamera->myCustomProjMatR);
+    SetCustomStereoProjection (theOtherCamera->myCustomProjMatL,
+                               theOtherCamera->myCustomHeadToEyeMatL,
+                               theOtherCamera->myCustomProjMatR,
+                               theOtherCamera->myCustomHeadToEyeMatR);
   }
   else if (theOtherCamera->IsCustomStereoFrustum())
   {
@@ -930,6 +933,65 @@ void Graphic3d_Camera::ResetCustomProjection()
   }
 }
 
+// =======================================================================
+// function : StereoProjection
+// purpose  :
+// =======================================================================
+void Graphic3d_Camera::StereoProjection (Graphic3d_Mat4d& theProjL,
+                                         Graphic3d_Mat4d& theHeadToEyeL,
+                                         Graphic3d_Mat4d& theProjR,
+                                         Graphic3d_Mat4d& theHeadToEyeR) const
+{
+  stereoProjection (theProjL, theHeadToEyeL, theProjR, theHeadToEyeR);
+}
+
+// =======================================================================
+// function : StereoProjectionF
+// purpose  :
+// =======================================================================
+void Graphic3d_Camera::StereoProjectionF (Graphic3d_Mat4& theProjL,
+                                          Graphic3d_Mat4& theHeadToEyeL,
+                                          Graphic3d_Mat4& theProjR,
+                                          Graphic3d_Mat4& theHeadToEyeR) const
+{
+  stereoProjection (theProjL, theHeadToEyeL, theProjR, theHeadToEyeR);
+}
+
+// =======================================================================
+// function : stereoProjection
+// purpose  :
+// =======================================================================
+template <typename Elem_t>
+void Graphic3d_Camera::stereoProjection (NCollection_Mat4<Elem_t>& theProjL,
+                                         NCollection_Mat4<Elem_t>& theHeadToEyeL,
+                                         NCollection_Mat4<Elem_t>& theProjR,
+                                         NCollection_Mat4<Elem_t>& theHeadToEyeR) const
+{
+  if (myIsCustomProjMatLR)
+  {
+    theProjL     .ConvertFrom (myCustomProjMatL);
+    theHeadToEyeL.ConvertFrom (myCustomHeadToEyeMatL);
+    theProjR     .ConvertFrom (myCustomProjMatR);
+    theHeadToEyeR.ConvertFrom (myCustomHeadToEyeMatR);
+    return;
+  }
+
+  NCollection_Mat4<Elem_t> aDummy;
+  computeProjection (aDummy, theProjL, theProjR, false);
+
+  const Standard_Real aIOD = myIODType == IODType_Relative
+                           ? myIOD * Distance()
+                           : myIOD;
+  if (aIOD != 0.0)
+  {
+    // X translation to cancel parallax
+    theHeadToEyeL.InitIdentity();
+    theHeadToEyeL.SetColumn (3, NCollection_Vec3<Elem_t> (Elem_t ( 0.5 * aIOD), Elem_t (0.0), Elem_t (0.0)));
+    theHeadToEyeR.InitIdentity();
+    theHeadToEyeR.SetColumn (3, NCollection_Vec3<Elem_t> (Elem_t (-0.5 * aIOD), Elem_t (0.0), Elem_t (0.0)));
+  }
+}
+
 // =======================================================================
 // function : SetCustomStereoFrustums
 // purpose  :
@@ -949,10 +1011,14 @@ void Graphic3d_Camera::SetCustomStereoFrustums (const Aspect_FrustumLRBT<Standar
 // purpose  :
 // =======================================================================
 void Graphic3d_Camera::SetCustomStereoProjection (const Graphic3d_Mat4d& theProjL,
-                                                  const Graphic3d_Mat4d& theProjR)
+                                                  const Graphic3d_Mat4d& theHeadToEyeL,
+                                                  const Graphic3d_Mat4d& theProjR,
+                                                  const Graphic3d_Mat4d& theHeadToEyeR)
 {
   myCustomProjMatL = theProjL;
   myCustomProjMatR = theProjR;
+  myCustomHeadToEyeMatL = theHeadToEyeL;
+  myCustomHeadToEyeMatR = theHeadToEyeR;
   myIsCustomProjMatLR = true;
   myIsCustomFrustomLR = false;
   InvalidateProjection();
@@ -970,19 +1036,18 @@ void Graphic3d_Camera::SetCustomMonoProjection (const Graphic3d_Mat4d& theProj)
 }
 
 // =======================================================================
-// function : UpdateProjection
+// function : computeProjection
 // purpose  :
 // =======================================================================
 template <typename Elem_t>
-Graphic3d_Camera::TransformMatrices<Elem_t>&
-  Graphic3d_Camera::UpdateProjection (TransformMatrices<Elem_t>& theMatrices) const
+void Graphic3d_Camera::computeProjection (NCollection_Mat4<Elem_t>& theProjM,
+                                          NCollection_Mat4<Elem_t>& theProjL,
+                                          NCollection_Mat4<Elem_t>& theProjR,
+                                          bool theToAddHeadToEye) const
 {
-  if (theMatrices.IsProjectionValid())
-  {
-    return theMatrices; // for inline accessors
-  }
-
-  theMatrices.InitProjection();
+  theProjM.InitIdentity();
+  theProjL.InitIdentity();
+  theProjR.InitIdentity();
 
   // sets top of frustum based on FOVy and near clipping plane
   Elem_t aScale   = static_cast<Elem_t> (myScale);
@@ -1036,7 +1101,7 @@ Graphic3d_Camera::TransformMatrices<Elem_t>&
 
   if (myIsCustomProjMatM)
   {
-    theMatrices.MProjection.ConvertFrom (myCustomProjMatM);
+    theProjM.ConvertFrom (myCustomProjMatM);
   }
   switch (myProjType)
   {
@@ -1044,7 +1109,7 @@ Graphic3d_Camera::TransformMatrices<Elem_t>&
     {
       if (!myIsCustomProjMatM)
       {
-        orthoProj (theMatrices.MProjection, anLRBT, aZNear, aZFar);
+        orthoProj (theProjM, anLRBT, aZNear, aZFar);
       }
       break;
     }
@@ -1052,7 +1117,7 @@ Graphic3d_Camera::TransformMatrices<Elem_t>&
     {
       if (!myIsCustomProjMatM)
       {
-        perspectiveProj (theMatrices.MProjection, anLRBT, aZNear, aZFar);
+        perspectiveProj (theProjM, anLRBT, aZNear, aZFar);
       }
       break;
     }
@@ -1062,51 +1127,58 @@ Graphic3d_Camera::TransformMatrices<Elem_t>&
     {
       if (!myIsCustomProjMatM)
       {
-        perspectiveProj (theMatrices.MProjection, anLRBT, aZNear, aZFar);
+        perspectiveProj (theProjM, anLRBT, aZNear, aZFar);
       }
       if (myIsCustomProjMatLR)
       {
-        theMatrices.LProjection.ConvertFrom (myCustomProjMatL);
-        theMatrices.RProjection.ConvertFrom (myCustomProjMatR);
+        if (theToAddHeadToEye)
+        {
+          theProjL.ConvertFrom (myCustomProjMatL * myCustomHeadToEyeMatL);
+          theProjR.ConvertFrom (myCustomProjMatR * myCustomHeadToEyeMatR);
+        }
+        else
+        {
+          theProjL.ConvertFrom (myCustomProjMatL);
+          theProjR.ConvertFrom (myCustomProjMatR);
+        }
       }
       else if (myIsCustomFrustomLR)
       {
         anLRBT = Aspect_FrustumLRBT<Elem_t> (myCustomFrustumL).Multiplied (aZNear);
-        perspectiveProj (theMatrices.LProjection, anLRBT, aZNear, aZFar);
-        if (aIOD != Elem_t (0.0))
-        {
-          theMatrices.LProjection.Translate (NCollection_Vec3<Elem_t> (Elem_t (0.5) * aIOD, Elem_t (0.0), Elem_t (0.0)));
-        }
+        perspectiveProj (theProjL, anLRBT, aZNear, aZFar);
 
         anLRBT = Aspect_FrustumLRBT<Elem_t> (myCustomFrustumR).Multiplied (aZNear);
-        perspectiveProj (theMatrices.RProjection, anLRBT, aZNear, aZFar);
-        if (aIOD != Elem_t (0.0))
-        {
-          theMatrices.RProjection.Translate (NCollection_Vec3<Elem_t> (Elem_t (-0.5) * aIOD, Elem_t (0.0), Elem_t (0.0)));
-        }
+        perspectiveProj (theProjR, anLRBT, aZNear, aZFar);
       }
       else
       {
-        stereoEyeProj (theMatrices.LProjection,
+        stereoEyeProj (theProjL,
                        anLRBT, aZNear, aZFar, aIOD, aFocus,
                        Aspect_Eye_Left);
-        stereoEyeProj (theMatrices.RProjection,
+        stereoEyeProj (theProjR,
                        anLRBT, aZNear, aZFar, aIOD, aFocus,
                        Aspect_Eye_Right);
       }
+
+      if (theToAddHeadToEye
+      && !myIsCustomProjMatLR
+      &&  aIOD != Elem_t (0.0))
+      {
+        // X translation to cancel parallax
+        theProjL.Translate (NCollection_Vec3<Elem_t> (Elem_t ( 0.5) * aIOD, Elem_t (0.0), Elem_t (0.0)));
+        theProjR.Translate (NCollection_Vec3<Elem_t> (Elem_t (-0.5) * aIOD, Elem_t (0.0), Elem_t (0.0)));
+      }
       break;
     }
   }
   if (myProjType == Projection_MonoLeftEye)
   {
-    theMatrices.MProjection = theMatrices.LProjection;
+    theProjM = theProjL;
   }
   else if (myProjType == Projection_MonoRightEye)
   {
-    theMatrices.MProjection = theMatrices.RProjection;
+    theProjM = theProjR;
   }
-
-  return theMatrices; // for inline accessors
 }
 
 // =======================================================================
@@ -1258,12 +1330,6 @@ void Graphic3d_Camera::stereoEyeProj (NCollection_Mat4<Elem_t>& theOutMx,
   aLRBT.Left  = theLRBT.Left  + aDXStereoShift;
   aLRBT.Right = theLRBT.Right + aDXStereoShift;
   perspectiveProj (theOutMx, aLRBT, theNear, theFar);
-
-  if (theIOD != Elem_t (0.0))
-  {
-    // X translation to cancel parallax
-    theOutMx.Translate (NCollection_Vec3<Elem_t> (aDx, Elem_t (0.0), Elem_t (0.0)));
-  }
 }
 
 // =======================================================================
index 42cb0ded21f5607fa8269f9bb6fbc2e0151e904d..8aee88ec6f52d5c26ab9b170ec21d0ffbaf51e68 100644 (file)
@@ -591,6 +591,26 @@ public:
 
 public:
 
+  //! Get stereo projection matrices.
+  //! @param theProjL      [out] left  eye projection matrix
+  //! @param theHeadToEyeL [out] left  head to eye translation matrix
+  //! @param theProjR      [out] right eye projection matrix
+  //! @param theHeadToEyeR [out] right head to eye translation matrix
+  Standard_EXPORT void StereoProjection (Graphic3d_Mat4d& theProjL,
+                                         Graphic3d_Mat4d& theHeadToEyeL,
+                                         Graphic3d_Mat4d& theProjR,
+                                         Graphic3d_Mat4d& theHeadToEyeR) const;
+
+  //! Get stereo projection matrices.
+  //! @param theProjL      [out] left  eye projection matrix
+  //! @param theHeadToEyeL [out] left  head to eye translation matrix
+  //! @param theProjR      [out] right eye projection matrix
+  //! @param theHeadToEyeR [out] right head to eye translation matrix
+  Standard_EXPORT void StereoProjectionF (Graphic3d_Mat4& theProjL,
+                                          Graphic3d_Mat4& theHeadToEyeL,
+                                          Graphic3d_Mat4& theProjR,
+                                          Graphic3d_Mat4& theHeadToEyeR) const;
+
   //! Unset all custom frustums and projection matrices.
   Standard_EXPORT void ResetCustomProjection();
 
@@ -606,8 +626,14 @@ public:
   bool IsCustomStereoProjection() const { return myIsCustomProjMatLR; }
 
   //! Set custom stereo projection matrices.
+  //! @param theProjL      [in] left  eye projection matrix
+  //! @param theHeadToEyeL [in] left  head to eye translation matrix
+  //! @param theProjR      [in] right eye projection matrix
+  //! @param theHeadToEyeR [in] right head to eye translation matrix
   Standard_EXPORT void SetCustomStereoProjection (const Graphic3d_Mat4d& theProjL,
-                                                  const Graphic3d_Mat4d& theProjR);
+                                                  const Graphic3d_Mat4d& theHeadToEyeL,
+                                                  const Graphic3d_Mat4d& theProjR,
+                                                  const Graphic3d_Mat4d& theHeadToEyeR);
 
   //! Return TRUE if custom projection matrix is set.
   bool IsCustomMonoProjection() const { return myIsCustomProjMatM; }
@@ -621,11 +647,40 @@ public:
 //! @name Managing projection and orientation cache
 private:
 
+  //! Get stereo projection matrices.
+  //! @param theProjL      [out] left  eye projection matrix
+  //! @param theHeadToEyeL [out] left  head to eye translation matrix
+  //! @param theProjR      [out] right eye projection matrix
+  //! @param theHeadToEyeR [out] right head to eye translation matrix
+  template <typename Elem_t>
+  Standard_EXPORT void stereoProjection (NCollection_Mat4<Elem_t>& theProjL,
+                                         NCollection_Mat4<Elem_t>& theHeadToEyeL,
+                                         NCollection_Mat4<Elem_t>& theProjR,
+                                         NCollection_Mat4<Elem_t>& theHeadToEyeR) const;
+
+  //! Compute projection matrices.
+  //! @param theProjM [out] mono projection matrix
+  //! @param theProjL [out] left  eye projection matrix
+  //! @param theProjR [out] right eye projection matrix
+  //! @param theToAddHeadToEye [in] flag to pre-multiply head-to-eye translation
+  template <typename Elem_t>
+  Standard_EXPORT void computeProjection (NCollection_Mat4<Elem_t>& theProjM,
+                                          NCollection_Mat4<Elem_t>& theProjL,
+                                          NCollection_Mat4<Elem_t>& theProjR,
+                                          bool theToAddHeadToEye) const;
+
   //! Compute projection matrices.
   //! @param theMatrices [in] the matrices data container.
   template <typename Elem_t>
-  Standard_EXPORT
-    TransformMatrices<Elem_t>& UpdateProjection (TransformMatrices<Elem_t>& theMatrices) const;
+  TransformMatrices<Elem_t>& UpdateProjection (TransformMatrices<Elem_t>& theMatrices) const
+  {
+    if (!theMatrices.IsProjectionValid())
+    {
+      theMatrices.InitProjection();
+      computeProjection (theMatrices.MProjection, theMatrices.LProjection, theMatrices.RProjection, true);
+    }
+    return theMatrices;
+  }
 
   //! Compute orientation matrix.
   //! @param theMatrices [in] the matrices data container.
@@ -742,6 +797,8 @@ private:
   Graphic3d_Mat4d  myCustomProjMatM;
   Graphic3d_Mat4d  myCustomProjMatL;
   Graphic3d_Mat4d  myCustomProjMatR;
+  Graphic3d_Mat4d  myCustomHeadToEyeMatL;
+  Graphic3d_Mat4d  myCustomHeadToEyeMatR;
   Aspect_FrustumLRBT<Standard_Real> myCustomFrustumL; //!< left  custom frustum
   Aspect_FrustumLRBT<Standard_Real> myCustomFrustumR; //!< right custom frustum
   Standard_Boolean myIsCustomProjMatM;  //!< flag indicating usage of custom projection matrix
index 9d9700a897cc4272f1e91ea4ffde903be9123155..3bde2f9d1505a83b19a5be14f94d661e8597a9df 100644 (file)
@@ -27,7 +27,6 @@
 // =======================================================================
 OpenGl_BackgroundArray::OpenGl_BackgroundArray (const Graphic3d_TypeOfBackground theType)
 : OpenGl_PrimitiveArray (NULL, Graphic3d_TOPA_TRIANGLESTRIPS, NULL, NULL, NULL),
-  myTrsfPers (Graphic3d_TMF_2d, theType == Graphic3d_TOB_TEXTURE ? Aspect_TOTP_CENTER : Aspect_TOTP_LEFT_LOWER),
   myType (theType),
   myFillMethod (Aspect_FM_NONE),
   myViewWidth (0),
@@ -399,26 +398,40 @@ Standard_Boolean OpenGl_BackgroundArray::createTextureArray (const Handle(OpenGl
 // =======================================================================
 Standard_Boolean OpenGl_BackgroundArray::createCubeMapArray() const
 {
-  Graphic3d_Attribute aCubeMapAttribInfo[] =
+  const Graphic3d_Attribute aCubeMapAttribInfo[] =
   {
-    { Graphic3d_TOA_POS, Graphic3d_TOD_VEC2}
+    { Graphic3d_TOA_POS, Graphic3d_TOD_VEC}
   };
 
   if (myAttribs.IsNull())
   {
     Handle(NCollection_AlignedAllocator) anAlloc = new NCollection_AlignedAllocator (16);
     myAttribs = new Graphic3d_Buffer (anAlloc);
+    myIndices = new Graphic3d_IndexBuffer (anAlloc);
   }
-  if (!myAttribs->Init(4, aCubeMapAttribInfo, 1))
+  if (!myAttribs->Init (8, aCubeMapAttribInfo, 1)
+   || !myIndices->Init<unsigned short> (14))
   {
     return Standard_False;
   }
 
-  OpenGl_Vec2* aData = reinterpret_cast<OpenGl_Vec2*>(myAttribs->changeValue(0));
-
-  for (unsigned int i = 0; i < 4; ++i)
   {
-    aData[i] = (OpenGl_Vec2(Standard_ShortReal(i / 2), Standard_ShortReal(i % 2)) - OpenGl_Vec2(0.5f)) * 2.f;
+    OpenGl_Vec3* aData = reinterpret_cast<OpenGl_Vec3*>(myAttribs->changeValue(0));
+    aData[0].SetValues (-1.0, -1.0,  1.0);
+    aData[1].SetValues ( 1.0, -1.0,  1.0);
+    aData[2].SetValues (-1.0,  1.0,  1.0);
+    aData[3].SetValues ( 1.0,  1.0,  1.0);
+    aData[4].SetValues (-1.0, -1.0, -1.0);
+    aData[5].SetValues ( 1.0, -1.0, -1.0);
+    aData[6].SetValues (-1.0,  1.0, -1.0);
+    aData[7].SetValues ( 1.0,  1.0, -1.0);
+  }
+  {
+    const unsigned short THE_BOX_TRISTRIP[14] = { 0, 1, 2, 3, 7, 1, 5, 4, 7, 6, 2, 4, 0, 1 };
+    for (unsigned int aVertIter = 0; aVertIter < 14; ++aVertIter)
+    {
+      myIndices->SetIndex (aVertIter, THE_BOX_TRISTRIP[aVertIter]);
+    }
   }
 
   return Standard_True;
@@ -428,7 +441,8 @@ Standard_Boolean OpenGl_BackgroundArray::createCubeMapArray() const
 // method  : Render
 // purpose :
 // =======================================================================
-void OpenGl_BackgroundArray::Render (const Handle(OpenGl_Workspace)& theWorkspace) const
+void OpenGl_BackgroundArray::Render (const Handle(OpenGl_Workspace)& theWorkspace,
+                                     Graphic3d_Camera::Projection theProjection) const
 {
   const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext();
   Standard_Integer aViewSizeX = aCtx->Viewport()[2];
@@ -457,7 +471,46 @@ void OpenGl_BackgroundArray::Render (const Handle(OpenGl_Workspace)& theWorkspac
   OpenGl_Mat4 aProjection = aCtx->ProjectionState.Current();
   OpenGl_Mat4 aWorldView  = aCtx->WorldViewState.Current();
 
-  if (myType != Graphic3d_TOB_CUBEMAP)
+  if (myType == Graphic3d_TOB_CUBEMAP)
+  {
+    Graphic3d_Camera aCamera (theWorkspace->View()->Camera());
+    aCamera.SetZRange (0.01, 1.0); // is needed to avoid perspective camera exception
+
+    // cancel translation
+    aCamera.MoveEyeTo (gp_Pnt (0.0, 0.0, 0.0));
+
+    // Handle projection matrix:
+    // - Cancel any head-to-eye translation for HMD display;
+    // - Ignore stereoscopic projection in case of non-HMD 3D display
+    //   (ideally, we would need a stereoscopic cubemap image; adding a parallax makes no sense);
+    // - Force perspective projection when orthographic camera is active
+    //   (orthographic projection makes no sense for cubemap).
+    const bool isCustomProj = aCamera.IsCustomStereoFrustum()
+                           || aCamera.IsCustomStereoProjection();
+    aCamera.SetProjectionType (theProjection == Graphic3d_Camera::Projection_Orthographic || !isCustomProj
+                             ? Graphic3d_Camera::Projection_Perspective
+                             : theProjection);
+
+    aProjection = aCamera.ProjectionMatrixF();
+    aWorldView = aCamera.OrientationMatrixF();
+    if (isCustomProj)
+    {
+      // get projection matrix without pre-multiplied stereoscopic head-to-eye translation
+      if (theProjection == Graphic3d_Camera::Projection_MonoLeftEye)
+      {
+        Graphic3d_Mat4 aMatProjL, aMatHeadToEyeL, aMatProjR, aMatHeadToEyeR;
+        aCamera.StereoProjectionF (aMatProjL, aMatHeadToEyeL, aMatProjR, aMatHeadToEyeR);
+        aProjection = aMatProjL;
+      }
+      else if (theProjection == Graphic3d_Camera::Projection_MonoRightEye)
+      {
+        Graphic3d_Mat4 aMatProjL, aMatHeadToEyeL, aMatProjR, aMatHeadToEyeR;
+        aCamera.StereoProjectionF (aMatProjL, aMatHeadToEyeL, aMatProjR, aMatHeadToEyeR);
+        aProjection = aMatProjR;
+      }
+    }
+  }
+  else
   {
     aProjection.InitIdentity();
     aWorldView.InitIdentity();
index c662ebfc9cb4086f75e005d836ecaaf75ebcced9..795f4aa05ca2ca93c518ce6d13c0d1d47ba7e64b 100644 (file)
@@ -34,7 +34,8 @@ public:
   Standard_EXPORT OpenGl_BackgroundArray (const Graphic3d_TypeOfBackground theType);
 
   //! Render primitives to the window
-  Standard_EXPORT virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const Standard_OVERRIDE;
+  Standard_EXPORT void Render (const Handle(OpenGl_Workspace)& theWorkspace,
+                               Graphic3d_Camera::Projection theProjection) const;
 
   //! Check if background parameters are set properly
   Standard_EXPORT bool IsDefined() const;
@@ -92,9 +93,10 @@ protected:
   //! on next rendering stage array data is to be updated.
   Standard_EXPORT void invalidateData();
 
+  using OpenGl_PrimitiveArray::Render;
+
 protected:
 
-  Graphic3d_TransformPers           myTrsfPers;       //!< transformation persistence
   Graphic3d_TypeOfBackground        myType;           //!< Type of background: texture or gradient.
   Aspect_FillMethod                 myFillMethod;     //!< Texture parameters
   mutable OpenGl_GradientParameters myGradientParams; //!< Gradient parameters
index 06e352b1be5af906c8a5fd90667140628189b756..3c8f75f89b436827749c07ace70ff178a3839ce6 100644 (file)
@@ -3161,12 +3161,9 @@ const Handle(Graphic3d_ShaderProgram)& OpenGl_ShaderManager::GetBgCubeMapProgram
     + THE_FUNC_cubemap_vector_transform
     + EOL"void main()"
       EOL"{"
-      EOL"  vec4 aViewDirection = occProjectionMatrixInverse * vec4(occVertex.xy, 0.0, 1.0);"
-      EOL"  aViewDirection /= aViewDirection.w;"
-      EOL"  aViewDirection.w = 0.0;"
-      EOL"  ViewDirection = normalize((occWorldViewMatrixInverse * aViewDirection).xyz);"
-      EOL"  ViewDirection = cubemapVectorTransform (ViewDirection, uYCoeff, uZCoeff);"
-      EOL"  gl_Position = vec4(occVertex.xy, 0.0, 1.0);"
+      EOL"  ViewDirection = cubemapVectorTransform (occVertex.xyz, uYCoeff, uZCoeff);"
+      EOL"  vec4 aPos = occProjectionMatrix * occWorldViewMatrix * vec4(occVertex.xyz, 1.0);"
+      EOL"  gl_Position = aPos.xyww;"
       EOL"}";
 
     TCollection_AsciiString aSrcFrag =
index 99b1686a703ecfdd51fdad58a467831b31f899de..79426a7b12502ac3f659449aacfaf2657890bab7 100644 (file)
@@ -409,7 +409,8 @@ protected: //! @name Rendering of GL graphics (with prepared drawing buffer).
                                             const Standard_Boolean theToDrawImmediate);
 
   //! Draw background (gradient / image)
-  Standard_EXPORT virtual void drawBackground (const Handle(OpenGl_Workspace)& theWorkspace);
+  Standard_EXPORT virtual void drawBackground (const Handle(OpenGl_Workspace)& theWorkspace,
+                                               Graphic3d_Camera::Projection theProjection);
 
   //! Render set of structures presented in the view.
   //! @param theProjection [in] the projection that is used for rendering.
index 7fd8d7eb1939fc9e3a8868211d44f1511b6801dc..bbe25aa22338bd7fb3dffd40c8b6a42e6a4722d1 100644 (file)
@@ -74,7 +74,8 @@ namespace
 //function : drawBackground
 //purpose  :
 //=======================================================================
-void OpenGl_View::drawBackground (const Handle(OpenGl_Workspace)& theWorkspace)
+void OpenGl_View::drawBackground (const Handle(OpenGl_Workspace)& theWorkspace,
+                                  Graphic3d_Camera::Projection theProjection)
 {
   const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext();
   const Standard_Boolean wasUsedZBuffer = theWorkspace->SetUseZBuffer (Standard_False);
@@ -85,21 +86,12 @@ void OpenGl_View::drawBackground (const Handle(OpenGl_Workspace)& theWorkspace)
 
   if (myBackgroundType == Graphic3d_TOB_CUBEMAP)
   {
-    Graphic3d_Camera aCamera (theWorkspace->View()->Camera());
-    aCamera.SetZRange (0.01, 1.0); // is needed to avoid perspective camera exception
-    aCamera.SetProjectionType (Graphic3d_Camera::Projection_Perspective);
-
-    aCtx->ProjectionState.Push();
-    aCtx->ProjectionState.SetCurrent (aCamera.ProjectionMatrixF());
-
     myCubeMapParams->Aspect()->ShaderProgram()->PushVariableInt ("uZCoeff", myBackgroundCubeMap->ZIsInverted() ? -1 : 1);
     myCubeMapParams->Aspect()->ShaderProgram()->PushVariableInt ("uYCoeff", myBackgroundCubeMap->IsTopDown() ? 1 : -1);
     const OpenGl_Aspects* anOldAspectFace = theWorkspace->SetAspects (myCubeMapParams);
 
-    myBackgrounds[Graphic3d_TOB_CUBEMAP]->Render (theWorkspace);
+    myBackgrounds[Graphic3d_TOB_CUBEMAP]->Render (theWorkspace, theProjection);
 
-    aCtx->ProjectionState.Pop();
-    aCtx->ApplyProjectionMatrix();
     theWorkspace->SetAspects (anOldAspectFace);
   }
   else if (myBackgroundType == Graphic3d_TOB_GRADIENT
@@ -113,7 +105,7 @@ void OpenGl_View::drawBackground (const Handle(OpenGl_Workspace)& theWorkspace)
         || myBackgrounds[Graphic3d_TOB_TEXTURE]->TextureFillMethod() == Aspect_FM_CENTERED
         || myBackgrounds[Graphic3d_TOB_TEXTURE]->TextureFillMethod() == Aspect_FM_NONE))
     {
-      myBackgrounds[Graphic3d_TOB_GRADIENT]->Render(theWorkspace);
+      myBackgrounds[Graphic3d_TOB_GRADIENT]->Render(theWorkspace, theProjection);
     }
 
     // Drawing background image if it is defined
@@ -124,7 +116,7 @@ void OpenGl_View::drawBackground (const Handle(OpenGl_Workspace)& theWorkspace)
       aCtx->core11fwd->glDisable (GL_BLEND);
 
       const OpenGl_Aspects* anOldAspectFace = theWorkspace->SetAspects (myTextureParams);
-      myBackgrounds[Graphic3d_TOB_TEXTURE]->Render (theWorkspace);
+      myBackgrounds[Graphic3d_TOB_TEXTURE]->Render (theWorkspace, theProjection);
       theWorkspace->SetAspects (anOldAspectFace);
     }
   }
@@ -1097,7 +1089,7 @@ void OpenGl_View::render (Graphic3d_Camera::Projection theProjection,
   // Render background
   if (!theToDrawImmediate)
   {
-    drawBackground (myWorkspace);
+    drawBackground (myWorkspace, theProjection);
   }
 
 #if !defined(GL_ES_VERSION_2_0)