1 /*! \page shader-intro Shader Effects
4 * <h2 class="pg">Introduction</h2>
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.
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.
14 * To set a custom shader to ImageRenderer you have to pass it through as a Property::Map
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
25 * mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);\n
26 * vertexPosition.xyz *= uSize;\n
27 * vertexPosition = uMvpMatrix * vertexPosition;\n
29 * vTexCoord = aPosition + vec2(0.5);\n
30 * gl_Position = vertexPosition;\n
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
42 * gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n
46 * Property::Map customShader;
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
52 * map.Insert(“shader”, customShader);
54 * ImageView imageView = ImageView::New("image-url.png")
55 * imageView.SetProperty(ImageView::Property::IMAGE, map);
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.
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
65 * //shader hints can be an array or a string
66 * optional array of shader hints
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);
75 * //or optional single shader hint as a string
76 * //customShader.Insert(“hints”, “output-is-transparent”);
79 * The value of a uniform can be set on the imageView
81 * // if the uniform was declared like this in the shader: uniform float myUniform;
82 * imageView.RegisterProperty( "myUniform", 0.5f );