2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://floralicense.org/license/
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
17 #include <dali-toolkit/public-api/shader-effects/ripple2d-effect.h>
29 const std::string TEXTURE_SIZE_PROPERTY_NAME( "uTextureSize" );
30 const std::string AMPLITUDE_PROPERTY_NAME( "uAmplitude" );
31 const std::string TIME_PROPERTY_NAME( "uTime" );
35 Ripple2DEffect::Ripple2DEffect()
39 //Call the Parent copy constructor to add reference to the implementation for this object
40 Ripple2DEffect::Ripple2DEffect(ShaderEffect handle)
45 Ripple2DEffect::~Ripple2DEffect()
50 Ripple2DEffect Ripple2DEffect::New()
52 // append the default version
53 std::string fragmentShader(
54 "uniform float uAmplitude;\n"
55 "uniform float uTime;\n"
58 " highp vec2 textureSize = sTextureRect.zw - sTextureRect.xy;\n"
59 " highp vec2 pos = -1.0 + 2.0 * vTexCoord.st/textureSize;\n"
60 " highp float len = length(pos);\n"
61 " highp vec2 texCoord = vTexCoord.st/textureSize + pos/len * sin( len * 12.0 - uTime * 4.0 ) * uAmplitude;\n"
62 " gl_FragColor = texture2D(sTexture, texCoord) * uColor;\n"
65 // Create the implementation, temporarily owned on stack
66 Dali::ShaderEffect shaderEffect = Dali::ShaderEffect::New(
69 Dali::GeometryType( GEOMETRY_TYPE_IMAGE ),
70 ShaderEffect::GeometryHints( ShaderEffect::HINT_BLENDING | ShaderEffect::HINT_GRID ));
72 /* Pass ownership to Ripple2DEffect through overloaded constructor, So that it now has access to the
73 Dali::ShaderEffect implementation */
74 Dali::Toolkit::Ripple2DEffect handle( shaderEffect );
76 handle.SetUniform( TEXTURE_SIZE_PROPERTY_NAME, Vector2(0.0f, 0.0f) );
77 handle.SetUniform( AMPLITUDE_PROPERTY_NAME, 0.0f );
78 handle.SetUniform( TIME_PROPERTY_NAME, 0.0f );
84 void Ripple2DEffect::SetAmplitude(float amplitude)
86 SetUniform( AMPLITUDE_PROPERTY_NAME, amplitude );
89 void Ripple2DEffect::SetTime(float time)
91 SetUniform( TIME_PROPERTY_NAME, time );
94 const std::string& Ripple2DEffect::GetAmplitudePropertyName() const
96 return AMPLITUDE_PROPERTY_NAME;
99 const std::string& Ripple2DEffect::GetTimePropertyName() const
101 return TIME_PROPERTY_NAME;
104 } // namespace Toolkit