Merge "Changed styles to use case-insensitive matching" into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / devel-api / shader-effects / shear-effect.h
1 #ifndef __DALI_TOOLKIT_SHEAR_EFFECT_H__
2 #define __DALI_TOOLKIT_SHEAR_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 ShearEffect
32  *
33  * ShearEffect is a custom shader effect to achieve shear effects in Image actors
34  *
35  * Animatable/Constrainable uniforms:
36  *  "uCenter"     - The center point of the shear effect in screen coordinates
37  *  "uAngleXAxis" - The angle of the shear effect in the X axis
38  *  "uAngleYAxis" - The angle of the shear effect in the Y axis
39  *
40  * @return A handle to a newly allocated ShaderEffect
41  */
42 inline ShaderEffect CreateShearEffect()
43 {
44   // append the default version
45   std::string vertexShader(
46       "uniform mediump  vec2  uCenter;\n"
47       "uniform mediump  float uAngleXAxis;\n"
48       "uniform mediump  float uAngleYAxis;\n"
49       "\n"
50       "void main()\n"
51       "{\n"
52       "mediump vec4 world = uModelView * vec4(aPosition, 1.0);\n"
53       "\n"
54       "world.x = world.x + tan(radians(uAngleXAxis)) * (world.y - uCenter.y * world.w);\n"
55       "world.y = world.y + tan(radians(uAngleYAxis)) * (world.x - uCenter.x * world.w);\n"
56       "\n"
57       "gl_Position = uProjection * world;\n"
58       "\n"
59       "vTexCoord = mix( sTextureRect.xy, sTextureRect.zw, aTexCoord );\n"
60       "}" );
61
62   // Create the implementation, temporarily owned on stack,
63   ShaderEffect shaderEffect =  Dali::ShaderEffect::New(
64       vertexShader,
65       "",
66       ShaderEffect::GeometryHints( ShaderEffect::HINT_GRID ));
67
68
69   shaderEffect.SetUniform( "uCenter", Vector2(0.0f, 0.0f), ShaderEffect::COORDINATE_TYPE_VIEWPORT_POSITION );
70   shaderEffect.SetUniform( "uAngleXAxis", 0.0f);
71   shaderEffect.SetUniform( "uAngleYAxis", 0.0f);
72
73   return shaderEffect;
74 }
75
76 } // namespace Toolkit
77
78 } // namespace Dali
79
80 #endif // __DALI_TOOLKIT_SHEAR_EFFECT_H__