cbef85bfc8a305e0f72a54f6db0e84e533bbfdd6
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / devel-api / shader-effects / ripple2d-effect.h
1 #ifndef __DALI_TOOLKIT_SHADER_EFFECT_RIPPLE2D_H__
2 #define __DALI_TOOLKIT_SHADER_EFFECT_RIPPLE2D_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 Ripple2DEffect
32  *
33  * Ripple2DEffect is a custom shader effect to achieve 2d ripple effects on Image actors.
34  *
35  * Animatable/Constrainable uniforms:
36  *  "uTime"       - The time duration for the 2d ripple
37  *  "uAmplitude"  - The amplitude of the 2d ripple
38  *
39  * @return A handle to a newly allocated ShaderEffect
40  */
41 inline ShaderEffect CreateRipple2DEffect()
42 {
43   // append the default version
44   std::string fragmentShader(
45       "precision mediump float;\n"
46       "uniform float uAmplitude;\n"
47       "uniform float uTime;\n"
48       "void main()\n"
49       "{\n"
50       "  highp vec2 textureSize = sTextureRect.zw - sTextureRect.xy;\n"
51       "  highp vec2 pos = -1.0 + 2.0 * vTexCoord.st/textureSize;\n"
52       "  highp float len = length(pos);\n"
53       "  highp vec2 texCoord = vTexCoord.st/textureSize + pos/len * sin( len * 12.0 - uTime * 4.0 ) * uAmplitude;\n"
54       "  gl_FragColor = texture2D(sTexture, texCoord) * uColor;\n"
55       "}" );
56
57   Dali::ShaderEffect shaderEffect =  Dali::ShaderEffect::New(
58       "", fragmentShader,
59       ShaderEffect::GeometryHints( ShaderEffect::HINT_BLENDING | ShaderEffect::HINT_GRID ));
60
61
62
63   shaderEffect.SetUniform( "uTextureSize", Vector2(0.0f, 0.0f) ); //@note: Is this needed?
64   shaderEffect.SetUniform( "uAmplitude", 0.0f );
65   shaderEffect.SetUniform( "uTime", 0.0f );
66
67   return shaderEffect;
68 }
69
70 } // namespace Toolkit
71
72 } // namespace Dali
73
74 #endif // __DALI_TOOLKIT_SHADER_EFFECT_RIPPLE2D_H__