QShaderProgram#

Encapsulates a Shader Program. More

Inheritance diagram of PySide6.Qt3DRender.Qt3DRender.QShaderProgram

Synopsis#

Properties#

Functions#

Slots#

Signals#

Static functions#

Note

This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE

Detailed Description#

A shader program consists of several different shaders, such as vertex and fragment shaders.

Qt3D will automatically populate a set of default uniforms if they are encountered during the shader instrospection phase.

Default Uniform

Associated Qt3D Parameter name

GLSL declaration

ModelMatrix

modelMatrix

uniform mat4 modelMatrix;

ViewMatrix

viewMatrix

uniform mat4 viewMatrix;

ProjectionMatrix

projectionMatrix

uniform mat4 projectionMatrix;

ModelViewMatrix

modelView

uniform mat4 modelView;

ViewProjectionMatrix

viewProjectionMatrix

uniform mat4 viewProjectionMatrix;

ModelViewProjectionMatrix

modelViewProjection mvp

uniform mat4 modelViewProjection; uniform mat4 mvp;

InverseModelMatrix

inverseModelMatrix

uniform mat4 inverseModelMatrix;

InverseViewMatrix

inverseViewMatrix

uniform mat4 inverseViewMatrix;

InverseProjectionMatrix

inverseProjectionMatrix

uniform mat4 inverseProjectionMatrix;

InverseModelViewMatrix

inverseModelView

uniform mat4 inverseModelView;

InverseViewProjectionMatrix

inverseViewProjectionMatrix

uniform mat4 inverseViewProjectionMatrix;

InverseModelViewProjectionMatrix

inverseModelViewProjection

uniform mat4 inverseModelViewProjection;

ModelNormalMatrix

modelNormalMatrix

uniform mat3 modelNormalMatrix;

ModelViewNormalMatrix

modelViewNormal

uniform mat3 modelViewNormal;

ViewportMatrix

viewportMatrix

uniform mat4 viewportMatrix;

InverseViewportMatrix

inverseViewportMatrix

uniform mat4 inverseViewportMatrix;

AspectRatio (surface width / surface height)

aspectRatio

uniform float aspectRatio;

Exposure

exposure

uniform float exposure;

Gamma

gamma

uniform float gamma;

Time (in nano seconds)

time

uniform float time;

EyePosition

eyePosition

uniform vec3 eyePosition;

SkinningPalette

skinningPalette[0]

const int maxJoints = 100; uniform mat4 skinningPalette[maxJoints];

RHI Support#

When writing GLSL 450 shader code to use with Qt 3D’s RHI backend, the default uniforms will be provided as 2 uniform buffer objects.

The binding locations for these is set to bindings 0 for RenderView uniforms and 1 for Command uniforms.

#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);
}

For user defined uniform buffer object, use binding starting at 2 or auto to let Qt 3D work out the binding automatically. Make sure to remain consistent between the different shader stages.

#version 450 core

layout(std140, binding = auto) uniform my_uniforms {
  vec4 myColor;
};

layout(location=0) out vec4 fragColor;

void main()
{
    fragColor = myColor;
}

There is no change involved when it comes to feeding values to uniforms.

For the above example, setting myColor could be done with:

QParameter *parameter = new QParameter();
parameter->setName("myColor");
parameter->setValue(QVariant::fromValue(QColor(Qt::blue)));

Textures still have to be defined as standalone uniforms.

#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));
}
class PySide6.Qt3DRender.Qt3DRender.QShaderProgram([parent=None])#
Parameters:

parentPySide6.Qt3DCore.Qt3DCore.QNode

Note

Properties can be used directly when from __feature__ import true_property is used or via accessor functions otherwise.

property PᅟySide6.Qt3DRender.Qt3DRender.QShaderProgram.computeShaderCode: PySide6.QtCore.QByteArray#

Holds the compute shader code used by this shader program.

Access functions:
property PᅟySide6.Qt3DRender.Qt3DRender.QShaderProgram.format: Format#

Holds the format of the code provided on the ShaderProgram . The default is ShaderProgram .GLSL

Access functions:
property PᅟySide6.Qt3DRender.Qt3DRender.QShaderProgram.fragmentShaderCode: PySide6.QtCore.QByteArray#

Holds the fragment shader code used by this shader program.

Access functions:
property PᅟySide6.Qt3DRender.Qt3DRender.QShaderProgram.geometryShaderCode: PySide6.QtCore.QByteArray#

Holds the geometry shader code used by this shader program.

Access functions:
property PᅟySide6.Qt3DRender.Qt3DRender.QShaderProgram.log: str#

Holds the log of the current shader program. This is useful to diagnose a compilation failure of the shader program.

Access functions:
property PᅟySide6.Qt3DRender.Qt3DRender.QShaderProgram.status: Status#

Holds the status of the current shader program.

Access functions:
property PᅟySide6.Qt3DRender.Qt3DRender.QShaderProgram.tessellationControlShaderCode: PySide6.QtCore.QByteArray#

Holds the tesselation control shader code used by this shader program.

Access functions:
property PᅟySide6.Qt3DRender.Qt3DRender.QShaderProgram.tessellationEvaluationShaderCode: PySide6.QtCore.QByteArray#

Holds the tesselation evaluation shader code used by this shader program.

Access functions:
property PᅟySide6.Qt3DRender.Qt3DRender.QShaderProgram.vertexShaderCode: PySide6.QtCore.QByteArray#

Holds the vertex shader code used by this shader program.

Access functions:
PySide6.Qt3DRender.Qt3DRender.QShaderProgram.ShaderType#

This enum identifies the type of shader used.

Constant

Description

Qt3DRender.QShaderProgram.Vertex

Vertex shader

Qt3DRender.QShaderProgram.Fragment

Fragment shader

Qt3DRender.QShaderProgram.TessellationControl

Tesselation control shader

Qt3DRender.QShaderProgram.TessellationEvaluation

Tesselation evaluation shader

Qt3DRender.QShaderProgram.Geometry

Geometry shader

Qt3DRender.QShaderProgram.Compute

Compute shader

PySide6.Qt3DRender.Qt3DRender.QShaderProgram.Status#

This enum identifies the status of shader used.

Constant

Description

Qt3DRender.QShaderProgram.NotReady

The shader hasn’t been compiled and linked yet

Qt3DRender.QShaderProgram.Ready

The shader was successfully compiled

Qt3DRender.QShaderProgram.Error

An error occurred while compiling the shader

PySide6.Qt3DRender.Qt3DRender.QShaderProgram.Format#

This enum identifies the format of the shader code used.

Constant

Description

Qt3DRender.QShaderProgram.GLSL

OpenGL

Qt3DRender.QShaderProgram.SPIRV

Vulkan, OpenGL 5

PySide6.Qt3DRender.Qt3DRender.QShaderProgram.computeShaderCode()#
Return type:

PySide6.QtCore.QByteArray

Getter of property computeShaderCode .

PySide6.Qt3DRender.Qt3DRender.QShaderProgram.computeShaderCodeChanged(computeShaderCode)#
Parameters:

computeShaderCodePySide6.QtCore.QByteArray

Notification signal of property computeShaderCode .

PySide6.Qt3DRender.Qt3DRender.QShaderProgram.format()#
Return type:

Format

See also

setFormat()

Getter of property format .

PySide6.Qt3DRender.Qt3DRender.QShaderProgram.formatChanged(format)#
Parameters:

formatFormat

Notification signal of property format .

PySide6.Qt3DRender.Qt3DRender.QShaderProgram.fragmentShaderCode()#
Return type:

PySide6.QtCore.QByteArray

Getter of property fragmentShaderCode .

PySide6.Qt3DRender.Qt3DRender.QShaderProgram.fragmentShaderCodeChanged(fragmentShaderCode)#
Parameters:

fragmentShaderCodePySide6.QtCore.QByteArray

Notification signal of property fragmentShaderCode .

PySide6.Qt3DRender.Qt3DRender.QShaderProgram.geometryShaderCode()#
Return type:

PySide6.QtCore.QByteArray

Getter of property geometryShaderCode .

PySide6.Qt3DRender.Qt3DRender.QShaderProgram.geometryShaderCodeChanged(geometryShaderCode)#
Parameters:

geometryShaderCodePySide6.QtCore.QByteArray

Notification signal of property geometryShaderCode .

static PySide6.Qt3DRender.Qt3DRender.QShaderProgram.loadSource(sourceUrl)#
Parameters:

sourceUrlPySide6.QtCore.QUrl

Return type:

PySide6.QtCore.QByteArray

Returns the shader code loaded from sourceUrl.

PySide6.Qt3DRender.Qt3DRender.QShaderProgram.log()#
Return type:

str

Getter of property log .

PySide6.Qt3DRender.Qt3DRender.QShaderProgram.logChanged(log)#
Parameters:

log – str

Notification signal of property log .

PySide6.Qt3DRender.Qt3DRender.QShaderProgram.setComputeShaderCode(computeShaderCode)#
Parameters:

computeShaderCodePySide6.QtCore.QByteArray

Setter of property computeShaderCode .

PySide6.Qt3DRender.Qt3DRender.QShaderProgram.setFormat(format)#
Parameters:

formatFormat

See also

format()

Setter of property format .

PySide6.Qt3DRender.Qt3DRender.QShaderProgram.setFragmentShaderCode(fragmentShaderCode)#
Parameters:

fragmentShaderCodePySide6.QtCore.QByteArray

Setter of property fragmentShaderCode .

PySide6.Qt3DRender.Qt3DRender.QShaderProgram.setGeometryShaderCode(geometryShaderCode)#
Parameters:

geometryShaderCodePySide6.QtCore.QByteArray

Setter of property geometryShaderCode .

PySide6.Qt3DRender.Qt3DRender.QShaderProgram.setShaderCode(type, shaderCode)#
Parameters:

Sets the shader code for type of shader to the shaderCode.

See also

shaderCode()

PySide6.Qt3DRender.Qt3DRender.QShaderProgram.setTessellationControlShaderCode(tessellationControlShaderCode)#
Parameters:

tessellationControlShaderCodePySide6.QtCore.QByteArray

Setter of property tessellationControlShaderCode .

PySide6.Qt3DRender.Qt3DRender.QShaderProgram.setTessellationEvaluationShaderCode(tessellationEvaluationShaderCode)#
Parameters:

tessellationEvaluationShaderCodePySide6.QtCore.QByteArray

Setter of property tessellationEvaluationShaderCode .

PySide6.Qt3DRender.Qt3DRender.QShaderProgram.setVertexShaderCode(vertexShaderCode)#
Parameters:

vertexShaderCodePySide6.QtCore.QByteArray

Setter of property vertexShaderCode .

PySide6.Qt3DRender.Qt3DRender.QShaderProgram.shaderCode(type)#
Parameters:

typeShaderType

Return type:

PySide6.QtCore.QByteArray

Returns the shader code for type.

See also

setShaderCode()

PySide6.Qt3DRender.Qt3DRender.QShaderProgram.status()#
Return type:

Status

Returns the status of the current shader program.

Getter of property status .

PySide6.Qt3DRender.Qt3DRender.QShaderProgram.statusChanged(status)#
Parameters:

statusStatus

Notification signal of property status .

PySide6.Qt3DRender.Qt3DRender.QShaderProgram.tessellationControlShaderCode()#
Return type:

PySide6.QtCore.QByteArray

Getter of property tessellationControlShaderCode .

PySide6.Qt3DRender.Qt3DRender.QShaderProgram.tessellationControlShaderCodeChanged(tessellationControlShaderCode)#
Parameters:

tessellationControlShaderCodePySide6.QtCore.QByteArray

Notification signal of property tessellationControlShaderCode .

PySide6.Qt3DRender.Qt3DRender.QShaderProgram.tessellationEvaluationShaderCode()#
Return type:

PySide6.QtCore.QByteArray

Getter of property tessellationEvaluationShaderCode .

PySide6.Qt3DRender.Qt3DRender.QShaderProgram.tessellationEvaluationShaderCodeChanged(tessellationEvaluationShaderCode)#
Parameters:

tessellationEvaluationShaderCodePySide6.QtCore.QByteArray

Notification signal of property tessellationEvaluationShaderCode .

PySide6.Qt3DRender.Qt3DRender.QShaderProgram.vertexShaderCode()#
Return type:

PySide6.QtCore.QByteArray

Getter of property vertexShaderCode .

PySide6.Qt3DRender.Qt3DRender.QShaderProgram.vertexShaderCodeChanged(vertexShaderCode)#
Parameters:

vertexShaderCodePySide6.QtCore.QByteArray

Notification signal of property vertexShaderCode .