/****************************************************************************
**
** Copyright (C) 2018 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt 3D Studio.
**
** $QT_BEGIN_LICENSE:FDL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Free Documentation License Usage
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of
** this file. Please review the following information to ensure
** the GNU Free Documentation License version 1.3 requirements
** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
** $QT_END_LICENSE$
**
****************************************************************************/
/*!
\title Effect Reference
\page effect-reference.html
\ingroup qt3dstudio-file-formats
This page explains how to write effects.
\section1 Overview
The effects specification allows writing custom effects, which are applied to
layers. The effects can have multiple passes to calculate the final result.
Each shader in a pass must implement the \c {void frag()} and \c {void vert()}
functions for fragment and vertex shader respectively. The passes are executed
in the order they are specified in the effect file. The studio shader library
can also be accessed with \c #include directive to add functionality.
\note Unlike custom materials, effects have full support for multiple render
passes in the Qt 3D Studio 2.0 runtime.
\section1 Effect Structure
\badcode
void vert()
{
}
void frag()
{
}
\endcode
The effect file structure follows the same pattern as custom materials, first is
the metadata with parameters in \c element, then effect shaders in
\c element and render passes in \c element.
\section1 Parameters
Effect metadata parameters are the same as for custom materials, but also have
a couple of effect-specific parameters. Parameters with \c Texture type and the
\c and \c elements allow using sampler-variables in
shader.
\note The Qt 3D Studio 2.0 runtime does not support other types of buffers
(shader storage buffers, indirect drawing, etc.). A temporary buffer specified
via the \c element maps to a texture. This can be bound to a sampler
variable in the shader via \c in the individual passes.
\section1 Elements
\section2
This element can be used to insert block of shader code that is shared among all shaders.
It gets inserted to all shaders in the effect.
\section2 and
These elements can be used to insert block of shader code that is shared among all vertex
and fragments shaders. The code inside \c element gets inserted to
all vertex shaders and similarly code inside \c element gets inserted
to all fragment shaders.
\section2 , and
The \c element specifies a shader with shader name specified with name attribute.
The name is used inside \c element to specify which shader to execute.
\c and \c elements are used to specify vertex shader code
and fragment shader code respectively. The vertex shader must implement the \c {void vert()}
function and fragment shader must implement the \c {void frag()} function, unless left empty.
The shader can use the \c varying, \c in and \c out specifiers to define custom variables
to pass parameters between shader stages.
\section2
The \c element is used to specify render passes for the effect. Each
render pass must be specified inside \c element. The \c element
can also contain \c elements to specify different kinds of data
storages for the effect.
\note In the Qt 3D Studio 2.0 runtime a buffer always maps to a texture.
\section2
This element can be used to create a buffer to be used inside the effect. Different passes
can read and write to these buffers while implementing different stages of the effect.
The \c element can be used to bind the buffer to shader variable so that it
can be read in shader.
The element attributes are:
\table
\header
\li attribute
\li values
\li description
\row
\li name
\li \c string
\li Used to specify unique name for the buffer.
\row
\li type
\li \list
\li \c ubyte - 8-bit unsigned integer
\li \c ushort - 16-bit unsigned integer
\li \c fp16 - 16-bit floating point number
\li \c fp32 - 32-bit floating point number
\endlist
\li Used to specify the type of the buffer.
\row
\li format
\li \list
\li \c source - take format from the source
\li \c depth24stencil8 - combined depth24 stencil 8
\li \c alpha - alpha
\li \c lum - luminance
\li \c lum_alpha - luminance alpha
\li \c rg - 2-component RG
\li \c rgb - 3-component RGB
\li \c rgba - 4-component RGBA
\endlist
\li Used to specify the format of the buffer.
\row
\li filter
\li \list
\li \c nearest - nearest neighbor
\li \c linear - linear interpolation
\endlist
\li Used to specify the input filtering mode.
\row
\li wrap
\li \list
\li \c clamp - clamp to edges
\li \c repeat - repeat values
\endlist
\li Used to specify the wrapping mode of the texture coordinates.
\row
\li size
\li \c float
\li Used to specify the size of the buffer relative to the frame buffer.
1.0 corresponds to same size. 0.5 corresponds to the buffer width and height
being half the size.
\row
\li lifetime
\li \list
\li \c scene - The buffer is allocated at the beginning of the scene
\li \c frame - The buffer is allocated at the beginning of the frame
\endlist
\li Used to specify how the buffer is allocated and deleted. Buffers with
\c frame lifetime can be reused by other effects.
\endtable
\section2
This element specifies one render pass in effect. The passes
are executed in the order they are specified in the effect file.
The element attributes are:
\table
\header
\li attribute
\li values
\li description
\row
\li shader
\li string
\li The name of the shader executed in this pass. Must match to a shader name
in the \c element.
\row
\li input
\li string
\li The name of one of the \c elements or [source].
\row
\li output
\li string
\li The name of one of the \c elements or [dest].
\row
\li format
\li \list
\li \c alpha - alpha
\li \c lum - luminance
\li \c lum_alpha - luminance alpha
\li \c rg - 2-component RG
\li \c rgb - 3-component RGB
\li \c rgba - 4-component RGBA
\endlist
\li If output is [dest], specifies the output format.
\endtable
\section2
This element binds a buffer (texture) to one of the shader sampler variables.
The element attributes are:
\table
\header
\li attribute
\li values
\li description
\row
\li value
\li string
\li The name of one of the \c elements or [source].
\row
\li param
\li string
\li The name of the shader variable.
\endtable
\section2
This element binds frame buffer depth as a texture to shader sampler variable.
The element attributes are:
\table
\header
\li attribute
\li values
\li description
\row
\li param
\li string
\li The name of the shader variable.
\endtable
\section2
This element can be used to set render pass specific shader parameters.
The parameter must match to a parameter specified in the \c element.
The element attributes are:
\table
\header
\li attribute
\li values
\li description
\row
\li name
\li string
\li The name of the property.
\row
\li value
\li float or integer
\li Specifies the value of the property.
\endtable
\section2
This element can be used to change the blending of the a render pass.
The element attributes are:
\table
\header
\li attribute
\li values
\li description
\row
\li dest
\li \list
\li \c SrcAlpha
\li \c OneMinusSrcAlpha
\li \c One
\endlist
\li Specifies the destination blending mode.
\row
\li source
\li \list
\li \c SrcAlpha
\li \c OneMinusSrcAlpha
\li \c One
\endlist
\li Specifies the source blending mode.
\endtable
\section2
This element can be used to enable/disable a render state for a pass.
The element attributes are:
\table
\header
\li attribute
\li values
\li description
\row
\li name
\li \list
\li \c Stencil
\li \c CullFace
\endlist
\li Name of the render state
\row
\li value
\li boolean
\li Specifies whether to enable or disable the render state.
\endtable
\section2
This element can be used to specify depth-stencil buffer and change the
depth-stencil test for a render pass.
The element attributes are:
\table
\header
\li attribute
\li values
\li description
\row
\li buffer
\li string
\li Name of the buffer used as a depth-stencil buffer.
\row
\li flags
\li \list
\li \c clear-stencil - Clear stencil buffer
\li \c clear-depth - Clear depth buffer
\endlist
\li Specifies flags for the element. These can be combined with logical or('|').
\row
\li stencil-fail
\li One of the stencil operation values
\li Specifies stencil fail operation.
\row
\li depth-fail
\li One of the stencil operation values
\li Specifies depth fail operation.
\row
\li depth-pass
\li One of the stencil operation values
\li Specifies depth pass operation.
\row
\li stencil-function
\li One of the boolean operator values
\li Specifies stencil function.
\row
\li reference
\li integer
\li Specifies stencil reference value.
\row
\li mask
\li integer
\li Specifies stencil mask value.
\endtable
The stencil operation values are:
\list
\li \c keep
\li \c zero
\li \c replace
\li \c increment
\li \c increment-wrap
\li \c decrement
\li \c decrement-wrap
\li \c invert
\endlist
The boolean operator values are:
\list
\li \c never
\li \c less
\li \c less-than-or-equal
\li \c equal
\li \c not-equal
\li \c greater
\li \c greater-than-or-equal
\li \c always
\endlist
\section2
This element can be used to select which faces are culled by CullFace.
The element attributes are:
\table
\header
\li attribute
\li values
\li description
\row
\li mode
\li \list
\li \c Back - Back faces.
\li \c Front - Front faces.
\li \c All - All faces.
\endlist
\li Specifies CullFace mode.
\endtable
*/