Skip to content

Kuesa::Qt3D::OpacityMask

Module: Kuesa Qt 3D API

Masks onscreen content based on the alpha color value of a mask texture. More...

#include <opacitymask.h>

Inherits from Kuesa::Qt3D::AbstractPostProcessingEffect, Qt3DCore::QNode

Public Signals

Name
void maskChanged(Qt3DRender::QAbstractTexture * mask)
void premultipliedAlphaChanged(bool premultipliedAlpha)

Public Functions

Name
OpacityMask(Qt3DCore::QNode * parent =nullptr)
virtual FrameGraphNodePtr frameGraphSubTree() const override
virtual QVector< Qt3DRender::QLayer * > layers() const override
virtual void setInputTexture(Qt3DRender::QAbstractTexture * texture) override
void setMask(Qt3DRender::QAbstractTexture * mask)
Qt3DRender::QAbstractTexture * mask() const
void setPremultipliedAlpha(bool premultipliedAlpha)
bool premultipliedAlpha() const

Public Properties

Name
Qt3DRender::QAbstractTexture * mask
bool premultipliedAlpha

Additional inherited members

Public Types inherited from Kuesa::Qt3D::AbstractPostProcessingEffect

Name
enum Type { Custom}
using QSharedPointer< Qt3DRender::QFrameGraphNode > FrameGraphNodePtr

Public Functions inherited from Kuesa::Qt3D::AbstractPostProcessingEffect

Name
~AbstractPostProcessingEffect()
Type type() const
virtual void setDepthTexture(Qt3DRender::QAbstractTexture * texture)
virtual void setCamera(Qt3DCore::QEntity * camera)
virtual void setWindowSize(const QSize & sceneSize)

Protected Functions inherited from Kuesa::Qt3D::AbstractPostProcessingEffect

Name
AbstractPostProcessingEffect(Qt3DCore::QNode * parent =nullptr, Type type =Custom)

Protected Attributes inherited from Kuesa::Qt3D::AbstractPostProcessingEffect

Name
const Type m_type

Detailed Description

1
class Kuesa::Qt3D::OpacityMask;

Masks onscreen content based on the alpha color value of a mask texture.

Given an RGBA mask texture, content of the backbuffer will be rendered as:

1
vec4 pixelColor = vec4(inputColor.rgb, inputColor.a * maskColor.a)

noalpha.png

A premultiplied alpha variant of the algorithm is also available which can be of use when combining Qt 3D / Kuesa content with 2D QtQuick content (Scene3D). It performs rendering doing:

1
vec4 pixelColor = vec4(inputColor.rgb / maskColor.a, inputColor.a * maskColor.a);
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
#include <Qt3DExtras/Qt3DWindow>
#include <ForwardRenderer>
#include <SceneEntity>
#include <OpacityMask>

Qt3DExtras::Qt3DWindow win;
Kuesa::Qt3D::SceneEntity *root = new Kuesa::Qt3D::SceneEntity();
Kuesa::Qt3D::ForwardRenderer *frameGraph = new Kuesa::Qt3D::ForwardRenderer();
Kuesa::Qt3D::OpacityMask *opacityMask = new Kuesa::Qt3D::OpacityMask();

Qt3DRender::QTextureLoader *texture = new Qt3DRender::QTextureLoader();
texture->setSource(QUrl("file:///opacityMask.png"));
opacityMask->setMask(texture);

frameGraph->addPostProcessingEffect(opacityMask);

win->setRootEntity(root);
win->setActiveFrameGraph(forwardRenderer);
...

alpha.png

Public Signals Documentation

signal maskChanged

1
2
3
void maskChanged(
    Qt3DRender::QAbstractTexture * mask
)

signal premultipliedAlphaChanged

1
2
3
void premultipliedAlphaChanged(
    bool premultipliedAlpha
)

Public Functions Documentation

function OpacityMask

1
2
3
explicit OpacityMask(
    Qt3DCore::QNode * parent =nullptr
)

function frameGraphSubTree

1
virtual FrameGraphNodePtr frameGraphSubTree() const override

Note: The lifetime of the returned subtree is assumed to be managed by the shared pointer. Any caller reparenting the subtree to add to a

Reimplements: Kuesa::Qt3D::AbstractPostProcessingEffect::frameGraphSubTree

Returns a FrameGraph subtree corresponding to the effect's implementation.

function layers

1
virtual QVector< Qt3DRender::QLayer * > layers() const override

Reimplements: Kuesa::Qt3D::AbstractPostProcessingEffect::layers

Return the layers provided by this effect. This will generally be the layer of a

function setInputTexture

1
2
3
virtual void setInputTexture(
    Qt3DRender::QAbstractTexture * texture
) override

Reimplements: Kuesa::Qt3D::AbstractPostProcessingEffect::setInputTexture

Sets the input texture to texture for this effect. The texture contain the rendered scene that the effect will be applied to. This is set automatically by the ForwardRenderer when the effect is added.

function setMask

1
2
3
void setMask(
    Qt3DRender::QAbstractTexture * mask
)

function mask

1
Qt3DRender::QAbstractTexture * mask() const

function setPremultipliedAlpha

1
2
3
void setPremultipliedAlpha(
    bool premultipliedAlpha
)

function premultipliedAlpha

1
bool premultipliedAlpha() const

Public Property Documentation

property mask

1
Qt3DRender::QAbstractTexture * mask;

The RGBA texture to use as a mask.

property premultipliedAlpha

1
bool premultipliedAlpha;

Specifies whether the masking should be performed using premultipliedAlpha. This can be useful when combining Kuesa and QtQuick with a Scene3D element. It is false by default.


Updated on 2023-07-03 at 11:02:10 +0000