Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
QSSGShaderUtils Namespace Reference

\qmltype Shader \inherits QtObject \inqmlmodule QtQuick3D More...

Classes

struct  ShaderType< QMetaType::Double >
struct  ShaderType< QMetaType::Bool >
struct  ShaderType< QMetaType::Int >
struct  ShaderType< QMetaType::QVector2D >
struct  ShaderType< QMetaType::QVector3D >
struct  ShaderType< QMetaType::QVector4D >
struct  ShaderType< QMetaType::QColor >
struct  ShaderType< QMetaType::QSize >
struct  ShaderType< QMetaType::QSizeF >
struct  ShaderType< QMetaType::QPoint >
struct  ShaderType< QMetaType::QPointF >
struct  ShaderType< QMetaType::QRect >
struct  ShaderType< QMetaType::QRectF >
struct  ShaderType< QMetaType::QQuaternion >
struct  ShaderType< QMetaType::QMatrix4x4 >
struct  ShaderType

Typedefs

using MetaTypeList = QList<QMetaType::Type>
using ResolveFunction = bool (*)(const QUrl &url, const QQmlContext *context, QByteArray &shaderData, QByteArray &shaderPathKey)

Functions

void setResolveFunction (ResolveFunction fn)
QByteArray resolveShader (const QUrl &fileUrl, const QQmlContext *context, QByteArray &shaderPathKey)
QByteArray uniformTypeName (QMetaType type)
QByteArray uniformTypeName (QSSGRenderShaderValue::Type type)
QSSGRenderShaderValue::Type uniformType (QMetaType type)
MetaTypeList supportedMetatypes ()

Variables

ResolveFunction resolveShaderOverride = nullptr
static constexpr QMetaType::Type qssg_metatype_list []

Detailed Description

\qmltype Shader \inherits QtObject \inqmlmodule QtQuick3D

Container component for defining shader code used by post-processing effects.

The Shader type is used for populating the \l{Pass::shaders}{shaders} list in the render \l{Pass}{pass} of an \l Effect.

A shader is code which is executed directly on the graphic hardware at a particular \l{Shader::stage}{stage} of the rendering pipeline.

See also
Effect

\qmlproperty url Shader::shader Specifies the name of the shader source file. For details on how to write shader code, see the \l Effect documentation.

Warning
Shader snippets are assumed to be trusted content. Application developers are advised to carefully consider the potential implications before allowing the loading of user-provided content that is not part of the application.

\qmlproperty enumeration Shader::stage Specifies the stage of the rendering pipeline when the shader code will be executed. The default is Shader.Fragment

\value Shader.Vertex The shader is a vertex shader. This code is run once per vertex in the input geometry and can be used to modify it before the geometry is rasterized (scan converted). In the case of effects, the input geometry is always a quad (four vertexes representing the corners of the render target). \value Shader.Fragment The shader is a fragment shader. After vertex processing, the modified geometry is turned into fragments (rasterization). Then a fragment shader is executed for each fragment, assigning a color to it. Fragments are a related concept to pixels, but with additional information attached. Also, as a result of some anti-aliasing strategies, there may be more than one fragment for each pixel in the output.

\qmltype TextureInput \inherits QtObject \inqmlmodule QtQuick3D

Specifies a texture exposed to the shaders of a CustomMaterial or Effect.

This is a type which can be used for exposing a \l Texture to a shader, either in the \l{Pass}{render pass} of an \l Effect, or in a \l CustomMaterial. It exists primarily to assign a local name to the \l Texture that can be referenced from shaders.

When a TextureInput property is declared in an \l Effect or a \l CustomMaterial, it will automatically be available as a sampler in all shaders by its property name.

\qmlproperty Texture TextureInput::texture The texture for which this TextureInput serves as an indirection.

\qmlproperty bool TextureInput::enabled The property determines if this TextureInput is enabled. The default value is true. When disabled, the shaders of the effect sample a dummy, opaque black texture instead of the one specified by \l texture.

\qmltype Pass \inherits QtObject \inqmlmodule QtQuick3D

Defines a render pass in an Effect.

An \l Effect may consist of multiple render passes. Each render pass has a setup phase where the list of \l{Pass::commands}{render commands} are executed, a \l{Pass::output}{output buffer} and a list of \l{Pass::shaders}{shaders} to use for rendering the effect.

See the documentation for \l Effect for more details on how to set up multiple rendering passes.

\qmlproperty Buffer Pass::output Specifies the output \l {Buffer}{buffer} of the pass.

\qmlproperty list Pass::commands Specifies the list of render \l {Command}{commands} of the pass.

\qmlproperty list Pass::shaders Specifies the list of \l {Shader}{shaders} of the pass.

\qmltype Command \inherits QtObject \inqmlmodule QtQuick3D

Supertype of commands to be performed as part of a pass in an Effect.

The Command type should not be instantiated by itself, but only exists as a polymorphic supertype for the different actions that can be performed as part of a \l{Pass}{render pass}.

See also
BufferInput, SetUniformValue, Effect

\qmltype BufferInput \inherits Command \inqmlmodule QtQuick3D

Defines an input buffer to be used as input for a pass of an Effect.

BufferInput is a \l Command which can be added to the list of commands in the \l Pass of an \l Effect. When executed, it will expose the buffer as a sample to the shaders in the render pass. The shaders must declare a sampler with the name given in the BufferInput's sampler property.

This can be used for sharing intermediate results between the different passes of an effect.

See also
TextureInput

\qmlproperty Buffer BufferInput::buffer Specifies the \l {Buffer}{buffer} which should be exposed to the shader.

\qmlproperty string BufferInput::sampler Specifies the name under which the buffer is exposed to the shader. When this property is not set, the buffer is exposed with the built-in name INPUT.

\qmltype Buffer \inherits QtObject \inqmlmodule QtQuick3D

Creates or references a color buffer to be used for a pass of an Effect.

A Buffer can be used to create intermediate buffers to share data between \l{Pass}{render passes} in an \l Effect.

Note
If the \l name property of the Buffer is empty, it will reference the default output texture of the render pass.

\qmlproperty enumeration Buffer::format Specifies the texture format. The default value is Buffer.RGBA8.

\value Buffer.RGBA8 \value Buffer.RGBA16F \value Buffer.RGBA32F \value Buffer.R8 \value Buffer.R16 \value Buffer.R16F \value Buffer.R32F

\qmlproperty enumeration Buffer::textureFilterOperation Specifies the texture filtering mode when sampling the contents of the Buffer. The default value is Buffer.Linear.

\value Buffer.Nearest Use nearest-neighbor filtering. \value Buffer.Linear Use linear filtering.

\qmlproperty enumeration Buffer::textureCoordOperation Specifies the behavior for texture coordinates when sampling outside the [0, 1] range. The default is Buffer.ClampToEdge.

\value Buffer.ClampToEdge Clamp coordinates to the edges. \value Buffer.Repeat Wrap the coordinates at the edges to tile the texture. \value Buffer.MirroredRepeat Wrap the coordinate at the edges, but mirror the texture when tiling it.

\qmlproperty real Buffer::sizeMultiplier Specifies the size multiplier of the buffer. For instance, a value of 1.0 creates a buffer with the same size as the effect's input texture while 0.5 creates buffer where both width and height is half as big. The default value is 1.0.

\qmlproperty enumeration Buffer::bufferFlags Specifies the buffer allocation flags. The default is Buffer.None.

\value Buffer.None No special behavior. \value Buffer.SceneLifetime The buffer is allocated for the whole lifetime of the scene.

\qmlproperty string Buffer::name Specifies the name of the buffer.

Note
When this property is empty, the Buffer will refer to the default output texture of the \l{Pass}{render pass} instead of allocating a buffer. This can be useful to override certain settings of the output, such as the texture format, without introducing a new, separate intermediate texture.

\qmltype SetUniformValue \inherits Command \inqmlmodule QtQuick3D

Defines a value to be set during a single \l {Pass}{pass}.

Since
5.15

SetUniformValue is a \l Command which can be added to the list of commands in a \l Pass. When executed, it will set the uniform given by the \l{SetUniformValue::target}{target} property to \l{SetUniformValue::value}{value}.

Note
The value set by this command is will only be set during the \l {Pass}{pass} it occurs in. For consecutive passes the value will be revert to the initial value of the uniform as it was defined in the \l Effect item.
See also
BufferInput

\qmlproperty string SetUniformValue::target Specifies the name of the uniform that will have its value changed during the \l {Pass}{pass}. This must match the name of an existing property in the \l Effect.

\qmlproperty Variant SetUniformValue::value Specifies the value that will be set on the target uniform.

\qmlvaluetype renderTargetBlend \inqmlmodule QtQuick3D

Defines blending parameters for a single color attachment of a render pass.

Since
6.11

The renderTargetBlend type is used to specify blending parameters for a single color attachment of a \l RenderPass. An instance of renderTargetBlend can be assigned to one of the \l PipelineStateOverride targetBlend0 through targetBlend7 properties, where the index corresponds to the color attachment slot.

The color blend equation is: \badcode result.rgb = srcColor * src.rgb opColor dstColor * dst.rgb result.a = srcAlpha * src.a opAlpha dstAlpha * dst.a

\qmlproperty bool renderTargetBlend::blendEnabled If set to true, enables blending for the color attachment. If set to false, disables blending and the output color is written directly to the attachment. The default value is false.

\qmlproperty enumeration renderTargetBlend::colorWrite A bitmask that controls which color channels are written to the color attachment. Multiple values can be combined with the | operator. The default value is {R | G | B | A}.

\value RenderTargetBlend.R Write to the red channel. \value RenderTargetBlend.G Write to the green channel. \value RenderTargetBlend.B Write to the blue channel. \value RenderTargetBlend.A Write to the alpha channel.

\qmlproperty enumeration renderTargetBlend::srcColor Sets the source color blend factor. This value scales the RGB components of the fragment shader output before the blend operation. The default value is One.

\value RenderTargetBlend.Zero Factor is (0, 0, 0). \value RenderTargetBlend.One Factor is (1, 1, 1). \value RenderTargetBlend.SrcColor Factor is the source color (r, g, b). \value RenderTargetBlend.OneMinusSrcColor Factor is (1-r, 1-g, 1-b) of the source. \value RenderTargetBlend.DstColor Factor is the destination color (r, g, b). \value RenderTargetBlend.OneMinusDstColor Factor is (1-r, 1-g, 1-b) of the destination. \value RenderTargetBlend.SrcAlpha Factor is the source alpha (a, a, a). \value RenderTargetBlend.OneMinusSrcAlpha Factor is (1-a, 1-a, 1-a) of the source. \value RenderTargetBlend.DstAlpha Factor is the destination alpha (a, a, a). \value RenderTargetBlend.OneMinusDstAlpha Factor is (1-a, 1-a, 1-a) of the destination. \value RenderTargetBlend.ConstantColor Factor is the constant color set on the pipeline. \value RenderTargetBlend.OneMinusConstantColor Factor is one minus the constant color. \value RenderTargetBlend.ConstantAlpha Factor is the constant alpha. \value RenderTargetBlend.OneMinusConstantAlpha Factor is one minus the constant alpha. \value RenderTargetBlend.SrcAlphaSaturate Factor is min(src.a, 1-dst.a) for RGB, 1 for A. \value RenderTargetBlend.Src1Color Factor is from the second color output of the fragment shader. \value RenderTargetBlend.OneMinusSrc1Color Factor is one minus the second color output. \value RenderTargetBlend.Src1Alpha Factor is the alpha of the second color output. \value RenderTargetBlend.OneMinusSrc1Alpha Factor is one minus the alpha of the second output.

\qmlproperty enumeration renderTargetBlend::dstColor Sets the destination color blend factor. This value scales the RGB components of the current value in the color attachment before the blend operation. The default value is OneMinusSrcAlpha. See srcColor for the list of available values.

\qmlproperty enumeration renderTargetBlend::opColor Sets the arithmetic operation used to combine the scaled source and destination color components. The default value is Add.

\value RenderTargetBlend.Add Result = src + dst. \value RenderTargetBlend.Subtract Result = src - dst. \value RenderTargetBlend.ReverseSubtract Result = dst - src. \value RenderTargetBlend.Min Result = min(src, dst). \value RenderTargetBlend.Max Result = max(src, dst).

\qmlproperty enumeration renderTargetBlend::srcAlpha Sets the source alpha blend factor. This value scales the alpha component of the fragment shader output before the blend operation. The default value is One. See srcColor for the list of available values.

\qmlproperty enumeration renderTargetBlend::dstAlpha Sets the destination alpha blend factor. This value scales the alpha component of the current value in the color attachment before the blend operation. The default value is OneMinusSrcAlpha. See srcColor for the list of available values.

\qmlproperty enumeration renderTargetBlend::opAlpha Sets the arithmetic operation used to combine the scaled source and destination alpha components. The default value is Add. See opColor for the list of available values.

\qmltype PipelineStateOverride \inherits Command \inqmlmodule QtQuick3D

Defines pipeline state overrides for a single \l {RenderPass}{pass}.

Since
6.11

PipelineStateOverride is a \l Command which can be added to the list of commands in a \l RenderPass. When executed, it will override the pipeline state in the render pass according to the properties set on the PipelineStateOverride. Only values that are set will override the existing pipeline state's values. If you want to reset a value that has been overridden to the default, then set the property to undefined.

See also
renderTargetBlend
\qmltype DepthStencilAttachment
\inherits Command
\inqmlmodule QtQuick3D
\brief Defines a depth-stencil attachment for a RenderPass.
\since 6.11

DepthStencilAttachment adds an implicit depth/stencil render buffer to a
\l RenderPass. The render buffer is automatically created and managed by the
rendering system. Because it is backed by an opaque render buffer rather
than a texture, its contents cannot be sampled in shaders. If you need to
read back depth values in a later pass, use \l DepthTextureAttachment instead.

Use DepthStencilAttachment when you need depth testing and/or stencil
operations in a pass but do not need to access the depth data afterwards.

\qml
RenderPass {
    commands: [
        ColorAttachment { name: "color0"; target: colorTexture },

Add a depth buffer so depth testing works in this pass DepthStencilAttachment {} ] } \endqml

See also
DepthTextureAttachment, RenderPassTexture

Typedef Documentation

◆ MetaTypeList

◆ ResolveFunction

using QSSGShaderUtils::ResolveFunction = bool (*)(const QUrl &url, const QQmlContext *context, QByteArray &shaderData, QByteArray &shaderPathKey)

Definition at line 38 of file qquick3dshaderutils_p.h.

Function Documentation

◆ resolveShader()

QByteArray QSSGShaderUtils::resolveShader ( const QUrl & fileUrl,
const QQmlContext * context,
QByteArray & shaderPathKey )

Definition at line 411 of file qquick3dshaderutils.cpp.

References resolveShaderOverride.

◆ setResolveFunction()

void QSSGShaderUtils::setResolveFunction ( ResolveFunction fn)

Definition at line 406 of file qquick3dshaderutils.cpp.

References resolveShaderOverride.

◆ supportedMetatypes()

MetaTypeList QSSGShaderUtils::supportedMetatypes ( )

Definition at line 676 of file qquick3dshaderutils.cpp.

◆ uniformType()

QSSGRenderShaderValue::Type QSSGShaderUtils::uniformType ( QMetaType type)

Definition at line 637 of file qquick3dshaderutils.cpp.

◆ uniformTypeName() [1/2]

QByteArray QSSGShaderUtils::uniformTypeName ( QMetaType type)

Definition at line 560 of file qquick3dshaderutils.cpp.

◆ uniformTypeName() [2/2]

QByteArray QSSGShaderUtils::uniformTypeName ( QSSGRenderShaderValue::Type type)

Definition at line 599 of file qquick3dshaderutils.cpp.

Variable Documentation

◆ qssg_metatype_list

constexpr QMetaType::Type QSSGShaderUtils::qssg_metatype_list
staticconstexpr
Initial value:
{
QMetaType::Double,
QMetaType::Bool,
QMetaType::QVector2D,
QMetaType::QVector3D,
QMetaType::QVector4D,
QMetaType::Int,
QMetaType::QColor,
QMetaType::QSize,
QMetaType::QSizeF,
QMetaType::QPoint,
QMetaType::QPointF,
QMetaType::QRect,
QMetaType::QRectF,
QMetaType::QQuaternion,
QMetaType::QMatrix4x4
}

Definition at line 437 of file qquick3dshaderutils.cpp.

◆ resolveShaderOverride

ResolveFunction QSSGShaderUtils::resolveShaderOverride = nullptr

Definition at line 404 of file qquick3dshaderutils.cpp.

Referenced by resolveShader(), and setResolveFunction().