Remove/Move experimental features
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / devel-api / shader-effects / mirror-effect.h
1 #ifndef __DALI_TOOLKIT_MIRROR_EFFECT_H__
2 #define __DALI_TOOLKIT_MIRROR_EFFECT_H__
3
4 /*
5  * Copyright (c) 2016 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/devel-api/shader-effects/shader-effect.h>
23
24 namespace Dali
25 {
26
27 namespace Toolkit
28 {
29
30 /**
31  * @brief Creates a new MirrorEffect
32  *
33  * MirrorEffect is a custom shader effect to achieve square effects in Image actors
34  *
35  * Animatable/Constrainable uniforms:
36  *  "uDepth"  - The depth of the mirror effect. Default value 0.5
37  *  "uAlpha"  - The alpha of the mirror effect. Default value 1.0
38  *
39  * @return A handle to a newly allocated ShaderEffect
40  */
41 inline ShaderEffect CreateMirrorEffect()
42 {
43   std::string vertexShader(
44       "void main()                                  \n"
45       "{                                            \n"
46       "  mediump vec3 pos = aPosition;              \n"
47       "  pos.y = pos.y * 3.0;                       \n"
48       "  mediump vec4 world = uModelView * vec4(pos,1.0); \n"
49       "  gl_Position = uProjection * world;         \n"
50       "  vTexCoord = mix( sTextureRect.xy, sTextureRect.zw, aTexCoord ); \n"
51       "}                                            \n" );
52
53   std::string fragmentShader(
54       "uniform  mediump float  uDepth;              \n"
55       "uniform  mediump float  uAlpha;              \n"
56       "void main()                                  \n"
57       "{                                            \n"
58       " if(vTexCoord.y < 1.0 / 3.0)                 \n"
59       " {                                           \n"
60       "   gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);  \n"
61       " }                                           \n"
62       " else if(vTexCoord.y < 2.0 / 3.0)            \n"
63       " {                                           \n"
64       "   gl_FragColor = texture2D(sTexture, vec2(vTexCoord.x, vTexCoord.y * 3.0 - 1.0)) * uColor;    \n"
65       "   gl_FragColor.a *= uAlpha;                 \n"
66       " }                                           \n"
67       " else                                        \n"
68       " {                                           \n"
69       "   highp float darkness = 3.0 - vTexCoord.y * 3.0;                                                   \n"
70       "   darkness = (1.0 - 1.0 / uDepth + darkness * 1.0/ uDepth) * 0.65;                            \n"
71       "   highp vec4 color = texture2D(sTexture, vec2(vTexCoord.x, -vTexCoord.y *3.0 + 3.0)) * uColor;      \n"
72       "   color.a *= uAlpha;                                                                          \n"
73       "   gl_FragColor = color * vec4(darkness, darkness, darkness, darkness);                        \n"
74       " }                                           \n"
75       "}                                            \n" );
76
77   Dali::ShaderEffect shaderEffect =  Dali::ShaderEffect::New(
78       vertexShader,
79       fragmentShader,
80       ShaderEffect::GeometryHints( ShaderEffect::HINT_BLENDING ));
81
82   shaderEffect.SetUniform("uAlpha", 1.0f);
83   shaderEffect.SetUniform("uDepth", 0.5f);
84
85   return shaderEffect;
86 }
87
88
89 } // namespace Toolkit
90
91 } // namespace Dali
92
93 #endif // __DALI_TOOLKIT_MIRROR_EFFECT_H__