Merge "Merge branch 'tizen' into devel/new_mesh" into devel/new_mesh
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / devel-api / shader-effects / blind-effect.h
1 #ifndef __DALI_TOOLKIT_SHADER_EFFECT_BLIND_H__
2 #define __DALI_TOOLKIT_SHADER_EFFECT_BLIND_H__
3
4 /*
5  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/shader-effects/shader-effect.h>
23
24 namespace Dali
25 {
26
27 namespace Toolkit
28 {
29
30 /**
31  * @brief BlindEffect is a custom shader effect to achieve blind effects in Image actors
32  *
33  * Animatable/Constrainable uniforms:
34  *  "uStep" - The step of the blind effect.
35  *
36  * @return A handle to a newly allocated ShaderEffect
37  */
38
39 inline ShaderEffect CreateBlindEffect()
40 {
41   std::string fragmentShader(
42       "uniform mediump float uStep;                                                        \n"
43       "void main()                                                                         \n"
44       "{                                                                                   \n"
45       "    mediump vec4 alphaColor;                                                        \n"
46       "    mediump vec4 baseColor;                                                         \n"
47       "    baseColor = texture2D( sTexture, vTexCoord);                                    \n"
48       "    alphaColor = vec4(0.1,0.1,0.1,1.0);                                             \n"
49       "    lowp float index = 0.0;                                                         \n"
50       "    index = floor(vTexCoord.y/0.1);                                                 \n"
51       "    if((vTexCoord.y < (index * 0.1 + uStep * 0.005)) && (vTexCoord.y > index * 0.1))\n"
52       "    {                                                                               \n"
53       "      gl_FragColor = alphaColor;                                                    \n"
54       "    }                                                                               \n"
55       "    else                                                                            \n"
56       "    {                                                                               \n"
57       "      gl_FragColor = baseColor;                                                     \n"
58       "    }                                                                               \n"
59       "    gl_FragColor*=uColor;                                                           \n"
60       "}                                                                                   \n"
61   );
62
63   Dali::ShaderEffect shaderEffect =  Dali::ShaderEffect::New(
64       "",
65       fragmentShader,
66       GeometryType( GEOMETRY_TYPE_IMAGE ),
67       ShaderEffect::GeometryHints( ShaderEffect::HINT_BLENDING | ShaderEffect::HINT_GRID ));
68
69   shaderEffect.SetUniform( "uStep", 0.0f );
70
71   return shaderEffect;
72 }
73
74 } // namespace Toolkit
75
76 } // namespace Dali
77
78 #endif // __DALI_TOOLKIT_SHADER_EFFECT_BLIND_H__