ShaderEffectThe ShaderEffect element applies custom shaders to a rectangle. More... Inherits Item Properties
Detailed DescriptionThe ShaderEffect element applies a custom OpenGL vertex and fragment shader to a rectangle. It allows you to write effects such as drop shadow, blur, colorize and page curl directly in QML. There are two types of input to the vertexShader: uniform variables and attributes. Some are predefined:
In addition, any property that can be mapped to an OpenGL Shading Language (GLSL) type is available as a uniform variable. The following list shows how properties are mapped to GLSL uniform variables:
The output from the fragmentShader should be premultiplied. If blending is enabled, source-over blending is used. However, additive blending can be achieved by outputting zero in the alpha channel. [Missing image declarative-shadereffectitem.png] import QtQuick 2.0 Rectangle { width: 200; height: 100 Row { Image { id: img; sourceSize { width: 100; height: 100 } source: "qt-logo.png" } ShaderEffect { width: 100; height: 100 property variant src: img vertexShader: " uniform highp mat4 qt_Matrix; attribute highp vec4 qt_Vertex; attribute highp vec2 qt_MultiTexCoord0; varying highp vec2 coord; void main() { coord = qt_MultiTexCoord0; gl_Position = qt_Matrix * qt_Vertex; }" fragmentShader: " varying highp vec2 coord; uniform sampler2D src; uniform lowp float qt_Opacity; void main() { lowp vec4 tex = texture2D(src, coord); gl_FragColor = vec4(vec3(dot(tex.rgb, vec3(0.344, 0.5, 0.156))), tex.a) * qt_Opacity; }" } } }
By default, the ShaderEffect consists of four vertices, one for each corner. For non-linear vertex transformations, like page curl, you can specify a fine grid of vertices by specifying a mesh resolution. Note: Scene Graph textures have origin in the top-left corner rather than bottom-left which is common in OpenGL. Property DocumentationIf this property is true, the output from the fragmentShader is blended with the background using source-over blend mode. If false, the background is disregarded. Blending decreases the performance, so you should set this property to false when blending is not needed. The default value is true. This property defines which sides of the element should be visible.
The default is NoCulling. This property holds the fragment shader's GLSL source code. The default shader passes the texture coordinate along to the fragment shader as "varying highp vec2 qt_TexCoord0". This property defines the mesh used to draw the ShaderEffect. It can hold any mesh object deriving from QQuickShaderEffectMesh, such as GridMesh. If a size value is assigned to this property, the ShaderEffect implicitly uses a GridMesh with the value as mesh resolution. By default, this property is the size 1x1. See also GridMesh. This property tells the current status of the OpenGL shader program.
When setting the fragment or vertex shader source code, the status will become Uncompiled. The first time the ShaderEffect is rendered with new shader source code, the shaders are compiled and linked, and the status is updated to Compiled or Error. See also log. This property holds the vertex shader's GLSL source code. The default shader expects the texture coordinate to be passed from the vertex shader as "varying highp vec2 qt_TexCoord0", and it samples from a sampler2D named "source". |