Two renderer on same layer

Hello,
im trying to display a point cloud and the axis/ground/various static data.
I can create my points and axis without any issue. My problem is that the lines that represent the axis are always in front, even if the point is supposed to be in front of the axis


In the picture, its the same scene, one from the top, one from the bottom, and the axis are akways in front of the points.

    mRenderers[Renderers::Background]     = vtkSmartPointer<vtkRenderer>::New();
    mRenderers[Renderers::Points]         = vtkSmartPointer<vtkRenderer>::New();
    mRenderers[Renderers::StaticData]     = vtkSmartPointer<vtkRenderer>::New();
    mRenderers[Renderers::ForeGroundInfo] = vtkSmartPointer<vtkRenderer>::New();

    mRenderers[Renderers::Background]->SetLayer( 0 );
    mRenderers[Renderers::Points]->SetLayer( 1 );
    mRenderers[Renderers::StaticData]->SetLayer( 1 );
    mRenderers[Renderers::ForeGroundInfo]->SetLayer( 2 );
    mVTKWidget->renderWindow()->SetNumberOfLayers( 3 );

    for( const auto &lRenderer : mRenderers )
    {
        mVTKWidget->renderWindow()->AddRenderer( lRenderer.second );
    }

    mRenderers[Renderers::Points]->SetActiveCamera( mRenderers[Renderers::Background]->GetActiveCamera() );
    mRenderers[Renderers::StaticData]->SetActiveCamera( mRenderers[Renderers::Background]->GetActiveCamera() );
    mRenderers[Renderers::ForeGroundInfo]->SetActiveCamera( mRenderers[Renderers::Background]->GetActiveCamera() );

This is how I created my renderers and set layers.

Is it possible to have the two renderers that are on the same layer respect depth and position?

Note: if I put them in the same renderer, it’s working correctly

Note2: I would prefer to keep them in two renderers, because data in the “StaticData” almost never change, but data in the “Points” renderer change all the time.
Maybe im misunderstanding the concept of renderers

Thanks

Hello, David,

My two cents: each renderer by default resets the depth/Z buffer of the viewport, so if you place them in different renderers, one scene will be on top of the other. So, I believe you need to call vtkRenderer::PreserveDepthBufferOn() or vtkRenderer::EraseOff() on each of your renderers.

take care,

Paulo

With EraseOff: well, nothing is erased, so new data is added to the current data, and the image becomes a mess

With PreserveDepthBufferOn: it seems to work when I use it on my “StaticData” renderer. It’s the one that share its layer with the “points” renderer.
It does nothing when I call it on the “points” renderer, probably because its added first to the render window

So everything good now, thanks for your help

1 Like