| 1 |
/**************************************************************************** |
| 2 |
** |
| 3 |
** Copyright (C) 2017 The Qt Company Ltd. |
| 4 |
** Contact: https://www.qt.io/licensing/ |
| 5 |
** |
| 6 |
** This file is part of the documentation of the Qt Toolkit. |
| 7 |
** |
| 8 |
** $QT_BEGIN_LICENSE:FDL$ |
| 9 |
** Commercial License Usage |
| 10 |
** Licensees holding valid commercial Qt licenses may use this file in |
| 11 |
** accordance with the commercial license agreement provided with the |
| 12 |
** Software or, alternatively, in accordance with the terms contained in |
| 13 |
** a written agreement between you and The Qt Company. For licensing terms |
| 14 |
** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 |
** information use the contact form at https://www.qt.io/contact-us. |
| 16 |
** |
| 17 |
** GNU Free Documentation License Usage |
| 18 |
** Alternatively, this file may be used under the terms of the GNU Free |
| 19 |
** Documentation License version 1.3 as published by the Free Software |
| 20 |
** Foundation and appearing in the file included in the packaging of |
| 21 |
** this file. Please review the following information to ensure |
| 22 |
** the GNU Free Documentation License version 1.3 requirements |
| 23 |
** will be met: https://www.gnu.org/licenses/fdl-1.3.html. |
| 24 |
** $QT_END_LICENSE$ |
| 25 |
** |
| 26 |
****************************************************************************/ |
| 27 |
/*! |
| 28 |
\title Qt Quick Examples - Shader Effects |
| 29 |
\example shadereffects |
| 30 |
\image qml-shadereffects-example.png |
| 31 |
\brief A Qt Quick example demonstrating the use of shader effects. |
| 32 |
\ingroup qtquickexamples |
| 33 |
|
| 34 |
This example demonstrates a couple of visual effects that you can perform |
| 35 |
with shaders in Qt Quick. It applies five different effects on a text and |
| 36 |
a couple of images. For more information, visit |
| 37 |
\l{Important Concepts In Qt Quick - Graphical Effects} |
| 38 |
|
| 39 |
\include examples-run.qdocinc |
| 40 |
|
| 41 |
\section1 Using ShaderEffect |
| 42 |
|
| 43 |
The \l ShaderEffect type typically operates on other types, using a |
| 44 |
\l ShaderEffectSource: |
| 45 |
\snippet shadereffects/shadereffects.qml source |
| 46 |
|
| 47 |
In the above snippet, \c theItem is the ID of a complex QML object in the |
| 48 |
file. |
| 49 |
|
| 50 |
ShaderEffects can use this ShaderEffectSource as a texture in their fragment |
| 51 |
shader: |
| 52 |
\snippet shadereffects/shadereffects.qml fragment |
| 53 |
|
| 54 |
In order to support multiple graphics APIs, not just OpenGL, the shader |
| 55 |
source is not embedded into QML. When running with the graphics API |
| 56 |
independent scene graph, the actual file in use is a pre-generated shader |
| 57 |
pack containing multiple variants of the shader code. The appropriate |
| 58 |
shader is then chosen by Qt Quick, regardless of running on Vulkan, Metal, |
| 59 |
Direct 3D, or OpenGL. Qt automatically selects the file under the \c qsb |
| 60 |
selector, for example \c{shaders/+qsb/wobble.frag}, when present. |
| 61 |
|
| 62 |
On the traditional code path, which can mean using OpenGL or Direct3D 12, |
| 63 |
file selectors are used to select the correct variant at runtime. Based on |
| 64 |
the Qt Quick backend in use, Qt will automatically select either |
| 65 |
\c{shaders/wobble.frag} with the GLSL source code or |
| 66 |
\c{shaders/+hlsl/wobble.frag} with the HLSL source code. |
| 67 |
|
| 68 |
\note For simplicity shader source code is used in all variants of the |
| 69 |
files. However, with the Direct3D backend of Qt Quick pre-compiled shaders |
| 70 |
are also supported. For example, try the following commands in the |
| 71 |
\c{content/shaders/+hlsl} directory: \c{move wobble.frag wobble.frag.src} |
| 72 |
followed by \c{fxc /E main /T ps_5_0 /Fo wobble.frag wobble.frag.src}. Now |
| 73 |
\c wobble.frag contains Direct3D bytecode and that is what gets shipped |
| 74 |
with the application instead of the shader source. Further changes are not |
| 75 |
necessary, the application will function like before. |
| 76 |
|
| 77 |
You can use any custom property on the ShaderEffect in your shader. This |
| 78 |
makes animated shader code very easy: |
| 79 |
\snippet shadereffects/shadereffects.qml properties |
| 80 |
|
| 81 |
ShaderEffects can also have a custom vertext shader. Setting the mesh |
| 82 |
property on ShaderEffect provides more vertices for you to manipulate, |
| 83 |
enabling more effects. |
| 84 |
\snippet shadereffects/shadereffects.qml vertex |
| 85 |
*/ |