1 #ifndef __DALI_TOOLKIT_SHADER_EFFECT_BENDY_H__
2 #define __DALI_TOOLKIT_SHADER_EFFECT_BENDY_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 * Creates a new Bendy effect
33 * BendyEffect is a custom shader effect to achieve bendy effects in Image actors
35 * Animatable/Constrainable uniforms:
36 * "uCenter" - The center point of the bendy effect
37 * "uDirection" - The direction of the bendy effect
38 * "uRadius" - The radius of the bendy effect
40 * @return A handle to a newly allocated ShaderEffect.
42 inline ShaderEffect CreateBendyEffect()
44 // append the default version
45 std::string vertextShader(
46 "uniform mediump vec2 uCenter;\n"
47 "uniform mediump vec2 uDirection;\n"
48 "uniform mediump float uRadius;\n"
50 "varying mediump float vShade;\n"
54 " mediump float lighting = 0.25;\n"
55 " mediump vec4 position = uModelView * vec4(aPosition, 1.0);\n"
57 " mediump vec2 d = position.xy - uCenter;\n"
58 " mediump float dist = max( 0.0, dot(d,uDirection) );\n"
59 " mediump float radius = max(0.0, uRadius - dist * 0.01);\n"
61 " mediump float cs = cos(dist / radius / 2.0);\n"
62 " mediump float sn = sin(dist / radius / 2.0);\n"
64 "position.xy = position.xy - uDirection * dist;\n"
66 "position.xy += uDirection * sn * radius;\n"
67 "position.z += (1.0 - cs) * radius;\n"
69 "gl_Position = uProjection * position;\n"
71 "vShade = 1.0 - abs(sn) * lighting;\n"
73 "vTexCoord = mix( sTextureRect.xy, sTextureRect.zw, aTexCoord );\n"
76 std::string fragmentShader(
77 "varying mediump float vShade;\n"
81 " gl_FragColor = texture2D(sTexture, vTexCoord) * uColor * vec4(vShade,vShade,vShade,1.0);\n"
84 // Create the implementation, temporarily owned on stack,
85 Dali::ShaderEffect shaderEffect = Dali::ShaderEffect::New(
88 ShaderEffect::GeometryHints( ShaderEffect::HINT_GRID | ShaderEffect::HINT_DEPTH_BUFFER ));
90 shaderEffect.SetUniform( "uCenter", Vector2(0.0f, 0.0f), ShaderEffect::COORDINATE_TYPE_VIEWPORT_POSITION );
91 shaderEffect.SetUniform( "uDirection", Vector2(0.0f, 0.0f), ShaderEffect::COORDINATE_TYPE_VIEWPORT_DIRECTION );
92 shaderEffect.SetUniform( "uRadius", 0.0f );
98 } // namespace Toolkit
102 #endif // __DALI_TOOLKIT_SHADER_EFFECT_BENDY_H__