diff --git a/src/OpenGl/OpenGl_BackgroundArray.cxx b/src/OpenGl/OpenGl_BackgroundArray.cxx index 6796992caa..9d9700a897 100644 --- a/src/OpenGl/OpenGl_BackgroundArray.cxx +++ b/src/OpenGl/OpenGl_BackgroundArray.cxx @@ -433,10 +433,15 @@ void OpenGl_BackgroundArray::Render (const Handle(OpenGl_Workspace)& theWorkspac const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext(); Standard_Integer aViewSizeX = aCtx->Viewport()[2]; Standard_Integer aViewSizeY = aCtx->Viewport()[3]; + Graphic3d_Vec2i aTileOffset, aTileSize; + if (theWorkspace->View()->Camera()->Tile().IsValid()) { aViewSizeX = theWorkspace->View()->Camera()->Tile().TotalSize.x(); aViewSizeY = theWorkspace->View()->Camera()->Tile().TotalSize.y(); + + aTileOffset = theWorkspace->View()->Camera()->Tile().OffsetLowerLeft(); + aTileSize = theWorkspace->View()->Camera()->Tile().TileSize; } if (myToUpdate || myViewWidth != aViewSizeX @@ -454,8 +459,30 @@ void OpenGl_BackgroundArray::Render (const Handle(OpenGl_Workspace)& theWorkspac if (myType != Graphic3d_TOB_CUBEMAP) { - myTrsfPers.Apply(theWorkspace->View()->Camera(), aProjection, aWorldView, - aCtx->Viewport()[2], aCtx->Viewport()[3]); + aProjection.InitIdentity(); + aWorldView.InitIdentity(); + if (theWorkspace->View()->Camera()->Tile().IsValid()) + { + aWorldView.SetDiagonal (OpenGl_Vec4 (2.0f / aTileSize.x(), 2.0f / aTileSize.y(), 1.0f, 1.0f)); + if (myType == Graphic3d_TOB_GRADIENT) + { + aWorldView.SetColumn (3, OpenGl_Vec4 (-1.0f - 2.0f * aTileOffset.x() / aTileSize.x(), + -1.0f - 2.0f * aTileOffset.y() / aTileSize.y(), 0.0f, 1.0f)); + } + else + { + aWorldView.SetColumn (3, OpenGl_Vec4 (-1.0f + (float) aViewSizeX / aTileSize.x() - 2.0f * aTileOffset.x() / aTileSize.x(), + -1.0f + (float) aViewSizeY / aTileSize.y() - 2.0f * aTileOffset.y() / aTileSize.y(), 0.0f, 1.0f)); + } + } + else + { + aWorldView.SetDiagonal (OpenGl_Vec4 (2.0f / myViewWidth, 2.0f / myViewHeight, 1.0f, 1.0f)); + if (myType == Graphic3d_TOB_GRADIENT) + { + aWorldView.SetColumn (3, OpenGl_Vec4 (-1.0f, -1.0f, 0.0f, 1.0f)); + } + } } aCtx->ProjectionState.Push(); diff --git a/src/OpenGl/OpenGl_View.cxx b/src/OpenGl/OpenGl_View.cxx index b5d5c23635..2ee86d6e1a 100644 --- a/src/OpenGl/OpenGl_View.cxx +++ b/src/OpenGl/OpenGl_View.cxx @@ -686,36 +686,6 @@ Bnd_Box OpenGl_View::MinMaxValues (const Standard_Boolean theToIncludeAuxiliary) Bnd_Box aBox = base_type::MinMaxValues (theToIncludeAuxiliary); - // add bounding box of gradient/texture background for proper Z-fit - if (theToIncludeAuxiliary - && (myBackgrounds[Graphic3d_TOB_TEXTURE]->IsDefined() - || myBackgrounds[Graphic3d_TOB_GRADIENT]->IsDefined())) - { - const Handle(Graphic3d_Camera)& aCamera = Camera(); - Graphic3d_Vec2i aWinSize; - Window()->Size (aWinSize.x(), aWinSize.y()); - - // Background is drawn using 2D transformation persistence - // (e.g. it is actually placed in 3D coordinates within active camera position). - // We add here full-screen plane with 2D transformation persistence - // for simplicity (myBgTextureArray might define a little bit different options - // but it is updated within ::Render()) - const Graphic3d_Mat4d& aProjectionMat = aCamera->ProjectionMatrix(); - const Graphic3d_Mat4d& aWorldViewMat = aCamera->OrientationMatrix(); - Graphic3d_BndBox3d aBox2d (Graphic3d_Vec3d (0.0, 0.0, 0.0), - Graphic3d_Vec3d (double(aWinSize.x()), double(aWinSize.y()), 0.0)); - - Graphic3d_TransformPers aTrsfPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_LOWER); - aTrsfPers.Apply (aCamera, - aProjectionMat, - aWorldViewMat, - aWinSize.x(), - aWinSize.y(), - aBox2d); - aBox.Add (gp_Pnt (aBox2d.CornerMin().x(), aBox2d.CornerMin().y(), aBox2d.CornerMin().z())); - aBox.Add (gp_Pnt (aBox2d.CornerMax().x(), aBox2d.CornerMax().y(), aBox2d.CornerMax().z())); - } - return aBox; } diff --git a/src/OpenGl/OpenGl_View_Raytrace.cxx b/src/OpenGl/OpenGl_View_Raytrace.cxx index 5530426c07..b667440015 100644 --- a/src/OpenGl/OpenGl_View_Raytrace.cxx +++ b/src/OpenGl/OpenGl_View_Raytrace.cxx @@ -2584,6 +2584,16 @@ Standard_Boolean OpenGl_View::setUniformState (const Standard_Integer the { aBackColorTop = myBackgrounds[Graphic3d_TOB_GRADIENT]->GradientColor (0); aBackColorBot = myBackgrounds[Graphic3d_TOB_GRADIENT]->GradientColor (1); + + if (myCamera->Tile().IsValid()) + { + Standard_Integer aTileOffset = myCamera->Tile().OffsetLowerLeft().y(); + Standard_Integer aTileSize = myCamera->Tile().TileSize.y(); + Standard_Integer aViewSize = myCamera->Tile().TotalSize.y(); + OpenGl_Vec4 aColorRange = aBackColorTop - aBackColorBot; + aBackColorBot = aBackColorBot + aColorRange * ((float) aTileOffset / aViewSize); + aBackColorTop = aBackColorBot + aColorRange * ((float) aTileSize / aViewSize); + } } aBackColorTop = theGlContext->Vec4FromQuantityColor (aBackColorTop); aBackColorBot = theGlContext->Vec4FromQuantityColor (aBackColorBot);