Qt3DRender::QShaderProgram Class
class Qt3DRender::QShaderProgramEncapsule un programme d'ombrage. Plus...
| En-tête : | #include <QShaderProgram> |
| CMake : | find_package(Qt6 REQUIRED COMPONENTS 3drender)target_link_libraries(mytarget PRIVATE Qt6::3drender) |
| qmake : | QT += 3drender |
| En QML : | ShaderProgram |
| Hérite : | Qt3DCore::QNode |
| Statut : | Déclassé |
Types publics
| enum | Format { GLSL, SPIRV } |
| enum | ShaderType { Vertex, Fragment, TessellationControl, TessellationEvaluation, Geometry, Compute } |
| enum | Status { NotReady, Ready, Error } |
Propriétés
|
|
Fonctions publiques
| QByteArray | computeShaderCode() const |
| Qt3DRender::QShaderProgram::Format | format() const |
| QByteArray | fragmentShaderCode() const |
| QByteArray | geometryShaderCode() const |
| QString | log() const |
| void | setFormat(Qt3DRender::QShaderProgram::Format format) |
| void | setShaderCode(Qt3DRender::QShaderProgram::ShaderType type, const QByteArray &shaderCode) |
| QByteArray | shaderCode(Qt3DRender::QShaderProgram::ShaderType type) const |
| Qt3DRender::QShaderProgram::Status | status() const |
| QByteArray | tessellationControlShaderCode() const |
| QByteArray | tessellationEvaluationShaderCode() const |
| QByteArray | vertexShaderCode() const |
Emplacements publics
| void | setComputeShaderCode(const QByteArray &computeShaderCode) |
| void | setFragmentShaderCode(const QByteArray &fragmentShaderCode) |
| void | setGeometryShaderCode(const QByteArray &geometryShaderCode) |
| void | setTessellationControlShaderCode(const QByteArray &tessellationControlShaderCode) |
| void | setTessellationEvaluationShaderCode(const QByteArray &tessellationEvaluationShaderCode) |
| void | setVertexShaderCode(const QByteArray &vertexShaderCode) |
Signaux
| void | computeShaderCodeChanged(const QByteArray &computeShaderCode) |
| void | formatChanged(Qt3DRender::QShaderProgram::Format format) |
| void | fragmentShaderCodeChanged(const QByteArray &fragmentShaderCode) |
| void | geometryShaderCodeChanged(const QByteArray &geometryShaderCode) |
| void | logChanged(const QString &log) |
| void | statusChanged(Qt3DRender::QShaderProgram::Status status) |
| void | tessellationControlShaderCodeChanged(const QByteArray &tessellationControlShaderCode) |
| void | tessellationEvaluationShaderCodeChanged(const QByteArray &tessellationEvaluationShaderCode) |
| void | vertexShaderCodeChanged(const QByteArray &vertexShaderCode) |
Membres publics statiques
| QByteArray | loadSource(const QUrl &sourceUrl) |
Description détaillée
Un programme de shaders se compose de plusieurs shaders différents, tels que les shaders de sommets et de fragments.
Qt3D remplira automatiquement un ensemble d'uniformes par défaut s'ils sont rencontrés pendant la phase d'instrospection du shader.
| Uniforme par défaut | Nom du paramètre Qt3D associé | Déclaration GLSL |
|---|---|---|
| Matrice de modèle | matriceModèle | mat4 uniforme matriceModèle ; |
| Matrice de vue | matriceVue | matrice de vue mat4 uniforme ; |
| Matrice de projection | matrice de projection | matrice de projection mat4 uniforme ; |
| Matrice de vue du modèle | vue-modèle | mat4 uniforme modelView ; |
| Matrice de projection de vue | matrice de projection de vue | matrice uniforme mat4 viewProjectionMatrix ; |
| Matrice de projection de la vue-modèle | modelViewProjection mvp | matrice uniforme mat4 modelViewProjection ; matrice uniforme mat4 mvp ; |
| Matrice de modèle inverse | matriceModèleInverse | mat4 uniforme inverseModelMatrix ; |
| Matrice de vue inversée | inverseViewMatrix | matrice uniforme mat4 inverseViewMatrix ; |
| Matrice d'injection inverse | matrice d'injection inverse | matrice uniforme mat4 inverseProjectionMatrix ; |
| Matrice inverseModelView | inverseModelView | matrice uniforme mat4 inverseModelView ; |
| Matrice d'injection inverseView | Matrice d'injection inverseView | matrice uniforme mat4 inverseViewProjectionMatrix ; |
| Matrice d'injection InverseModelView | inverseModelViewProjection | matrice uniforme mat4 inverseViewProjection ; |
| Matrice ModèleNormal | matrice modèleNormal | matrice uniforme mat3 modelNormalMatrix ; |
| MatriceNormaleModèle | modèleVueNormale | matrice uniforme mat3 modelViewNormal ; |
| Matrice de la vue | MatriceVueSurVue | matrice uniforme mat4 viewportMatrix ; |
| Matrice d'affichage inverse | matrice inverseViewportMatrix | matrice uniforme mat4 inverseViewportMatrix ; |
| AspectRatio (largeur de la surface / hauteur de la surface) | aspectRatio | float uniforme aspectRatio ; |
| Exposition | exposition | float uniforme exposure ; |
| Gamma | gamma | float uniforme gamma ; |
| Temps (en nano secondes) | temps | float uniforme time ; |
| Position de l'œil | position de l'oeil | vec3 uniforme eyePosition ; |
| Palette d'habillage | skinningPalette[0] | const int maxJoints = 100 ; uniform mat4 skinningPalette[maxJoints] ; |
Support RHI
Lorsque vous écrivez du code de shader GLSL 450 à utiliser avec le backend RHI de Qt 3D, les uniformes par défaut seront fournis sous la forme de 2 objets uniformes tampons.
Les emplacements de liaison pour ceux-ci sont définis sur les liaisons 0 pour les uniformes RenderView et 1 pour les uniformes Command.
#version 450 core
layout(location = 0) in vec3 vertexPosition;
layout(std140, binding = 0) uniform qt3d_render_view_uniforms {
mat4 viewMatrix;
mat4 projectionMatrix;
mat4 uncorrectedProjectionMatrix;
mat4 clipCorrectionMatrix;
mat4 viewProjectionMatrix;
mat4 inverseViewMatrix;
mat4 inverseProjectionMatrix;
mat4 inverseViewProjectionMatrix;
mat4 viewportMatrix;
mat4 inverseViewportMatrix;
vec4 textureTransformMatrix;
vec3 eyePosition;
float aspectRatio;
float gamma;
float exposure;
float time;
float yUpInNDC;
float yUpInFBO;
};
layout(std140, binding = 1) uniform qt3d_command_uniforms {
mat4 modelMatrix;
mat4 inverseModelMatrix;
mat4 modelViewMatrix;
mat3 modelNormalMatrix;
mat4 inverseModelViewMatrix;
mat4 modelViewProjection;
mat4 inverseModelViewProjectionMatrix;
};
void main()
{
gl_Position = (projectionMatrix * viewMatrix * modelMatrix * vertexPosition);
}Pour les objets tampons d'uniformes définis par l'utilisateur, utilisez la liaison commençant par 2 ou auto pour laisser Qt 3D déterminer la liaison automatiquement. Veillez à rester cohérent entre les différentes étapes du shader.
#version 450 core
layout(std140, binding = auto) uniform my_uniforms {
vec4 myColor;
};
layout(location=0) out vec4 fragColor;
void main()
{
fragColor = myColor;
}Il n'y a pas de changement lorsqu'il s'agit d'alimenter les uniformes en valeurs.
Pour l'exemple ci-dessus, la définition de myColor peut être faite avec :
QParameter *parameter = new QParameter();
parameter->setName("myColor");
parameter->setValue(QVariant::fromValue(QColor(Qt::blue)));Les textures doivent toujours être définies comme des uniformes autonomes.
#version 450 core
layout(binding=0) uniform sampler2D source;
layout(location=0) out vec4 fragColor;
void main()
{
fragColor = texture(source, vec2(0.5, 0.5));
}Documentation sur les types de membres
enum QShaderProgram::Format
Cette énumération identifie le format du code shader utilisé.
| Constante | Valeur | Description du format |
|---|---|---|
Qt3DRender::QShaderProgram::GLSL | 0 | OpenGL |
Qt3DRender::QShaderProgram::SPIRV | 1 | Vulkan, OpenGL 5 |
enum QShaderProgram::ShaderType
Cette énumération identifie le type de nuanceur utilisé.
| Constante | Valeur | Description |
|---|---|---|
Qt3DRender::QShaderProgram::Vertex | 0 | Nuanceur de sommet |
Qt3DRender::QShaderProgram::Fragment | 1 | Nuanceur de fragments |
Qt3DRender::QShaderProgram::TessellationControl | 2 | Shader de contrôle de tesselation |
Qt3DRender::QShaderProgram::TessellationEvaluation | 3 | Shader d'évaluation de la tesselation |
Qt3DRender::QShaderProgram::Geometry | 4 | Shader de géométrie |
Qt3DRender::QShaderProgram::Compute | 5 | Shader de calcul |
enum QShaderProgram::Status
Cette énumération identifie le statut du shader utilisé.
| Constante | Valeur | Description |
|---|---|---|
Qt3DRender::QShaderProgram::NotReady | 0 | Le shader n'a pas encore été compilé et lié. |
Qt3DRender::QShaderProgram::Ready | 1 | Le shader a été compilé avec succès |
Qt3DRender::QShaderProgram::Error | 2 | Une erreur s'est produite lors de la compilation du shader |
Documentation sur les propriétés
computeShaderCode : QByteArray
Contient le code de nuanceur de calcul utilisé par ce programme de nuanceur.
Fonctions d'accès :
| QByteArray | computeShaderCode() const |
| void | setComputeShaderCode(const QByteArray &computeShaderCode) |
Signal de notification :
| void | computeShaderCodeChanged(const QByteArray &computeShaderCode) |
format : Format
Indique le format du code fourni sur le site ShaderProgram. Le format par défaut est ShaderProgram.GLSL.
Fonctions d'accès :
| Qt3DRender::QShaderProgram::Format | format() const |
| void | setFormat(Qt3DRender::QShaderProgram::Format format) |
Signal de notification :
| void | formatChanged(Qt3DRender::QShaderProgram::Format format) |
fragmentShaderCode : QByteArray
Contient le code de nuanceur de fragment utilisé par ce programme de nuanceur.
Fonctions d'accès :
| QByteArray | fragmentShaderCode() const |
| void | setFragmentShaderCode(const QByteArray &fragmentShaderCode) |
Signal de notification :
| void | fragmentShaderCodeChanged(const QByteArray &fragmentShaderCode) |
geometryShaderCode : QByteArray
Contient le code du nuanceur géométrique utilisé par ce programme de nuanceur.
Fonctions d'accès :
| QByteArray | geometryShaderCode() const |
| void | setGeometryShaderCode(const QByteArray &geometryShaderCode) |
Signal de notification :
| void | geometryShaderCodeChanged(const QByteArray &geometryShaderCode) |
[read-only] log : QString
Contient le journal du programme de nuanceur en cours. Cette fonction est utile pour diagnostiquer un échec de compilation du programme de nuanceur.
Fonctions d'accès :
| QString | log() const |
Signal de notification :
| void | logChanged(const QString &log) |
[read-only] status : Status
Indique l'état du programme de nuanceur en cours.
Fonctions d'accès :
| Qt3DRender::QShaderProgram::Status | status() const |
Signal de notification :
| void | statusChanged(Qt3DRender::QShaderProgram::Status status) |
tessellationControlShaderCode : QByteArray
Contient le code du shader de contrôle de tesselation utilisé par ce programme de shader.
Fonctions d'accès :
| QByteArray | tessellationControlShaderCode() const |
| void | setTessellationControlShaderCode(const QByteArray &tessellationControlShaderCode) |
Signal de notification :
| void | tessellationControlShaderCodeChanged(const QByteArray &tessellationControlShaderCode) |
tessellationEvaluationShaderCode : QByteArray
Contient le code du shader d'évaluation de la tesselation utilisé par ce programme de shader.
Fonctions d'accès :
| QByteArray | tessellationEvaluationShaderCode() const |
| void | setTessellationEvaluationShaderCode(const QByteArray &tessellationEvaluationShaderCode) |
Signal du notificateur :
| void | tessellationEvaluationShaderCodeChanged(const QByteArray &tessellationEvaluationShaderCode) |
vertexShaderCode : QByteArray
Contient le code du nuanceur de vertex utilisé par ce programme de nuanceur.
Fonctions d'accès :
| QByteArray | vertexShaderCode() const |
| void | setVertexShaderCode(const QByteArray &vertexShaderCode) |
Signal de notification :
| void | vertexShaderCodeChanged(const QByteArray &vertexShaderCode) |
Fonction membre Documentation
[static invokable] QByteArray QShaderProgram::loadSource(const QUrl &sourceUrl)
Renvoie le code du shader chargé à partir de sourceUrl.
Remarque : cette fonction peut être invoquée via le système de méta-objets et à partir de QML. Voir Q_INVOKABLE.
void QShaderProgram::setShaderCode(Qt3DRender::QShaderProgram::ShaderType type, const QByteArray &shaderCode)
Définit le code du shader pour type du shader à shaderCode.
Voir aussi shaderCode().
QByteArray QShaderProgram::shaderCode(Qt3DRender::QShaderProgram::ShaderType type) const
Renvoie le code du shader pour type.
Voir aussi setShaderCode().
Qt3DRender::QShaderProgram::Status QShaderProgram::status() const
Renvoie le statut du programme de nuanceur en cours.
Remarque : fonction Getter pour l'état de la propriété.
© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.