1 #ifndef __DALI_TOOLKIT_SHADER_EFFECT_RIPPLE_H__
2 #define __DALI_TOOLKIT_SHADER_EFFECT_RIPPLE_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 RippleEffect
33 * RippleEffect is a custom shader effect to achieve ripple effects on Image actors.
35 * Animatable/Constrainable uniforms:
36 * "uAmplitude" - The amplitude of the effect
37 * "uCenter" - The center point of the effect as screen coordinates
38 * "uTime" - The time duration for the ripple
40 * @return A handle to a newly allocated ShaderEffect
42 inline ShaderEffect CreateRippleEffect()
44 std::string vertexShader(
45 "precision mediump float;\n"
46 "uniform mediump vec2 uCenter;\n"
47 "uniform mediump float uTime;\n"
48 "uniform mediump float uAmplitude;\n"
49 "varying mediump float vLight;\n"
50 "varying mediump float vShade;\n"
53 "float lighting = uAmplitude * 0.02;\n"
54 "float waveLength = uAmplitude * 0.0016;\n"
55 "vec4 world = uModelView * vec4(aPosition,1.0);\n"
56 "vec2 d = vec2(world.x - uCenter.x, world.y - uCenter.y);\n"
57 "float dist = length(d);\n"
58 "float amplitude = cos(uTime - dist*waveLength);\n"
59 "float slope = sin(uTime - dist*waveLength);\n"
60 "world.z += amplitude * uAmplitude;\n"
61 "gl_Position = uProjection * world;\n"
62 "vec2 lightDirection = vec2(-0.707,0.707);\n"
66 " dot = dot(normalize(d),lightDirection) * lighting;\n"
68 "vShade = 1.0 - (dot * slope);\n"
69 "vLight = max(0.0, dot * -slope);\n"
70 "vTexCoord = aTexCoord;\n"
73 // append the default version
74 std::string imageFragmentShader(
75 "precision mediump float;\n"
76 "varying mediump float vLight;\n"
77 "varying mediump float vShade;\n"
80 " gl_FragColor = texture2D(sTexture, vTexCoord) * uColor * vec4(vShade,vShade,vShade,1.0) + vec4(vLight, vLight, vLight,0.0);\n"
84 Dali::ShaderEffect shaderEffect = Dali::ShaderEffect::New(
85 vertexShader, imageFragmentShader,
86 ShaderEffect::GeometryHints(ShaderEffect::HINT_GRID) );
89 shaderEffect.SetUniform( "uAmplitude", 0.0f );
90 shaderEffect.SetUniform( "uCenter", Vector2(0.0f, 0.0f));
91 shaderEffect.SetUniform( "uTime", 0.0f );
96 } // namespace Toolkit
100 #endif // __DALI_TOOLKIT_SHADER_EFFECT_RIPPLE_H__