Merge branch 'devel/master' into devel/new_mesh
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / devel-api / shader-effects / carousel-effect.h
1 #ifndef __DALI_TOOLKIT_CAROUSEL_EFFECT_H__
2 #define __DALI_TOOLKIT_CAROUSEL_EFFECT_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 Creates a new Carousel effect
32  *
33  * CarouselEffect is a custom shader effect to achieve Carousel effects in actors
34  *
35  * A Carousel has a Radius property which can be +ve (appear as if viewing from the outside of
36  * a cylinder/sphere)
37  * or -ve (appear as if viewing from the inside of a cylinder/sphere).
38  *
39  * It can be a horizontal or vertical (cylindrical) or both (spherical). The AnglePerUnit
40  * property provides this functionality as a Vector2.
41  *
42  * Finally, the carousel's center position can be specified as a Screen coordinate (top-left being
43  * the origin).
44  *
45  * Animatable/Constrainable uniforms:
46  *  "uRadius"       - The radius of the Carousel effect. A positive Radius will bend toward the camera,
47  *                    while a negative Radius will bend away from the camera.
48  *  "uAnglePerUnit" - The angle deviation of Carousel in degrees per geometric unit for each axis
49                       For example if you wish for the horizontal angle deviation to vary from +/- 10
50                       degrees, then a Value of 20.0f / stageWidth for the X component should be specified.
51  *  "uCenter"       - The center point of the carousel (in screen coordinates) this is where the peek of the carousel should appear.
52  *                    Defaults value is top-left corner (0.0f, 0.0f).
53  *
54  * @return A handle to a newly allocated ShaderEffect
55  */
56 inline ShaderEffect CreateCarouselEffect()
57 {
58   // append the default version
59     std::string vertexShader(
60                 "uniform float uRadius;\n"
61                 "uniform mediump vec2 uCenter;\n"
62                 "uniform mediump vec2 uAnglePerUnit;\n"
63                 "\n"
64                 "void main()\n"
65                 "{\n"
66                 "    mediump vec4 world = uModelView * vec4(aPosition,1.0);\n"
67                 "    mediump vec2 d = (world.xy - uCenter) * uAnglePerUnit;\n"
68                 "    mediump float a = length(d);\n"
69                 "    mediump float cs = cos(radians(a));\n"
70                 "    world.z -= cs * uRadius;\n"
71                 "    gl_Position = uProjection * world;\n"
72                 "    \n"
73                 "    vTexCoord = aTexCoord;\n"
74                 "}\n");
75
76     ShaderEffect shaderEffect = ShaderEffect::New(
77         vertexShader,
78         "",
79         ShaderEffect::GeometryHints( ShaderEffect::HINT_GRID | ShaderEffect::HINT_DEPTH_BUFFER ));
80
81
82     shaderEffect.SetUniform( "uRadius", 0.0f );
83     shaderEffect.SetUniform( "uCenter", Vector2( 0.0f, 0.0f ) );
84     shaderEffect.SetUniform( "uAnglePerUnit", Vector2( 0.0f, 0.0f ) );
85
86     return shaderEffect;
87 }
88
89 } // namespace Toolkit
90
91 } // namespace Dali
92
93 #endif // __DALI_TOOLKIT_CAROUSEL_EFFECT_H__