0026617: Visualization, Ray Tracing - adopt progressive rendering Path Tracing for...
authorapl <apl@opencascade.com>
Tue, 20 Oct 2015 09:59:56 +0000 (12:59 +0300)
committerbugmaster <bugmaster@opencascade.com>
Thu, 22 Oct 2015 08:00:08 +0000 (11:00 +0300)
- Use two different FBOs for accumulating frames for left/right eye projection.
- Added equality checks to camera modification methods to avoid camera updates when performing identity operations.

src/Graphic3d/Graphic3d_Camera.cxx
src/OpenGl/OpenGl_FrameBuffer.cxx
src/OpenGl/OpenGl_View.hxx
src/OpenGl/OpenGl_View_Raytrace.cxx
src/OpenGl/OpenGl_View_Redraw.cxx
src/V3d/V3d_View.cxx
src/ViewerTest/ViewerTest_ViewerCommands.cxx
tests/v3d/end
tests/v3d/raytrace/begin
tests/v3d/raytrace/bug26617 [new file with mode: 0644]

index 2443cab72b51b7456948c27df1d8caff6025c724..a4689ccb6455d765c9ea8e9eac6808f6fbc96c0f 100644 (file)
@@ -103,20 +103,13 @@ Graphic3d_Camera::Graphic3d_Camera (const Handle(Graphic3d_Camera)& theOther)
 // =======================================================================
 void Graphic3d_Camera::CopyMappingData (const Handle(Graphic3d_Camera)& theOtherCamera)
 {
-  myFOVy       = theOtherCamera->myFOVy;
-  myZNear      = theOtherCamera->myZNear;
-  myZFar       = theOtherCamera->myZFar;
-  myAspect     = theOtherCamera->myAspect;
-  myScale      = theOtherCamera->myScale;
-  myZFocus     = theOtherCamera->myZFocus;
-  myZFocusType = theOtherCamera->myZFocusType;
-  myIOD        = theOtherCamera->myIOD;
-  myIODType    = theOtherCamera->myIODType;
-  myProjType   = theOtherCamera->myProjType;
-
-  myWorldViewProjState.ProjectionState() = theOtherCamera->ProjectionState();
-
-  InvalidateProjection();
+  SetFOVy           (theOtherCamera->FOVy());
+  SetZRange         (theOtherCamera->ZNear(), theOtherCamera->ZFar());
+  SetAspect         (theOtherCamera->Aspect());
+  SetScale          (theOtherCamera->Scale());
+  SetZFocus         (theOtherCamera->ZFocusType(), theOtherCamera->ZFocus());
+  SetIOD            (theOtherCamera->GetIODType(), theOtherCamera->IOD());
+  SetProjectionType (theOtherCamera->ProjectionType());
 }
 
 // =======================================================================
@@ -125,14 +118,10 @@ void Graphic3d_Camera::CopyMappingData (const Handle(Graphic3d_Camera)& theOther
 // =======================================================================
 void Graphic3d_Camera::CopyOrientationData (const Handle(Graphic3d_Camera)& theOtherCamera)
 {
-  myUp         = theOtherCamera->myUp;
-  myEye        = theOtherCamera->myEye;
-  myCenter     = theOtherCamera->myCenter;
-  myAxialScale = theOtherCamera->myAxialScale;
-
-  myWorldViewProjState.WorldViewState() = theOtherCamera->WorldViewState();
-
-  InvalidateOrientation();
+  SetUp         (theOtherCamera->Up());
+  SetEye        (theOtherCamera->Eye());
+  SetCenter     (theOtherCamera->Center());
+  SetAxialScale (theOtherCamera->AxialScale());
 }
 
 // =======================================================================
@@ -151,6 +140,11 @@ void Graphic3d_Camera::Copy (const Handle(Graphic3d_Camera)& theOther)
 // =======================================================================
 void Graphic3d_Camera::SetEye (const gp_Pnt& theEye)
 {
+  if (Eye().IsEqual (theEye, 0.0))
+  {
+    return;
+  }
+
   myEye = theEye;
   InvalidateOrientation();
 }
@@ -161,6 +155,11 @@ void Graphic3d_Camera::SetEye (const gp_Pnt& theEye)
 // =======================================================================
 void Graphic3d_Camera::SetCenter (const gp_Pnt& theCenter)
 {
+  if (Center().IsEqual (theCenter, 0.0))
+  {
+    return;
+  }
+
   myCenter = theCenter;
   InvalidateOrientation();
 }
@@ -171,6 +170,11 @@ void Graphic3d_Camera::SetCenter (const gp_Pnt& theCenter)
 // =======================================================================
 void Graphic3d_Camera::SetUp (const gp_Dir& theUp)
 {
+  if (Up().IsEqual (theUp, 0.0))
+  {
+    return;
+  }
+
   myUp = theUp;
   InvalidateOrientation();
 }
@@ -181,6 +185,11 @@ void Graphic3d_Camera::SetUp (const gp_Dir& theUp)
 // =======================================================================
 void Graphic3d_Camera::SetAxialScale (const gp_XYZ& theAxialScale)
 {
+  if (AxialScale().IsEqual (theAxialScale, 0.0))
+  {
+    return;
+  }
+
   myAxialScale = theAxialScale;
   InvalidateOrientation();
 }
@@ -191,6 +200,11 @@ void Graphic3d_Camera::SetAxialScale (const gp_XYZ& theAxialScale)
 // =======================================================================
 void Graphic3d_Camera::SetDistance (const Standard_Real theDistance)
 {
+  if (Distance() == theDistance)
+  {
+    return;
+  }
+
   gp_Vec aCenter2Eye (Direction());
   aCenter2Eye.Reverse();
 
@@ -214,6 +228,11 @@ Standard_Real Graphic3d_Camera::Distance() const
 // =======================================================================
 void Graphic3d_Camera::SetDirection (const gp_Dir& theDir)
 {
+  if (Direction().IsEqual (theDir, 0.0))
+  {
+    return;
+  }
+
   gp_Vec aScaledDir (theDir);
   aScaledDir.Scale (Distance());
   aScaledDir.Reverse();
@@ -392,8 +411,8 @@ void Graphic3d_Camera::SetZFocus(const FocusType theType, const Standard_Real th
 // =======================================================================
 void Graphic3d_Camera::SetIOD (const IODType theType, const Standard_Real theIOD)
 {
-  if (IODType() == theType
-   && IOD    () == theIOD)
+  if (GetIODType() == theType
+   && IOD       () == theIOD)
   {
     return;
   }
@@ -432,10 +451,14 @@ gp_Dir Graphic3d_Camera::OrthogonalizedUp() const
 // =======================================================================
 void Graphic3d_Camera::Transform (const gp_Trsf& theTrsf)
 {
-  myUp.Transform (theTrsf);
-  myEye.Transform (theTrsf);
-  myCenter.Transform (theTrsf);
-  InvalidateOrientation();
+  if (theTrsf.Form() == gp_Identity)
+  {
+    return;
+  }
+
+  SetUp     (myUp.Transformed (theTrsf));
+  SetEye    (myEye.Transformed (theTrsf));
+  SetCenter (myCenter.Transformed (theTrsf));
 }
 
 // =======================================================================
index 60dc24344c46a9abbe3a8faa199bc47b8887df50..38cb43fd060ec3f4ecf4a5936fee9b5a2b26e673 100644 (file)
@@ -322,6 +322,9 @@ void OpenGl_FrameBuffer::Release (OpenGl_Context* theGlCtx)
 
   myColorTexture->Release (theGlCtx);
   myDepthStencilTexture->Release (theGlCtx);
+
+  myVPSizeX = 0;
+  myVPSizeY = 0;
 }
 
 // =======================================================================
index 864a5125047237af00fa182cf837fe287d0ea90a..2f0123b4ddb17c3ed8d44f8a214505f375289236 100644 (file)
@@ -505,18 +505,22 @@ protected: //! @name Rendering of GL graphics (with prepared drawing buffer).
                                        const Standard_Boolean       theToDrawImmediate);
 
   //! Renders the graphical scene.
+  //! @param theProjection [in] the projection that is used for rendering.
   //! @param theReadDrawFbo [in] the framebuffer for rendering graphics.
   //! @param theToDrawImmediate [in] the flag indicates whether the rendering performs in immediate mode.
-  Standard_EXPORT virtual void renderScene (OpenGl_FrameBuffer*    theReadDrawFbo,
+  Standard_EXPORT virtual void renderScene (Graphic3d_Camera::Projection theProjection,
+                                            OpenGl_FrameBuffer*    theReadDrawFbo,
                                             const Standard_Boolean theToDrawImmediate);
 
   //! Draw background (gradient / image)
   Standard_EXPORT virtual void drawBackground (const Handle(OpenGl_Workspace)& theWorkspace);
 
   //! Render set of structures presented in the view.
+  //! @param theProjection [in] the projection that is used for rendering.
   //! @param theReadDrawFbo [in] the framebuffer for rendering graphics.
   //! @param theToDrawImmediate [in] the flag indicates whether the rendering performs in immediate mode.
-  Standard_EXPORT virtual void renderStructs (OpenGl_FrameBuffer*    theReadDrawFbo,
+  Standard_EXPORT virtual void renderStructs (Graphic3d_Camera::Projection theProjection,
+                                              OpenGl_FrameBuffer*    theReadDrawFbo,
                                               const Standard_Boolean theToDrawImmediate);
 
   //! Renders trihedron.
@@ -927,8 +931,8 @@ protected: //! @name methods related to ray-tracing
   //! Releases OpenGL/GLSL shader programs.
   void releaseRaytraceResources (const Handle(OpenGl_Context)& theGlContext);
 
-  //! Resizes OpenGL frame buffers.
-  Standard_Boolean resizeRaytraceBuffers (const Standard_Integer        theSizeX,
+  //! Updates auxiliary OpenGL frame buffers.
+  Standard_Boolean updateRaytraceBuffers (const Standard_Integer        theSizeX,
                                           const Standard_Integer        theSizeY,
                                           const Handle(OpenGl_Context)& theGlContext);
 
@@ -958,12 +962,14 @@ protected: //! @name methods related to ray-tracing
                                        const OpenGl_Vec3*            theOrigins,
                                        const OpenGl_Vec3*            theDirects,
                                        const OpenGl_Mat4&            theUnviewMat,
+                                       Graphic3d_Camera::Projection  theProjection,
                                        OpenGl_FrameBuffer*           theReadDrawFbo,
                                        const Handle(OpenGl_Context)& theGlContext);
 
   //! Redraws the window using OpenGL/GLSL ray-tracing.
   Standard_Boolean raytrace (const Standard_Integer        theSizeX,
                              const Standard_Integer        theSizeY,
+                             Graphic3d_Camera::Projection  theProjection,
                              OpenGl_FrameBuffer*           theReadDrawFbo,
                              const Handle(OpenGl_Context)& theGlContext);
 
@@ -1030,9 +1036,9 @@ protected: //! @name fields related to ray-tracing
   Handle(OpenGl_TextureBufferArb) myRaytraceLightSrcTexture;
 
   //! 1st framebuffer (FBO) to perform adaptive FSAA.
-  Handle(OpenGl_FrameBuffer) myRaytraceFBO1;
+  Handle(OpenGl_FrameBuffer) myRaytraceFBO1[2];
   //! 2nd framebuffer (FBO) to perform adaptive FSAA.
-  Handle(OpenGl_FrameBuffer) myRaytraceFBO2;
+  Handle(OpenGl_FrameBuffer) myRaytraceFBO2[2];
   //! Framebuffer (FBO) for preliminary OpenGL output.
   Handle(OpenGl_FrameBuffer) myOpenGlFBO;
 
index 653e2c263cd0c9d0bbee93104177f4dd7c8bf167..27e9b007c140708353f6d00512f61c36148baab7 100644 (file)
@@ -1586,14 +1586,16 @@ Standard_Boolean OpenGl_View::initRaytraceResources (const Handle(OpenGl_Context
     return myRaytraceInitStatus == OpenGl_RT_INIT;
   }
 
-  if (myRaytraceFBO1.IsNull())
+  if (myRaytraceFBO1[0].IsNull())
   {
-    myRaytraceFBO1 = new OpenGl_FrameBuffer (GL_RGBA32F);
+    myRaytraceFBO1[0] = new OpenGl_FrameBuffer (GL_RGBA32F);
+    myRaytraceFBO1[1] = new OpenGl_FrameBuffer (GL_RGBA32F);
   }
 
-  if (myRaytraceFBO2.IsNull())
+  if (myRaytraceFBO2[0].IsNull())
   {
-    myRaytraceFBO2 = new OpenGl_FrameBuffer (GL_RGBA32F);
+    myRaytraceFBO2[0] = new OpenGl_FrameBuffer (GL_RGBA32F);
+    myRaytraceFBO2[1] = new OpenGl_FrameBuffer (GL_RGBA32F);
   }
 
   const GLfloat aVertices[] = { -1.f, -1.f,  0.f,
@@ -1631,8 +1633,10 @@ inline void nullifyResource (const Handle(OpenGl_Context)& theGlContext,
 void OpenGl_View::releaseRaytraceResources (const Handle(OpenGl_Context)& theGlContext)
 {
   nullifyResource (theGlContext, myOpenGlFBO);
-  nullifyResource (theGlContext, myRaytraceFBO1);
-  nullifyResource (theGlContext, myRaytraceFBO2);
+  nullifyResource (theGlContext, myRaytraceFBO1[0]);
+  nullifyResource (theGlContext, myRaytraceFBO2[0]);
+  nullifyResource (theGlContext, myRaytraceFBO1[1]);
+  nullifyResource (theGlContext, myRaytraceFBO2[1]);
 
   nullifyResource (theGlContext, myRaytraceShader);
   nullifyResource (theGlContext, myPostFSAAShader);
@@ -1661,18 +1665,44 @@ void OpenGl_View::releaseRaytraceResources (const Handle(OpenGl_Context)& theGlC
 }
 
 // =======================================================================
-// function : resizeRaytraceBuffers
-// purpose  : Resizes OpenGL frame buffers
+// function : updateRaytraceBuffers
+// purpose  : Updates auxiliary OpenGL frame buffers.
 // =======================================================================
-Standard_Boolean OpenGl_View::resizeRaytraceBuffers (const Standard_Integer        theSizeX,
+Standard_Boolean OpenGl_View::updateRaytraceBuffers (const Standard_Integer        theSizeX,
                                                      const Standard_Integer        theSizeY,
                                                      const Handle(OpenGl_Context)& theGlContext)
 {
-  if (myRaytraceFBO1->GetVPSizeX() != theSizeX
-   || myRaytraceFBO1->GetVPSizeY() != theSizeY)
+  // Auxiliary buffers are not used.
+  if (!myRaytraceParameters.GlobalIllumination && !myRenderParams.IsAntialiasingEnabled)
   {
-    myRaytraceFBO1->Init (theGlContext, theSizeX, theSizeY);
-    myRaytraceFBO2->Init (theGlContext, theSizeX, theSizeY);
+    myRaytraceFBO1[0]->Release (theGlContext.operator->());
+    myRaytraceFBO2[0]->Release (theGlContext.operator->());
+    myRaytraceFBO1[1]->Release (theGlContext.operator->());
+    myRaytraceFBO2[1]->Release (theGlContext.operator->());
+    return Standard_True;
+  }
+
+  if ( myRaytraceFBO1[0]->GetVPSizeX() != theSizeX
+    || myRaytraceFBO1[0]->GetVPSizeY() != theSizeY)
+  {
+    myRaytraceFBO1[0]->Init (theGlContext, theSizeX, theSizeY);
+    myRaytraceFBO2[0]->Init (theGlContext, theSizeX, theSizeY);
+  }
+
+  // Init second set of buffers for stereographic rendering.
+  if (myCamera->ProjectionType() == Graphic3d_Camera::Projection_Stereo)
+  {
+    if (myRaytraceFBO1[1]->GetVPSizeX() != theSizeX
+     || myRaytraceFBO1[1]->GetVPSizeY() != theSizeY)
+    {
+      myRaytraceFBO1[1]->Init (theGlContext, theSizeX, theSizeY);
+      myRaytraceFBO2[1]->Init (theGlContext, theSizeX, theSizeY);
+    }
+  }
+  else
+  {
+    myRaytraceFBO1[1]->Release (theGlContext.operator->());
+    myRaytraceFBO2[1]->Release (theGlContext.operator->());
   }
 
   return Standard_True;
@@ -2343,6 +2373,7 @@ Standard_Boolean OpenGl_View::runRaytraceShaders (const Standard_Integer
                                                   const OpenGl_Vec3*            theOrigins,
                                                   const OpenGl_Vec3*            theDirects,
                                                   const OpenGl_Mat4&            theUnviewMat,
+                                                  Graphic3d_Camera::Projection  theProjection,
                                                   OpenGl_FrameBuffer*           theReadDrawFbo,
                                                   const Handle(OpenGl_Context)& theGlContext)
 {
@@ -2351,22 +2382,15 @@ Standard_Boolean OpenGl_View::runRaytraceShaders (const Standard_Integer
   Handle(OpenGl_FrameBuffer) aRenderFramebuffer;
   Handle(OpenGl_FrameBuffer) anAccumFramebuffer;
 
+  // Choose proper set of framebuffers for stereo rendering
+  Standard_Boolean isStereo   = myCamera->ProjectionType() == Graphic3d_Camera::Projection_Stereo;
+  Standard_Boolean isRightEye = theProjection              == Graphic3d_Camera::Projection_MonoRightEye;
+  Standard_Integer aFBOIdx    = (isStereo && isRightEye) ? 1 : 0;
+
   if (myRaytraceParameters.GlobalIllumination) // if path-tracing is used
   {
-    for (int anIdx = 0; anIdx < 3; ++anIdx)
-    {
-      if  (fabsf (theOrigins[anIdx].x() - myPreviousOrigins[anIdx].x()) > std::numeric_limits<Standard_ShortReal>::epsilon()
-        || fabsf (theOrigins[anIdx].y() - myPreviousOrigins[anIdx].y()) > std::numeric_limits<Standard_ShortReal>::epsilon()
-        || fabsf (theOrigins[anIdx].z() - myPreviousOrigins[anIdx].z()) > std::numeric_limits<Standard_ShortReal>::epsilon())
-      {
-        myAccumFrames = 0; // camera has been moved
-      }
-
-      myPreviousOrigins[anIdx] = theOrigins[anIdx];
-    }
-
-    aRenderFramebuffer = myAccumFrames % 2 ? myRaytraceFBO1 : myRaytraceFBO2;
-    anAccumFramebuffer = myAccumFrames % 2 ? myRaytraceFBO2 : myRaytraceFBO1;
+    aRenderFramebuffer = myAccumFrames % 2 ? myRaytraceFBO1[aFBOIdx] : myRaytraceFBO2[aFBOIdx];
+    anAccumFramebuffer = myAccumFrames % 2 ? myRaytraceFBO2[aFBOIdx] : myRaytraceFBO1[aFBOIdx];
 
     anAccumFramebuffer->ColorTexture()->Bind (
       theGlContext, GL_TEXTURE0 + OpenGl_RT_PrevAccumTexture);
@@ -2375,7 +2399,7 @@ Standard_Boolean OpenGl_View::runRaytraceShaders (const Standard_Integer
   }
   else if (myRenderParams.IsAntialiasingEnabled) // if 2-pass ray-tracing is used
   {
-    myRaytraceFBO1->BindBuffer (theGlContext);
+    myRaytraceFBO1[aFBOIdx]->BindBuffer (theGlContext);
 
     glDisable (GL_BLEND);
   }
@@ -2426,12 +2450,10 @@ Standard_Boolean OpenGl_View::runRaytraceShaders (const Standard_Integer
       theGlContext, GL_TEXTURE0 + OpenGl_RT_PrevAccumTexture);
 
     theGlContext->core20fwd->glDrawArrays (GL_TRIANGLES, 0, 6);
-
-    ++myAccumFrames;
   }
   else if (myRenderParams.IsAntialiasingEnabled)
   {
-    myRaytraceFBO1->ColorTexture()->Bind (theGlContext, GL_TEXTURE0 + OpenGl_RT_FsaaInputTexture);
+    myRaytraceFBO1[aFBOIdx]->ColorTexture()->Bind (theGlContext, GL_TEXTURE0 + OpenGl_RT_FsaaInputTexture);
 
     aResult &= theGlContext->BindProgram (myPostFSAAProgram);
 
@@ -2473,7 +2495,7 @@ Standard_Boolean OpenGl_View::runRaytraceShaders (const Standard_Integer
       aResult &= myPostFSAAProgram->SetUniform (theGlContext,
         myUniformLocations[1][OpenGl_RT_uOffsetY], aOffsetY);
 
-      Handle(OpenGl_FrameBuffer)& aFramebuffer = anIt % 2 ? myRaytraceFBO2 : myRaytraceFBO1;
+      Handle(OpenGl_FrameBuffer)& aFramebuffer = anIt % 2 ? myRaytraceFBO2[aFBOIdx] : myRaytraceFBO1[aFBOIdx];
 
       if (anIt == 3) // disable FBO on last iteration
       {
@@ -2513,6 +2535,7 @@ Standard_Boolean OpenGl_View::runRaytraceShaders (const Standard_Integer
 // =======================================================================
 Standard_Boolean OpenGl_View::raytrace (const Standard_Integer        theSizeX,
                                         const Standard_Integer        theSizeY,
+                                        Graphic3d_Camera::Projection  theProjection,
                                         OpenGl_FrameBuffer*           theReadDrawFbo,
                                         const Handle(OpenGl_Context)& theGlContext)
 {
@@ -2521,7 +2544,7 @@ Standard_Boolean OpenGl_View::raytrace (const Standard_Integer        theSizeX,
     return Standard_False;
   }
 
-  if (!resizeRaytraceBuffers (theSizeX, theSizeY, theGlContext))
+  if (!updateRaytraceBuffers (theSizeX, theSizeY, theGlContext))
   {
     return Standard_False;
   }
@@ -2576,6 +2599,7 @@ Standard_Boolean OpenGl_View::raytrace (const Standard_Integer        theSizeX,
                                                    aOrigins,
                                                    aDirects,
                                                    anUnviewMat,
+                                                   theProjection,
                                                    theReadDrawFbo,
                                                    theGlContext);
 
index f123f695ce68d5cc65cb745a18310e368b041d37..5fb382dc9d171fe49f9f3b6f415df1300e2b52b1 100644 (file)
@@ -460,6 +460,12 @@ void OpenGl_View::Redraw()
   }
 #endif
 
+  if (myRenderParams.Method == Graphic3d_RM_RAYTRACING
+   && myRenderParams.IsGlobalIlluminationEnabled)
+  {
+    myAccumFrames++;
+  }
+
   // bind default FBO
   bindDefaultFbo();
 
@@ -779,6 +785,7 @@ void OpenGl_View::render (Graphic3d_Camera::Projection theProjection,
   {
     aContext->ProjectionState.SetCurrent (myCamera->ProjectionMatrixF());
     aContext->WorldViewState .SetCurrent (myCamera->OrientationMatrixF());
+    myAccumFrames = 0;
   }
 
   // Apply new matrix state if camera has changed or this view differs from the one
@@ -915,7 +922,7 @@ void OpenGl_View::render (Graphic3d_Camera::Projection theProjection,
     aContext->ProjectionState.SetCurrent (myCamera->ProjectionStereoRightF());
     aContext->ApplyProjectionMatrix();
   }
-  renderScene (theOutputFBO, theToDrawImmediate);
+  renderScene (theProjection, theOutputFBO, theToDrawImmediate);
 
   // ===============================
   //      Step 4: Trihedron
@@ -980,8 +987,9 @@ void OpenGl_View::InvalidateBVHData (const Graphic3d_ZLayerId theLayerId)
 //function : renderStructs
 //purpose  :
 //=======================================================================
-void OpenGl_View::renderStructs (OpenGl_FrameBuffer*    theReadDrawFbo,
-                                 const Standard_Boolean theToDrawImmediate)
+void OpenGl_View::renderStructs (Graphic3d_Camera::Projection theProjection,
+                                 OpenGl_FrameBuffer*          theReadDrawFbo,
+                                 const Standard_Boolean       theToDrawImmediate)
 {
   if ( myZLayers.NbStructures() <= 0 )
     return;
@@ -1095,7 +1103,7 @@ void OpenGl_View::renderStructs (OpenGl_FrameBuffer*    theReadDrawFbo,
       }
 
       // Ray-tracing polygonal primitive arrays
-      raytrace (aSizeX, aSizeY, theReadDrawFbo, aCtx);
+      raytrace (aSizeX, aSizeY, theProjection, theReadDrawFbo, aCtx);
 
       // Render upper (top and topmost) OpenGL layers
       myZLayers.Render (myWorkspace, theToDrawImmediate, OpenGl_LF_Upper);
@@ -1143,8 +1151,9 @@ void OpenGl_View::Invalidate()
 //function : renderScene
 //purpose  :
 //=======================================================================
-void OpenGl_View::renderScene (OpenGl_FrameBuffer*    theReadDrawFbo,
-                               const Standard_Boolean theToDrawImmediate)
+void OpenGl_View::renderScene (Graphic3d_Camera::Projection theProjection,
+                               OpenGl_FrameBuffer*          theReadDrawFbo,
+                               const Standard_Boolean       theToDrawImmediate)
 {
   const Handle(OpenGl_Context)& aContext = myWorkspace->GetGlContext();
 
@@ -1278,7 +1287,7 @@ void OpenGl_View::renderScene (OpenGl_FrameBuffer*    theReadDrawFbo,
       myWorkspace->NamedStatus |= OPENGL_NS_FORBIDSETTEX;
       myWorkspace->DisableTexture();
       // Render the view
-      renderStructs (theReadDrawFbo, theToDrawImmediate);
+      renderStructs (theProjection, theReadDrawFbo, theToDrawImmediate);
       break;
 
     case Graphic3d_TOD_ENVIRONMENT:
@@ -1288,7 +1297,7 @@ void OpenGl_View::renderScene (OpenGl_FrameBuffer*    theReadDrawFbo,
         myWorkspace->EnableTexture (myTextureEnv);
       }
       // Render the view
-      renderStructs (theReadDrawFbo, theToDrawImmediate);
+      renderStructs (theProjection, theReadDrawFbo, theToDrawImmediate);
       myWorkspace->DisableTexture();
       break;
 
@@ -1296,7 +1305,7 @@ void OpenGl_View::renderScene (OpenGl_FrameBuffer*    theReadDrawFbo,
       // First pass
       myWorkspace->NamedStatus &= ~OPENGL_NS_FORBIDSETTEX;
       // Render the view
-      renderStructs (theReadDrawFbo, theToDrawImmediate);
+      renderStructs (theProjection, theReadDrawFbo, theToDrawImmediate);
       myWorkspace->DisableTexture();
 
       // Second pass
@@ -1332,7 +1341,7 @@ void OpenGl_View::renderScene (OpenGl_FrameBuffer*    theReadDrawFbo,
         myWorkspace->NamedStatus |= OPENGL_NS_FORBIDSETTEX;
 
         // Render the view
-        renderStructs (theReadDrawFbo, theToDrawImmediate);
+        renderStructs (theProjection, theReadDrawFbo, theToDrawImmediate);
         myWorkspace->DisableTexture();
 
         // Restore properties back
index fbf0cfc3447035d58182159d59cbe05064eaa0bb..dccc1f8689fbd04d34b1c9642e6d5c32f0d7229d 100644 (file)
@@ -3189,10 +3189,10 @@ Standard_Boolean V3d_View::FitMinMax (const Handle(Graphic3d_Camera)& theCamera,
   // 4) Determine new zooming in view space.
 
   // 1. Determine normalized projection asymmetry (if any).
-  Standard_Real anAssymX = Tan ( aCamSide.Angle (aFrustumPlane (1).Axis().Direction()))
-                         - Tan (-aCamSide.Angle (aFrustumPlane (2).Axis().Direction()));
-  Standard_Real anAssymY = Tan ( aCamUp.Angle   (aFrustumPlane (3).Axis().Direction()))
-                         - Tan (-aCamUp.Angle   (aFrustumPlane (4).Axis().Direction()));
+  Standard_Real anAssymX = Tan (( aCamSide).Angle (aFrustumPlane (1).Axis().Direction()))
+                         - Tan ((-aCamSide).Angle (aFrustumPlane (2).Axis().Direction()));
+  Standard_Real anAssymY = Tan (( aCamUp)  .Angle (aFrustumPlane (3).Axis().Direction()))
+                         - Tan ((-aCamUp)  .Angle (aFrustumPlane (4).Axis().Direction()));
 
   // 2. Determine how far should be the frustum planes placed from center
   //    of bounding box, in order to match the bounding box closely.
@@ -3232,12 +3232,12 @@ Standard_Boolean V3d_View::FitMinMax (const Handle(Graphic3d_Camera)& theCamera,
   //                            \//
   //                            //
   //                      (frustum plane)
-  aFitDistance.ChangeValue (1) *= Sqrt(1 + Pow (Tan ( aCamSide.Angle (aFrustumPlane (1).Axis().Direction())), 2.0));
-  aFitDistance.ChangeValue (2) *= Sqrt(1 + Pow (Tan (-aCamSide.Angle (aFrustumPlane (2).Axis().Direction())), 2.0));
-  aFitDistance.ChangeValue (3) *= Sqrt(1 + Pow (Tan ( aCamUp.Angle   (aFrustumPlane (3).Axis().Direction())), 2.0));
-  aFitDistance.ChangeValue (4) *= Sqrt(1 + Pow (Tan (-aCamUp.Angle   (aFrustumPlane (4).Axis().Direction())), 2.0));
-  aFitDistance.ChangeValue (5) *= Sqrt(1 + Pow (Tan ( aCamDir.Angle  (aFrustumPlane (5).Axis().Direction())), 2.0));
-  aFitDistance.ChangeValue (6) *= Sqrt(1 + Pow (Tan (-aCamDir.Angle  (aFrustumPlane (6).Axis().Direction())), 2.0));
+  aFitDistance.ChangeValue (1) *= Sqrt(1 + Pow (Tan (  aCamSide .Angle (aFrustumPlane (1).Axis().Direction())), 2.0));
+  aFitDistance.ChangeValue (2) *= Sqrt(1 + Pow (Tan ((-aCamSide).Angle (aFrustumPlane (2).Axis().Direction())), 2.0));
+  aFitDistance.ChangeValue (3) *= Sqrt(1 + Pow (Tan (  aCamUp   .Angle (aFrustumPlane (3).Axis().Direction())), 2.0));
+  aFitDistance.ChangeValue (4) *= Sqrt(1 + Pow (Tan ((-aCamUp)  .Angle (aFrustumPlane (4).Axis().Direction())), 2.0));
+  aFitDistance.ChangeValue (5) *= Sqrt(1 + Pow (Tan (  aCamDir  .Angle (aFrustumPlane (5).Axis().Direction())), 2.0));
+  aFitDistance.ChangeValue (6) *= Sqrt(1 + Pow (Tan ((-aCamDir) .Angle (aFrustumPlane (6).Axis().Direction())), 2.0));
 
   Standard_Real aViewSizeXv = aFitDistance (1) + aFitDistance (2);
   Standard_Real aViewSizeYv = aFitDistance (3) + aFitDistance (4);
index 503f9db58213fa38cc1c6027f3789a66ad2d7c1f..6e9263475733e4f554827c12c825fa399c2102e6 100644 (file)
@@ -7407,6 +7407,33 @@ static int VStereo (Draw_Interpretor& theDI,
 
     Standard_Boolean isActive = ViewerTest_myDefaultCaps.contextStereo;
     theDI << "Stereo " << (isActive ? "ON" : "OFF") << "\n";
+    if (isActive)
+    {
+      TCollection_AsciiString aMode;
+      switch (aView->RenderingParams().StereoMode)
+      {
+        case Graphic3d_StereoMode_QuadBuffer       : aMode = "quadBuffer";       break;
+        case Graphic3d_StereoMode_RowInterlaced    : aMode = "rowInterlaced";    break;
+        case Graphic3d_StereoMode_ColumnInterlaced : aMode = "columnInterlaced"; break;
+        case Graphic3d_StereoMode_ChessBoard       : aMode = "chessBoard";       break;
+        case Graphic3d_StereoMode_SideBySide       : aMode = "sideBySide";       break;
+        case Graphic3d_StereoMode_OverUnder        : aMode = "overUnder";        break;
+        case Graphic3d_StereoMode_SoftPageFlip     : aMode = "softpageflip";     break;
+        case Graphic3d_StereoMode_Anaglyph  :
+          aMode = "anaglyph";
+          switch (aView->RenderingParams().AnaglyphFilter)
+          {
+            case Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple      : aMode.AssignCat (" (redCyanSimple)");      break;
+            case Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized   : aMode.AssignCat (" (redCyan)");            break;
+            case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Simple   : aMode.AssignCat (" (yellowBlueSimple)");   break;
+            case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized: aMode.AssignCat (" (yellowBlue)");         break;
+            case Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple : aMode.AssignCat (" (greenMagentaSimple)"); break;
+            default: break;
+          }
+        default: break;
+      }
+      theDI << "Mode " << aMode << "\n";
+    }
     return 0;
   }
 
index be897336cb53af5d392c0876ae41b6ead036570b..3fbd32339de5727b22321c8082ea825563a58236 100755 (executable)
@@ -1,5 +1,32 @@
 catch { vfit }
-if { ![info exists subgroup] || $subgroup != "mesh" } {
+if { [info exists subgroup] && $subgroup == "raytrace" } {
+
+  # dump final image for raytraced visualization tests
+  if { ![info exists to_dump_screen] || $to_dump_screen == 1 } {
+    catch { set render_parameters [vrenderparams] }
+    catch { set stereo_parameters [vstereo] }
+
+    # for global illumination mode accumulate frames before dumping
+    regexp {renderMode *: *([A-Za-z]+)} $render_parameters full renderMode
+    regexp {GI *: *([A-Za-z]+)}         $render_parameters full gi_enabled
+    if { [string equal -nocase "raytrace" $renderMode] && [string equal -nocase "on" $gi_enabled] } {
+      vfps 200
+    }
+
+    set dump_options {}
+    regexp {Stereo *([A-Za-z]+)} $stereo_parameters full stereo_enabled
+    regexp {Mode *([A-Za-z]+)}   $stereo_parameters full stereo_mode
+    if { [string equal -nocase "on" $stereo_enabled] } {
+      set dump_options {-stereo blend}
+    }
+
+    if { [ catch { vdump $imagedir/${test_image}.png {*}$dump_options } catch_result ] } {
+      puts $catch_result
+    }
+  }
+} elseif { ![info exists subgroup] || $subgroup != "mesh" } {
+
+  # dump final image for common visualization tests
   if { ![info exists to_dump_screen] && [ catch { vdump $imagedir/${test_image}.png } catch_result ] } {
     puts $catch_result
   }
index 6cabd388d996499252c0b1851469ca27cea2e9a5..ac9de1e478fdb4e9b111d094241281ec4d62a661 100644 (file)
@@ -1 +1,2 @@
+set subgroup "raytrace"
 vinit View1
\ No newline at end of file
diff --git a/tests/v3d/raytrace/bug26617 b/tests/v3d/raytrace/bug26617
new file mode 100644 (file)
index 0000000..cb5882a
--- /dev/null
@@ -0,0 +1,38 @@
+puts "============"
+puts "CR26617"
+puts "============"
+puts ""
+
+##########################################################################################
+# Visualization, Ray Tracing - adopt progressive rendering Path Tracing for rendering stereoscopic pair
+##########################################################################################
+
+# custom shapes
+set aShape1 [locate_data_file occ/Top.brep]
+set aShape2 [locate_data_file occ/Bottom.brep]
+
+# setup 3D viewer content
+vinit name=View1 w=512 h=512
+vglinfo
+
+vvbo 0
+vsetdispmode 1
+vsetgradientbg 180 200 255 180 180 180 2
+restore $aShape1 s1
+restore $aShape2 s2
+vdisplay s1 s2
+vsetmaterial s1 Silver
+vsetmaterial s2 Pewter
+vsetlocation s1 0.0 0.1 0.0
+vlight change 0 pos -1 1 1
+
+# activate ray-tracing
+vrenderparams -raytrace
+vtextureenv on 5
+vrenderparams -reflections -gi
+
+# activate stereo
+vstereo on
+vstereo -mode anaglyph
+vcamera -iod 0.1
+vfit