Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Depth problem with Qt3D
QtWS25 Last Chance

Depth problem with Qt3D

Scheduled Pinned Locked Moved Solved General and Desktop
qt3dqt5.12.xdepth test
4 Posts 2 Posters 1.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Alain38 0
    wrote on last edited by
    #1

    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 https://forum.qt.io/topic/74419/a-weird-bug-why-is-there-no-spatial-depth-in-my-3d-scene

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

    A 1 Reply Last reply
    0
    • A Alain38 0

      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 https://forum.qt.io/topic/74419/a-weird-bug-why-is-there-no-spatial-depth-in-my-3d-scene

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

      A Offline
      A Offline
      Alain38 0
      wrote on last edited by
      #2

      @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);
              rootRenderPass->addRenderState(rootDepthTest);
              rootTechnique ->addRenderPass(rootRenderPass);
              rootEffect    ->addTechnique(rootTechnique);
              rootMaterial  ->setEffect(rootEffect);
              m_rootEntity->addComponent(rootMaterial);
      
      
      1 Reply Last reply
      4
      • A Offline
        A Offline
        Alain38 0
        wrote on last edited by
        #3

        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))
                            {
                                currentPass->removeRenderState(currentState);
                                Qt3DRender::QDepthTest*  depthTest  = new Qt3DRender::QDepthTest;
                                depthTest ->setDepthFunction(Qt3DRender::QDepthTest::Less);
                                currentPass->addRenderState(depthTest);
                                break;
                            }
                        }
                    }
                }
            }
        
        

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

        1 Reply Last reply
        0
        • V Offline
          V Offline
          vickyjohn
          Banned
          wrote on last edited by vickyjohn
          #4
          This post is deleted!
          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved