4dd11a122b548def5b1f2313c226d7ee0fc1cc3f
[platform/core/uifw/dali-toolkit.git] / optional / dali-toolkit / public-api / shader-effects / blind-effect.cpp
1 //
2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://floralicense.org/license/
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 #include <dali-toolkit/public-api/shader-effects/blind-effect.h>
18
19 namespace Dali
20 {
21
22 namespace Toolkit
23 {
24
25 namespace
26 {
27
28 const std::string STEP_PROPERTY_NAME( "uStep" );
29
30 } // namespace
31
32 BlindEffect::BlindEffect()
33 {
34 }
35
36 //Call the Parent copy constructor to add reference to the implementation for this object
37 BlindEffect::BlindEffect(ShaderEffect handle)
38 :ShaderEffect(handle)
39 {
40 }
41
42 BlindEffect::~BlindEffect()
43 {
44 }
45
46
47 BlindEffect BlindEffect::New()
48 {
49   std::string fragmentShader(
50     "uniform float uStep;                                                                \n"
51     "void main()                                                                         \n"
52     "{                                                                                   \n"
53     "    vec4 alphaColor;                                                                \n"
54     "    vec4 baseColor;                                                                 \n"
55     "    baseColor = texture2D( sTexture, vTexCoord);                                    \n"
56     "    alphaColor = vec4(0.1,0.1,0.1,1.0);                                             \n"
57     "    float index = 0.0;                                                              \n"
58     "    index = floor(vTexCoord.y/0.1);                                                 \n"
59     "    if((vTexCoord.y < (index * 0.1 + uStep * 0.005)) && (vTexCoord.y > index * 0.1))\n"
60     "    {                                                                               \n"
61     "      gl_FragColor = alphaColor;                                                    \n"
62     "    }                                                                               \n"
63     "    else                                                                            \n"
64     "    {                                                                               \n"
65     "      gl_FragColor = baseColor;                                                     \n"
66     "    }                                                                               \n"
67     "    gl_FragColor*=uColor;                                                           \n"
68     "}                                                                                   \n"
69   );
70
71   Dali::ShaderEffect shaderEffectCustom =  Dali::ShaderEffect::New(
72       "",
73       fragmentShader,
74       Dali::GeometryType( GEOMETRY_TYPE_IMAGE ),
75       ShaderEffect::GeometryHints( ShaderEffect::HINT_BLENDING | ShaderEffect::HINT_GRID ));
76
77   Dali::Toolkit::BlindEffect handle( shaderEffectCustom );
78
79   handle.SetUniform( STEP_PROPERTY_NAME, 0.0f );
80
81   return handle;
82 }
83
84 void BlindEffect::SetStep(float step)
85 {
86   SetUniform( STEP_PROPERTY_NAME, step );
87 }
88
89 const std::string& BlindEffect::GetStepPropertyName() const
90 {
91   return STEP_PROPERTY_NAME;
92 }
93
94 } // namespace Toolkit
95
96 } // namespace Dali