Depth problem with Qt3D

  • Hi,
    I have a new problem with Qt3D. I'm just creating a scene without any specific shader. So, it is a just a set of entities created in a "random" order, without taking care of there position in the scene. All the entities have a QTransform to place them (relatively to the scene or a parent entity for complex entities).

    Rotating the view (I'm using the orbital camera controller), I have discovered that display is not correct. The depth test seems to not be active. So entities are displayed in the order when have been created without taking care of hidden sections. With OpenGL, I know how to fix this problem, using the depth test. But I do not know how to fix the problem with Qt3D.

    Note: this problem has already been reported (but still marked "unsolved") 2 years ago. See

    The difference in my code is that I'm using Qt 5.12.

  • @Alain38-0 I found the way!. It is just a little bit complex. I have to create a material for the root entity that enables the depth test. For whom who have the same problem:

            m_rootEntity = new Qt3DCore::QEntity();
            Qt3DRender::QMaterial *  rootMaterial   = new Qt3DRender::QMaterial;
            Qt3DRender::QEffect*     rootEffect     = new Qt3DRender::QEffect;
            Qt3DRender::QTechnique*  rootTechnique  = new Qt3DRender::QTechnique;
            Qt3DRender::QRenderPass* rootRenderPass = new Qt3DRender::QRenderPass;
            Qt3DRender::QDepthTest*  rootDepthTest  = new Qt3DRender::QDepthTest;
            rootDepthTest ->setDepthFunction(Qt3DRender::QDepthTest::Less);
            rootTechnique ->addRenderPass(rootRenderPass);
            rootEffect    ->addTechnique(rootTechnique);
            rootMaterial  ->setEffect(rootEffect);

  • Correction. I do not why. But my proposal no more works. But I found another way that seems to work. In fact the QDiffuseSpecularMaterial that we are supposed to use (other materials are deprecated), disable the depth buffer. So, this is a working code to force the enable (create a new effect does not work):

        Qt3DRender::QEffect *effect = material->effect();
        if (effect)
            for (Qt3DRender::QTechnique* currentTechnique : effect->techniques())
                for (Qt3DRender::QRenderPass * currentPass : currentTechnique->renderPasses())
                    for (Qt3DRender::QRenderState * currentState : currentPass->renderStates())
                        if (dynamic_cast<Qt3DRender::QNoDepthMask *>(currentState))
                            Qt3DRender::QDepthTest*  depthTest  = new Qt3DRender::QDepthTest;
                            depthTest ->setDepthFunction(Qt3DRender::QDepthTest::Less);

    Warning: if you have fully transparent (alpha = 0) objects, the test fails. So the objects behind the invisible one are not displayed.

  • Banned

    This post is deleted!