1 #ifndef __DALI_TOOLKIT_SHADER_EFFECT_RIPPLE2D_H__
2 #define __DALI_TOOLKIT_SHADER_EFFECT_RIPPLE2D_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 Ripple2DEffect
33 * Ripple2DEffect is a custom shader effect to achieve 2d ripple effects on Image actors.
35 * Animatable/Constrainable uniforms:
36 * "uTime" - The time duration for the 2d ripple
37 * "uAmplitude" - The amplitude of the 2d ripple
39 * @return A handle to a newly allocated ShaderEffect
41 inline ShaderEffect CreateRipple2DEffect()
43 // append the default version
44 std::string fragmentShader(
45 "precision mediump float;\n"
46 "uniform float uAmplitude;\n"
47 "uniform float uTime;\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"
57 Dali::ShaderEffect shaderEffect = Dali::ShaderEffect::New(
59 ShaderEffect::GeometryHints( ShaderEffect::HINT_BLENDING | ShaderEffect::HINT_GRID ));
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 );
70 } // namespace Toolkit
74 #endif // __DALI_TOOLKIT_SHADER_EFFECT_RIPPLE2D_H__