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. Qt3d blending
Forum Updated to NodeBB v4.3 + New Features

Qt3d blending

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 732 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.
  • W Offline
    W Offline
    wang_qt
    wrote on last edited by
    #1

    I am now using Qt3D to draw some 3D object. I draw an object with semi transparent effect with the following code,
    m_pWorkspaceEntity = new Qt3DCore::QEntity(pRootEntity);

    auto cubeMesh12 = new Qt3DExtras::QCuboidMesh();
    cubeMesh12->setXExtent(200);
    cubeMesh12->setYExtent(800);
    cubeMesh12->setZExtent(800);
    
    auto pWorkspaceMaterial = new Qt3DExtras::QDiffuseSpecularMaterial();
    pWorkspaceMaterial->setDiffuse(QColor(255,0,0,200));
    pWorkspaceMaterial->setAlphaBlendingEnabled(true);
    
    
    m_pWorkspaceTransform = new Qt3DCore::QTransform();
    m_pWorkspaceTransform->setTranslation(QVector3D(500,0,0));
    
    m_pWorkspaceEntity->addComponent(cubeMesh12);
    m_pWorkspaceEntity->addComponent(pWorkspaceMaterial);
    m_pWorkspaceEntity->addComponent(m_pWorkspaceTransform);
    

    As you can see, this cuboid is in semi trasnsparent state because QColor(255,0,0,200) is used. However, what I get is
    (0_1523360499788_2018-04-10_134058.png

    The object behind the cuboid is totally displayed.

    I have turn on the blending functionality of Qt3D in the framegrpah, as shown below,
    auto pCullFaceRenderState = new Qt3DRender::QCullFace();
    pCullFaceRenderState->setMode(Qt3DRender::QCullFace::Back);

    auto pFrontFaceRenderState = new Qt3DRender::QFrontFace();
    pFrontFaceRenderState->setDirection(Qt3DRender::QFrontFace::CounterClockWise);
    
    auto PDepthTestRenderState = new Qt3DRender::QDepthTest();
    PDepthTestRenderState->setDepthFunction(Qt3DRender::QDepthTest::Less);
    
    auto pBlendEquation = new Qt3DRender::QBlendEquation();
    pBlendEquation->setBlendFunction(Qt3DRender::QBlendEquation::Add);
    
    auto pBlendEquationArguments = new Qt3DRender::QBlendEquationArguments();
    pBlendEquationArguments->setSourceRgba(Qt3DRender::QBlendEquationArguments::SourceAlpha);
    pBlendEquationArguments->setDestinationRgba(Qt3DRender::QBlendEquationArguments::OneMinusSourceAlpha);
    pBlendEquationArguments->setBufferIndex(-1);
    
    
    
    
    //One viewport
    m_pSurfaceSelectorOneViewPort = new Qt3DRender::QRenderSurfaceSelector();
    m_pSurfaceSelectorOneViewPort->setSurface(this);
    
    //Clear Buffer
    auto pClearBufferOneViewPort = new  Qt3DRender::QClearBuffers(m_pSurfaceSelectorOneViewPort);
    auto PNoDrawOneViewPort = new Qt3DRender::QNoDraw(pClearBufferOneViewPort);
    pClearBufferOneViewPort->setBuffers(Qt3DRender::QClearBuffers::ColorDepthBuffer);
    pClearBufferOneViewPort->setClearColor(QColor(95,105,115));//change the background color
    
    //View LeftUp
    auto pViewPortLeftUpOneViewPort = new Qt3DRender::QViewport(m_pSurfaceSelectorOneViewPort);
    auto pCameraSelectorLeftUpOneViewPort = new Qt3DRender::QCameraSelector(pViewPortLeftUpOneViewPort);
    pViewPortLeftUpOneViewPort->setNormalizedRect(QRectF(0.0f,0.0f,1.0f,1.0f));
    pCameraSelectorLeftUpOneViewPort->setCamera(m_pCameraLeftUp);
    
    
    auto PRenderStateSet= new Qt3DRender::QRenderStateSet(pCameraSelectorLeftUpOneViewPort);
    PRenderStateSet->addRenderState(pCullFaceRenderState);
    PRenderStateSet->addRenderState(pFrontFaceRenderState);
    PRenderStateSet->addRenderState(PDepthTestRenderState);
    PRenderStateSet->addRenderState(pBlendEquation);
    PRenderStateSet->addRenderState(pBlendEquationArguments);
    

    I have spent lots of time trying to solve this problem, but I still get no result.
    Thanks for your help in advance.

    1 Reply Last reply
    0
    • H Offline
      H Offline
      HappyFeet
      wrote on last edited by
      #2

      Are you setting your render surface selector to be a child of the active framegraph somewhere? If not, you have to do this.

      E.g. if you are using a Qt3DWindow you can retrieve its render settings (which are only there to hold the active framegrahp) by calling renderSettings(). Then you can set your custom framegraph (i.e. you only have to set your render surface selector, as that's the root node of your graph) using the setActiveFramegraph(QFramegraphNode*) function.

      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