Merge "DALi Version 1.1.10" into devel/master
[platform/core/uifw/dali-toolkit.git] / docs / content / programming-guide / shader-intro.h
1 /*! \page shader-intro Shader Effects
2  *
3  *
4  * <h2 class="pg">Introduction</h2>
5  *
6  * The shader effects allow the developer to apply visual deformations on Image Views.
7  * They can affect the geometry, the colors and textures of the Image View.
8  *
9  * <br>
10  * <br>
11  * <h2 class="pg">Custom Shader Effects</h2>
12  * The custom shader lets the developers create their own shader effects by specifying the vertex and pixel shaders.
13  *
14  * To set a custom shader to ImageRenderer you have to pass it through as a Property::Map
15  * @code
16  * //an example vertex shader
17  * const char* VERTEX_SHADER = DALI_COMPOSE_SHADER(
18  *   attribute mediump vec2 aPosition;\n
19  *   varying mediump vec2 vTexCoord;\n
20  *   uniform mediump mat4 uMvpMatrix;\n
21  *   uniform mediump vec3 uSize;\n
22  *   \n
23  *   void main()\n
24  *   {\n
25  *     mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);\n
26  *     vertexPosition.xyz *= uSize;\n
27  *     vertexPosition = uMvpMatrix * vertexPosition;\n
28  *     \n
29  *     vTexCoord = aPosition + vec2(0.5);\n
30  *     gl_Position = vertexPosition;\n
31  *   }\n
32  * );
33  *
34  * //an example fragment shader
35  * const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER(
36  *   varying mediump vec2 vTexCoord;\n
37  *   uniform sampler2D sTexture;\n
38  *   uniform lowp vec4 uColor;\n
39  *   \n
40  *   void main()\n
41  *   {\n
42  *     gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n
43  *   }\n
44  * );
45  *
46  * Property::Map customShader;
47  *
48  * customShader.Insert(“vertex-shader”, VERTEX_SHADER); //if this is not set then the default ImageView vertex shader will be used
49  * customShader.Insert(“fragment-shader”, FRAGMENT_SHADER); //if this is not set then the default ImageView fragment shader will be used
50  *
51  * Property::Map map;
52  * map.Insert(“shader”, customShader);
53  *
54  * ImageView imageView = ImageView::New("image-url.png")
55  * imageView.SetProperty(ImageView::Property::IMAGE, map);
56  * @endcode
57  *
58  * Optionally, you can subdivide the grid horizontally or vertically before you add it to the map but you should not do this if a quad is used.
59  * @code
60  * int X_SUB_DIVISIONS = 20;
61  * int Y_SUB_DIVISIONS = 20;
62  * customShader.Insert(“subdivide-grid-x”, X_SUB_DIVISIONS); //optional number of times to subdivide the grid horizontally, don’t add if you just want to use a quad
63  * customShader.Insert(“subdivide-grid-y”, Y_SUB_DIVISIONS); //optional number of times to subdivide the grid vertically, don’t add if you just want to use a quad
64  *
65  * //shader hints can be an array or a string
66  * optional array of shader hints
67  *
68  * Property::Array shaderHints;
69  * shaderHints.PushBack(“requires-self-depth-test”);
70  * shaderHints.PushBack(“output-is-transparent”);
71  * shaderHints.PushBack(“output-is-opaque”);
72  * shaderHints.PushBack(“modifies-geometry”);
73  * customShader.Insert(“hints”, shaderHints);
74  *
75  * //or optional single shader hint as a string
76  * //customShader.Insert(“hints”, “output-is-transparent”);
77  * @endcode
78  *
79  * The value of a uniform can be set on the imageView
80  * @code
81  * // if the uniform was declared like this in the shader: uniform float myUniform;
82  * imageView.RegisterProperty( "myUniform", 0.5f );
83  * @endcode
84  *
85  *
86  */