1 #ifndef __DALI_TOOLKIT_CAROUSEL_EFFECT_H__
2 #define __DALI_TOOLKIT_CAROUSEL_EFFECT_H__
5 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <dali/public-api/shader-effects/shader-effect.h>
31 * @brief Creates a new Carousel effect
33 * CarouselEffect is a custom shader effect to achieve Carousel effects in actors
35 * A Carousel has a Radius property which can be +ve (appear as if viewing from the outside of
37 * or -ve (appear as if viewing from the inside of a cylinder/sphere).
39 * It can be a horizontal or vertical (cylindrical) or both (spherical). The AnglePerUnit
40 * property provides this functionality as a Vector2.
42 * Finally, the carousel's center position can be specified as a Screen coordinate (top-left being
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).
54 * @return A handle to a newly allocated ShaderEffect
56 inline ShaderEffect CreateCarouselEffect()
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"
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"
73 " vTexCoord = mix( sTextureRect.xy, sTextureRect.zw, aTexCoord );\n"
76 ShaderEffect shaderEffect = ShaderEffect::New(
79 ShaderEffect::GeometryHints( ShaderEffect::HINT_GRID | ShaderEffect::HINT_DEPTH_BUFFER ));
82 shaderEffect.SetUniform( "uRadius", 0.0f );
83 shaderEffect.SetUniform( "uCenter", Vector2( 0.0f, 0.0f ) );
84 shaderEffect.SetUniform( "uAnglePerUnit", Vector2( 0.0f, 0.0f ) );
89 } // namespace Toolkit
93 #endif // __DALI_TOOLKIT_CAROUSEL_EFFECT_H__