Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Classes principales  ·  Annotées  ·  Classes groupées  ·  Modules  ·  Fonctions  · 

ShaderEffect

The ShaderEffect element applies custom shaders to a rectangle. More...

Inherits Item

Properties

Detailed Description

The 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:

  • uniform mat4 qt_Matrix - combined transformation matrix, the product of the matrices from the root item to this ShaderEffect, and an orthogonal projection.
  • uniform float qt_Opacity - combined opacity, the product of the opacities from the root item to this ShaderEffect.
  • attribute vec4 qt_Vertex - vertex position, the top-left vertex has position (0, 0), the bottom-right (width, height).
  • attribute vec2 qt_MultiTexCoord0 - texture coordinate, the top-left coordinate is (0, 0), the bottom-right (1, 1).

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:

  • bool, int, qreal -> bool, int, float - If the type in the shader is not the same as in QML, the value is converted automatically.
  • QColor -> vec4 - When colors are passed to the shader, they are first premultiplied. Thus Qt.rgba(0.2, 0.6, 1.0, 0.5) becomes vec4(0.1, 0.3, 0.5, 0.5) in the shader, for example.
  • QRect, QRectF -> vec4 - Qt.rect(x, y, w, h) becomes vec4(x, y, w, h) in the shader.
  • QPoint, QPointF, QSize, QSizeF -> vec2
  • QVector3D -> vec3
  • QTransform -> mat4
  • Image, ShaderEffectSource -> sampler2D - Origin is in the top-left corner, and the color values are premultiplied.

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;
                 }"
         }
     }
 }

\endrow

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 Documentation

blending : bool

If 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.


cullMode : enumeration

This property defines which sides of the element should be visible.

The default is NoCulling.


fragmentShader : string

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".


read-onlylog : string

This property holds a log of warnings and errors from the latest attempt at compiling and linking the OpenGL shader program. It is updated at the same time status is set to Compiled or Error.

See also status.


mesh : variant

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.


read-onlystatus : enumeration

This property tells the current status of the OpenGL shader program.

  • ShaderEffect.Compiled - the shader program was successfully compiled and linked.
  • ShaderEffect.Uncompiled - the shader program has not yet been compiled.
  • ShaderEffect.Error - the shader program failed to compile or link.

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.


vertexShader : string

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".


Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt 5.0-snapshot
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web