QMaterial Class▲
-
Header: QMaterial
-
Since: Qt 5.5
-
CMake:
find_package(Qt6 REQUIRED COMPONENTS 3drender)
target_link_libraries(mytarget PRIVATE Qt6::3drender)
-
qmake: QT += 3drender
-
Inherited By: Qt3DExtras::QDiffuseMapMaterial, Qt3DExtras::QDiffuseSpecularMapMaterial, Qt3DExtras::QDiffuseSpecularMaterial, Qt3DExtras::QGoochMaterial, Qt3DExtras::QMetalRoughMaterial, Qt3DExtras::QMorphPhongMaterial, Qt3DExtras::QNormalDiffuseMapMaterial, Qt3DExtras::QNormalDiffuseSpecularMapMaterial, Qt3DExtras::QPerVertexColorMaterial, Qt3DExtras::QPhongAlphaMaterial, Qt3DExtras::QPhongMaterial, and Qt3DExtras::QTextureMaterial
-
Instantiated By: qml-qt3d-render-material.xml
-
Inherits: Qt3DCore::QComponent
-
Inherited By: Qt3DExtras::QDiffuseMapMaterial, Qt3DExtras::QDiffuseSpecularMapMaterial, Qt3DExtras::QDiffuseSpecularMaterial, Qt3DExtras::QGoochMaterial, Qt3DExtras::QMetalRoughMaterial, Qt3DExtras::QMorphPhongMaterial, Qt3DExtras::QNormalDiffuseMapMaterial, Qt3DExtras::QNormalDiffuseSpecularMapMaterial, Qt3DExtras::QPerVertexColorMaterial, Qt3DExtras::QPhongAlphaMaterial, Qt3DExtras::QPhongMaterial, and Qt3DExtras::QTextureMaterial
Detailed Description▲
QMaterial provides a way to specify the rendering of an entity. Any aspect can define its own subclass of QMaterial so that a Material can be used to describe a visual element; for example, the way sound should reflect off an element, the temperature of a surface, and so on.
In itself, a QMaterial doesn't do anything. It's only when it references a QEffect node that a QMaterial becomes useful.
In practice, it often happens that a single QEffect is being referenced by several QMaterial components. This allows to only create the effect, techniques, passes and shaders once while allowing to specify the material by adding QParameter instances.
A QParameter defined on a QMaterial overrides parameter (of the same name) defined in a QEffect, QTechnique and QRenderPass, but are overridden by parameter in QRenderPassFilter and QTechniqueFilter.
QMaterial *
material1 =
new
QMaterial();
QMaterial *
material2 =
new
QMaterial();
// Create effect, technique, render pass and shader
QEffect *
effect =
new
QEffect();
QTechnique *
gl3Technique =
new
QTechnique();
QRenderPass *
gl3Pass =
new
QRenderPass();
QShaderProgram *
glShader =
new
QShaderProgram();
// Set the shader on the render pass
gl3Pass-&
gt;setShaderProgram(glShader);
// Add the pass to the technique
gl3Technique-&
gt;addRenderPass(gl3Pass);
// Set the targeted GL version for the technique
gl3Technique-&
gt;graphicsApiFilter()-&
gt;setApi(QGraphicsApiFilter::
OpenGL);
gl3Technique-&
gt;graphicsApiFilter()-&
gt;setMajorVersion(3
);
gl3Technique-&
gt;graphicsApiFilter()-&
gt;setMinorVersion(1
);
gl3Technique-&
gt;graphicsApiFilter()-&
gt;setProfile(QGraphicsApiFilter::
CoreProfile);
// Add the technique to the effect
effect-&
gt;addTechnique(gl3Technique);
// Set the effect on the materials
material1-&
gt;setEffect(effect);
material2-&
gt;setEffect(effect);
// Set different parameters on the materials
const
QString parameterName =
QStringLiteral("color"
);
material1-&
gt;addParameter(new
QParameter(parameterName, QColor::
fromRgbF(0.0
f, 1.0
f, 0.0
f, 1.0
f);
material2-&
gt;addParameter(new
QParameter(parameterName, QColor::
fromRgbF(1.0
f, 1.0
f, 1.0
f, 1.0
f);
See Also▲
See also QEffect, QTechnique, QParameter
Property Documentation▲
effect : Qt3DRender::QEffect*▲
Specifies the effect to be used with the material.
Access functions:
-
*effect() const
-
void setEffect( *effect)
Notifier signal:
-
void effectChanged( *effect)
Member Function Documentation▲
void QMaterial::addParameter(Qt3DRender::QParameter *parameter)▲
Add a parameter to the material's parameters.
QList<Qt3DRender::QParameter *> QMaterial::parameters() const▲
Returns a vector of the material's current parameters
void QMaterial::removeParameter(Qt3DRender::QParameter *parameter)▲
Remove a parameter from the material's parameters.