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  · 

ShaderProgram

The ShaderProgram item is derivative class of the more general Effect class in QML/3d. Whereas the Effect class provides support for standard effects under OpenGL, the ShaderProgramEffect supports effects based on custom shader programs for the GPU. More...

Inherits Effect

ShaderProgram instantiates the C++ class ShaderProgram

This type was introduced in Qt 4.8.

Detailed Description

The ShaderProgram class provides Qml/3d users with the ability to use a QGLShaderProgram within the logical context of the normal Effect class provided by Qml/3d.

If the system does not support shaders, then ShaderProgram will behave the same as Effect, with support for simple lit materials only.

Attributes

ShaderProgram provides a standard set of 8 vertex attributes that can be provided via the geometry Mesh:

Shader VariableMesh AttributePurpose
qt_VertexQGL::PositionThe primary position of the vertex.
qt_NormalQGL::NormalThe normal at each vertex, for lit material effects.
qt_ColorQGL::ColorThe color at each vertex, for per-vertex color effects.
qt_MultiTexCoord0QGL::TextureCoord0The texture co-ordinate at each vertex for texture unit 0.
qt_MultiTexCoord1QGL::TextureCoord1Secondary texture co-ordinate at each vertex.
qt_MultiTexCoord2QGL::TextureCoord2Tertiary texture co-ordinate at each vertex.
qt_Custom0QGL::CustomVertex0First custom vertex attribute that can be used for any user-defined purpose.
qt_Custom1QGL::CustomVertex1Second custom vertex attribute that can be used for any user-defined purpose.

These attributes are used in the vertexShader, as in the following example of a simple texture shader:

 attribute highp vec4 qt_Vertex;
 attribute highp vec4 qt_MultiTexCoord0;
 uniform mediump mat4 qt_ModelViewProjectionMatrix;
 varying highp vec4 texCoord;

 void main(void)
 {
     gl_Position = qt_ModelViewProjectionMatrix * qt_Vertex;
     texCoord = qt_MultiTexCoord0;
 }

Standard uniform variables

ShaderProgram provides a standard set of uniform variables for common values from the environment:

Shader VariablePurpose
qt_ModelViewProjectionMatrixCombination of the modelview and projection matrices into a single 4x4 matrix.
qt_ModelViewMatrixModelview matrix without the projection. This is typically used for performing calculations in eye co-ordinates.
qt_ProjectionMatrixProjection matrix without the modelview.
qt_NormalMatrixNormal matrix, which is the transpose of the inverse of the top-left 3x3 part of the modelview matrix. This is typically used in lighting calcuations to transform qt_Normal.
qt_WorldMatrixModelview matrix without the eye position and orientation component. See QGLPainter::worldMatrix() for further information.
qt_Texture0Sampler holding the texture from the Effect::texture property.
qt_ColorSet to the value of the Effect::color property.

The above variables are usually declared in the shaders as follows (where highp may be replaced with mediump or lowp depending upon the shader's precision requirements):

 uniform highp mat4 qt_ModelViewProjectionMatrix;
 uniform highp mat4 qt_ModelViewMatrix;
 uniform highp mat3 qt_NormalMatrix;
 uniform sampler2D qt_Texture0;
 uniform highp vec4 qt_Color;

Other lighting and material values, such as the ambient, diffuse, and specular colors, can be passed to the shader program using custom uniform variables, or the standard variable names described in the QGLShaderProgramEffect documentation.

Custom uniform variables

Many properties defined on the ShaderProgram are automatically exposed as uniforms for the fragment and vertex shaders under the same name.

QML and shader types do not match exactly, so the following table shows how QML properties should be declared in qml compared to shader programs:

QML PropertyShader Program Variable
 property double myDouble : 1.0
uniform highp float myDouble;
 property real myReal : 1.0
uniform mediump float myReal;
 property bool myBoolean : true
uniform bool myBoolean;
 property int myInt : 1
uniform int myInt;
 property variant myPoint : Qt.point(1, 1)
uniform mediump vec2 myPoint;
 property variant myPointF : Qt.point(1.0, 1.0)
uniform mediump vec2 myPointF;
 property variant mySize : Qt.size(1.0, 1.0)
uniform mediump vec2 mySize;
 property color myColor : "#80c342"
uniform lowp vec4 myColor;
 property variant myMatrix3x3 :
            [1.0, 0.0, 0.0,
             0.0, 1.0, 0.0,
             0.0, 0.0, 1.0]
uniform mat3 myMatrix3x3;
 property variant myMatrix4x4 :
        [1.0 , 0.0, 0.0, 0.0,
        0.0, 1.0, 0.0, 0.0,
        0.0, 0.0, 1.0, 0.0,
        0.0, 0.0, 0.0, 1.0 ]
uniform mat4 myMatrix4x4;
 property string imageExample :
        "http://example.com/image.png"
uniform sampler2D imageExample;

Note: The precision hints in this table are just examples. highp, mediump, and lowp do not map directly onto floats, doubles, colors etc. Choose the most appropriate variable type for your qml or javascript, and the most appropriate precision for your shader program.

Be aware that variant properties in general and matrices in particular can have significant performance implications. Conversion from variants can be slow, and matrices can consume multiple slots for uniforms, which are usually limited by hardware.

String properties are assumed to be urls to images for use in textures. Where these images are remote, they are loaded in the background and bound to the effect when they are ready.

See also QGLGraphicsViewportItem.

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