Qt3D: Antialising in deferred rendering



  • Hello all,

    I am writing an application in which I want to use deferred rendering.

    When using forward rendering, we can see that multisample antialiasing (MSAA) is enabled.
    However, I am trying to have MSAA in my deferred rendering application and I am not able to do this.

    As my framegraph is pretty complex (see below), I just show important parts of my code where I have tried to enable MSAA.

    • First of all, I have followed the answer of this topic before creating the Qt3DWindow.
    • Then, in my framegraph I have enabled MSAA by adding a QMultiSampleAntiAliasing in the QRenderStateSet
        auto globalRenderStateSet = new Qt3DRender::QRenderStateSet(viewport);
        auto depthTestState = new Qt3DRender::QDepthTest();
        depthTestState -> setDepthFunction(Qt3DRender::QDepthTest::LessOrEqual);
        auto msaaState = new Qt3DRender::QMultiSampleAntiAliasing();
        globalRenderStateSet -> addRenderState(depthTestState);
        globalRenderStateSet -> addRenderState(msaaState);
    
    • I have a GBuffer (QRenderTarget) in which I use only QTexture2DMultisample objects, all with the same amount of samples (the same as in the QSurfaceFormat of the first point as well).
        _textures = new Qt3DRender::QTexture2DMultisample*[attachmentsCount];
        _attachments = new Qt3DRender::QRenderTargetOutput*[attachmentsCount];
        for (int attachmentIndex = 0 ; attachmentIndex < attachmentsCount ; attachmentIndex++)
        {
            const TargetOutputParameters& parameter = parameters[attachmentIndex];
    
            _attachments[attachmentIndex] = new Qt3DRender::QRenderTargetOutput(this);
            _textures[attachmentIndex] = new Qt3DRender::QTexture2DMultisample();
            _textures[attachmentIndex] -> setFormat(parameter.format());
            _textures[attachmentIndex] -> setWidth(TextureWidth);
            _textures[attachmentIndex] -> setHeight(TextureHeight);
            _textures[attachmentIndex] -> setGenerateMipMaps(false);
            _textures[attachmentIndex] -> setWrapMode(Qt3DRender::QTextureWrapMode(Qt3DRender::QTextureWrapMode::ClampToEdge));
            _textures[attachmentIndex] -> setMinificationFilter(Qt3DRender::QAbstractTexture::Linear);
            _textures[attachmentIndex] -> setMagnificationFilter(Qt3DRender::QAbstractTexture::Linear);
            _textures[attachmentIndex] -> setSamples(8);
    
            _attachments[attachmentIndex] -> setTexture(_textures[attachmentIndex]);
            _attachments[attachmentIndex] -> setAttachmentPoint(parameter.attachmentPoint());
            _attachments[attachmentIndex] -> setObjectName(parameter.name());
    
            addOutput(_attachments[attachmentIndex]);
        }
    
    • I have another QRenderTarget (MSAADestinationRenderTarget) in which I only have QTexture2D objects. I perform a QBlitFramebuffer to copy the MSAA color texture into the single-sample render target.
                auto noDraw = new Qt3DRender::QNoDraw(cameraSelector);
                auto sceneBlitColorFBOs = new Qt3DRender::QBlitFramebuffer(noDraw);
    
                _gBuffer = new GBuffer();
                _msaaRenderTarget = new MSAADestinationRenderTarget();
    
                auto msaaRenderTargetSelector = new Qt3DRender::QRenderTargetSelector(cameraSelector);
                msaaRenderTargetSelector -> setTarget(_msaaRenderTarget);
    
                sceneBlitColorFBOs -> setSource(_gBuffer);
                sceneBlitColorFBOs -> setSourceAttachmentPoint(Qt3DRender::QRenderTargetOutput::Color0);
                sceneBlitColorFBOs -> setSourceRect(QRect(0, 0, _view -> width(), _view->height()));
                sceneBlitColorFBOs -> setDestination(_msaaRenderTarget);
                sceneBlitColorFBOs -> setDestinationAttachmentPoint(Qt3DRender::QRenderTargetOutput::Color0);
                sceneBlitColorFBOs -> setDestinationRect(QRect(0, 0, _view -> width(), _view->height()));
    

    All of this seems to be working well as I can display this texture on a quad and see the scene, move the camera, etc. But, it is not antialiased.

    Am I missing something?
    Thank you for any help.

    Denis

    Framegraph:
    0_1521640808054_framegraph.png



  • Hi,

    I have not found any solution from C++ code itself.
    So I have implemented FXAA into my fragment shader to get an antialiased picture.

    Denis


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.